Search in sources :

Example 36 with AgentBean

use of com.code.server.constant.game.AgentBean in project summer by foxsugar.

the class AgentAction method becomeAgent.

@RequestMapping("/becomeAgent")
public AgentResponse becomeAgent(long userId) {
    AgentResponse agentResponse = new AgentResponse();
    AgentBean agentBean = agentRedisService.getAgentBean(userId);
    if (agentBean != null) {
    // todo 之前是代理
    }
    // 之前不是代理
    if (agentBean == null) {
        GameAgent gameAgent = new GameAgent();
        gameAgent.setId(userId);
        gameAgent.setCreateDate(new Date());
        // 推荐
        String openId = userService.getUserDao().getOpenIdById(userId);
        Recommend recommend = recommendService.getRecommendDao().findOne(openId);
        // 有推荐
        if (recommend != null) {
            long agentId = recommend.getAgentId();
            AgentBean parent = agentRedisService.getAgentBean(agentId);
            // 上级代理存在
            if (parent != null) {
                // 和上级的partner是同一个
                gameAgent.setPartnerId(parent.getPartnerId());
                gameAgent.setParentId(agentId);
                gameAgent.setIsPartner(0);
                // 上级代理加一个child
                parent.getChildList().add(userId);
            }
        }
        // 保存到数据库
        gameAgentService.getGameAgentDao().save(gameAgent);
        agentBean = AgentService.gameAgent2AgentBean(gameAgent);
        // 保存的reids
        agentRedisService.setAgent2Redis(agentBean);
    }
    return agentResponse;
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) GameAgent(com.code.server.db.model.GameAgent) Recommend(com.code.server.db.model.Recommend) LocalDate(java.time.LocalDate) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with AgentBean

use of com.code.server.constant.game.AgentBean in project summer by foxsugar.

the class HomeServiceImpl method showHomePage.

@Override
public HomePageVo showHomePage(long agentId) {
    AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
    HomePageVo homePageVo = new HomePageVo();
    homePageVo.setRebate(agentBean.getRebate());
    homePageVo.setInvitationCode("" + agentId);
    HomeChargeVo homeChargeVo = todayChargeService.showCharge(agentId);
    String total = homeChargeVo.getTotal();
    homePageVo.setTotalMoney((Double.parseDouble(total)));
    // 收益
    AgentInfo agentInfo = agentBean.getAgentInfo();
    String today = DateUtil.convert2DayString(new Date());
    Map<String, ChildCost> everyDayCos = agentInfo.getEveryDayCost();
    ChildCost childCost = everyDayCos.get(today);
    if (childCost != null) {
        homePageVo.setFirstLevel(childCost.getFirstLevel() * 0.01 * 0.2);
        homePageVo.setSecondLevel(childCost.getSecondLevel() * 0.01 * 0.1);
        homePageVo.setThirdLevel(childCost.getThirdLevel() * 0.01 * 0.1);
        // homePageVo.setAllCost(childCost.getFirstLevel() * 0.01 * 0.2 + childCost.getSecondLevel()* 0.01 * 0.1 + childCost.getThirdLevel() * 0.01 * 0.1);
        double allCost = (childCost.getFirstLevel() + childCost.getSecondLevel() + childCost.getThirdLevel()) * 0.01;
        homePageVo.setAllCost(allCost);
    }
    return homePageVo;
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) HomePageVo(com.code.server.login.vo.HomePageVo) HomeChargeVo(com.code.server.login.vo.HomeChargeVo) ChildCost(com.code.server.constant.db.ChildCost) AgentInfo(com.code.server.constant.db.AgentInfo)

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