Search in sources :

Example 6 with GameAgent

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

GameAgent (com.code.server.db.model.GameAgent)6 AgentBean (com.code.server.constant.game.AgentBean)4 Recommend (com.code.server.db.model.Recommend)2 LocalDate (java.time.LocalDate)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 AgentUser (com.code.server.db.model.AgentUser)1 GameAgentWx (com.code.server.db.model.GameAgentWx)1 User (com.code.server.db.model.User)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1