use of com.code.server.constant.game.AgentBean in project summer by foxsugar.
the class TodayChargeAction method showCost.
@AuthChecker
@RequestMapping("/dCost")
public AgentResponse showCost(String start, String end) {
// 转化为标准字符串
logger.info("dCost==========start:{},end:{}", start, end);
start = DateUtil.becomeStandardSTime(start);
end = DateUtil.becomeStandardSTime(end);
logger.info("dCost==========start:{},end:{}", start, end);
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
long agentId = AgentUtil.getAgentByRequest(request);
List<String> list = DateUtil.getDateListIn(end, start);
AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
AgentInfo agentInfo = agentBean.getAgentInfo();
List<DChildCostVo> li = new ArrayList<>();
double oneLevel = 0d;
double twoLevel = 0d;
double threeLevel = 0d;
for (String dateStr : list) {
ChildCost childCost = agentInfo.getEveryDayCost().get(dateStr);
DChildCostVo dChildCostVo = new DChildCostVo();
if (childCost != null) {
BeanUtils.copyProperties(childCost, dChildCostVo);
}
dChildCostVo.setDateStr(dateStr);
li.add(dChildCostVo);
oneLevel += dChildCostVo.getFirstLevel();
twoLevel += dChildCostVo.getSecondLevel();
threeLevel += dChildCostVo.getThirdLevel();
}
// double total = oneLevel * 0.2 * 0.01 + twoLevel * 0.1 * 0.01 + threeLevel *0.1 * 0.01;
double total = (oneLevel + twoLevel + threeLevel) * 0.01;
Map<String, Object> result = new HashMap<>();
result.put("li", li);
result.put("total", total);
// result.put("oneLevel", oneLevel * 0.2 * 0.01);
// result.put("twoLevel", twoLevel * 0.1 * 0.01);
// result.put("threeLevel", threeLevel *0.1 * 0.01);
result.put("oneLevel", oneLevel * 0.01);
result.put("twoLevel", twoLevel * 0.01);
result.put("threeLevel", threeLevel * 0.01);
result.put("start", list.get(list.size() - 1));
result.put("end", list.get(0));
double income = oneLevel * 0.2 * 0.01 + twoLevel * 0.1 * 0.01 + threeLevel * 0.1 * 0.01;
result.put("income", income);
AgentResponse agentResponse = new AgentResponse(200, result);
return agentResponse;
}
use of com.code.server.constant.game.AgentBean in project summer by foxsugar.
the class AgentRedisService method addRebate.
@Override
public double addRebate(long agentId, double rebate) {
HashOperations<String, String, Double> agent_rebate = redisTemplate.opsForHash();
// 把修改后的值放入userBean里
double m = agent_rebate.increment(AGENT_REBATE, "" + agentId, rebate);
AgentBean agentBean = getAgentBean(agentId);
if (agentBean != null) {
agentBean.setRebate(m);
updateAgentBean(agentBean);
}
return m;
}
use of com.code.server.constant.game.AgentBean in project summer by foxsugar.
the class DemoAction method downwardDelegate.
@DemoChecker
@RequestMapping("/downward")
public AgentResponse downwardDelegate(HttpServletRequest request, long agentId) {
String token = AgentUtil.findTokenInHeader();
int self_agentId = (int) AgentUtil.getUserIdByToken(token);
logger.info("self_id:{}, agent id:{}", self_agentId, agentId);
AgentUser agentUser = agentUserDao.findOne(self_agentId);
logger.info("agentUser:{}", agentUser);
int self_code = 0;
if (self_agentId != 1) {
self_code = Integer.parseInt(agentUser.getUsername());
}
// 先给个demo
if (agentId == 0) {
Map<String, Object> rrss = assDemo();
AgentResponse agentResponse = new AgentResponse();
agentResponse.setData(rrss);
return agentResponse;
}
// 如果代理是空的
if (RedisManager.getAgentRedisService().getAgentBean(agentId) == null) {
AgentResponse agentResponse = new AgentResponse();
agentResponse.setCode(com.code.server.login.action.ErrorCode.ERROR);
agentResponse.setMsg("代理不存在");
return agentResponse;
}
AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
if (agentBean.getPartnerId() != self_agentId && self_agentId != 1 && agentId != self_code) {
AgentResponse agentResponse = new AgentResponse();
agentResponse.setCode(com.code.server.login.action.ErrorCode.ERROR);
agentResponse.setMsg("没有权限");
return agentResponse;
}
// 直接玩家
List<Long> aList = new ArrayList<>();
// 二级代理
List<Long> bList = new ArrayList<>();
// 三级代理
List<Long> cList = new ArrayList<>();
agentBean.getChildList().stream().forEach(x -> {
if (RedisManager.getAgentRedisService().isExit(x)) {
bList.add(x);
} else {
aList.add(x);
}
});
bList.stream().forEach(x -> {
if (RedisManager.getAgentRedisService().isExit(x)) {
cList.add(x);
}
});
List<User> aUsers = userDao.findUsersByIdIn(aList);
List<User> bUsers = userDao.findUsersByIdIn(bList);
Map<String, Object> rs = assembleDelegateRelationship(agentId, aUsers, bUsers);
AgentResponse agentResponse = new AgentResponse();
agentResponse.setData(rs);
System.out.println(agentResponse);
return agentResponse;
}
use of com.code.server.constant.game.AgentBean in project summer by foxsugar.
the class MenuHandler method handle_link.
/**
* 处理链接
*
* @param wxMessage
* @param wxService
* @return
*/
private WxMpXmlOutMessage handle_link(WxMpXmlMessage wxMessage, WxMpService wxService) {
Long agentId = null;
try {
WxMpUser wxMpUser = wxService.getUserService().userInfo(wxMessage.getFromUser());
String unionId = wxMpUser.getUnionId();
agentId = gameAgentService.getGameAgentDao().getUserIdByUnionId(unionId);
if (agentId == null || agentId == 0) {
return new TextBuilder().build("代理不存在", wxMessage, wxService);
}
// gameAgent 是否已经生成ticket
AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
if (agentBean.getOpenId() == null || agentBean.getQrTicket() == null || "".equals(agentBean.getQrTicket())) {
agentBean.setImage(wxMpUser.getHeadImgUrl());
agentBean.setOpenId(wxMpUser.getOpenId());
// 根据unionId生成二维码 todo 加上游戏key
WxMpQrCodeTicket ticket = wxService.getQrcodeService().qrCodeCreateLastTicket(serverConfig.getDomainMapKey() + "|" + unionId);
agentBean.setQrTicket(ticket.getTicket());
RedisManager.getAgentRedisService().updateAgentBean(agentBean);
}
RedisManager.getAgentRedisService().updateAgentBean(agentBean);
} catch (WxErrorException e) {
e.printStackTrace();
}
WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
item.setTitle("您有如下专属代理链接");
item.setDescription("点击进入专属界面");
WxMpXmlOutNewsMessage.Item item1 = new WxMpXmlOutNewsMessage.Item();
// todo 展示二维码 链接
item1.setPicUrl("https://mmbiz.qpic.cn/mmbiz_png/wj1STzkg04h46BuribmuoJnsMQgc2m70558p3mE91j6zq4sph6RavCicfUiahTSRj4CVRSRN9ecdJKic6ysZeBCZiag/0?wx_fmt=png");
item1.setTitle("棋牌");
item1.setDescription("点击进入专属界面");
// String url = "http://" + serverConfig.getDomain() + "/game/wechat/clickLink";
String sid = "" + System.currentTimeMillis() + "_" + new Random().nextInt(999999);
String url = MessageFormat.format("http://" + serverConfig.getDomain() + "/agent/#/sharelink?id={0}&sid={1}&in=1", "" + agentId, sid);
// String url = MessageFormat.format("http://" + serverConfig.getDomain() +"/game/wechat/showLink?agentId={0}&sid={1}", ""+agentId, sid);
logger.info("设置专属链接地址 : " + url);
item1.setUrl(url);
item1.setDescription("");
WxMpXmlOutNewsMessage m = WxMpXmlOutMessage.NEWS().fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).addArticle(item, item1).build();
return m;
}
use of com.code.server.constant.game.AgentBean in project summer by foxsugar.
the class AgentRedisService method addRebate.
@Override
public double addRebate(long agentId, double rebate, String date, String deleteDay) {
HashOperations<String, String, Double> agent_rebate = redisTemplate.opsForHash();
// 把修改后的值放入userBean里
double m = agent_rebate.increment(AGENT_REBATE, "" + agentId, rebate);
AgentBean agentBean = getAgentBean(agentId);
if (agentBean != null) {
agentBean.setRebate(m);
if (rebate > 0) {
// 历史总返利
double allRebate = agentBean.getAgentInfo().getAllRebate();
allRebate += rebate;
agentBean.getAgentInfo().setAllRebate(allRebate);
// 每日返利
Map<String, Double> everyDayRebate = agentBean.getAgentInfo().getEveryDayRebate();
double todayRebate = everyDayRebate.getOrDefault(date, 0D);
todayRebate += rebate;
everyDayRebate.putIfAbsent(date, todayRebate);
// 删除记录
everyDayRebate.remove(deleteDay);
}
updateAgentBean(agentBean);
}
return m;
}
Aggregations