Search in sources :

Example 16 with AgentBean

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;
}
Also used : ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) HttpServletRequest(javax.servlet.http.HttpServletRequest) AgentBean(com.code.server.constant.game.AgentBean) ChildCost(com.code.server.constant.db.ChildCost) AgentInfo(com.code.server.constant.db.AgentInfo) AuthChecker(com.code.server.login.anotation.AuthChecker) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with AgentBean

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;
}
Also used : AgentBean(com.code.server.constant.game.AgentBean)

Example 18 with AgentBean

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;
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) DemoChecker(com.code.server.login.anotation.DemoChecker) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with AgentBean

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;
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) WxMpQrCodeTicket(me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket) TextBuilder(com.code.server.login.wechat.builder.TextBuilder) Random(java.util.Random) WxMpUser(me.chanjar.weixin.mp.bean.result.WxMpUser) WxMpXmlOutNewsMessage(me.chanjar.weixin.mp.bean.message.WxMpXmlOutNewsMessage) WxErrorException(me.chanjar.weixin.common.exception.WxErrorException)

Example 20 with AgentBean

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;
}
Also used : AgentBean(com.code.server.constant.game.AgentBean)

Aggregations

AgentBean (com.code.server.constant.game.AgentBean)37 User (com.code.server.db.model.User)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 UserBean (com.code.server.constant.game.UserBean)6 WxErrorException (me.chanjar.weixin.common.exception.WxErrorException)6 Recommend (com.code.server.db.model.Recommend)5 WxMpUser (me.chanjar.weixin.mp.bean.result.WxMpUser)5 AgentUser (com.code.server.db.model.AgentUser)4 GameAgent (com.code.server.db.model.GameAgent)4 ChildCost (com.code.server.constant.db.ChildCost)3 LocalDate (java.time.LocalDate)3 ArrayList (java.util.ArrayList)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 AgentInfo (com.code.server.constant.db.AgentInfo)2 Charge (com.code.server.db.model.Charge)2 DemoChecker (com.code.server.login.anotation.DemoChecker)2 TextBuilder (com.code.server.login.wechat.builder.TextBuilder)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Random (java.util.Random)2