Search in sources :

Example 6 with Recommend

use of com.code.server.db.model.Recommend in project summer by foxsugar.

the class WechatAction method becomeAgent.

@RequestMapping("/becomeAgent")
@ResponseBody
public AgentResponse becomeAgent(long userId) {
    AgentResponse agentResponse = new AgentResponse();
    AgentBean agentBean = agentRedisService.getAgentBean(userId);
    // todo 之前是代理
    if (agentBean != null) {
        return new AgentResponse().setCode(ErrorCode.ALREADY_AGENT);
    }
    // 之前不是代理
    GameAgent gameAgent = new GameAgent();
    gameAgent.setId(userId);
    // 推荐
    String unionId = userService.getUserDao().getOpenIdById(userId);
    Recommend recommend = recommendService.getRecommendDao().findOne(unionId);
    GameAgentWx gameAgentWx = gameAgentWxService.getGameAgentWxDao().findOne(unionId);
    if (gameAgentWx == null) {
        return new AgentResponse().setCode(ErrorCode.NOT_WX_USER);
    }
    String openId = gameAgentWx.getOpenId();
    gameAgent.setOpenId(openId);
    gameAgent.setId(userId);
    gameAgent.setUnionId(unionId);
    // 有推荐
    if (recommend != null) {
        long parentId = recommend.getAgentId();
        AgentBean parent = agentRedisService.getAgentBean(parentId);
        // 上级代理存在
        if (parent != null) {
            // 和上级的partner是同一个
            gameAgent.setPartnerId(parent.getPartnerId());
            gameAgent.setParentId(parentId);
            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) GameAgentWx(com.code.server.db.model.GameAgentWx) Recommend(com.code.server.db.model.Recommend) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with Recommend

use of com.code.server.db.model.Recommend 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)

Aggregations

Recommend (com.code.server.db.model.Recommend)7 AgentBean (com.code.server.constant.game.AgentBean)5 User (com.code.server.db.model.User)4 WxErrorException (me.chanjar.weixin.common.exception.WxErrorException)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 UserBean (com.code.server.constant.game.UserBean)2 GameAgent (com.code.server.db.model.GameAgent)2 ServerConfig (com.code.server.login.config.ServerConfig)2 WxMpUser (me.chanjar.weixin.mp.bean.result.WxMpUser)2 GameAgentWx (com.code.server.db.model.GameAgentWx)1 LocalDate (java.time.LocalDate)1 WxMpOAuth2AccessToken (me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1