Search in sources :

Example 1 with GameAgent

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

the class RecommendDelegateServiceImpl method user2Agent.

/**
 * 玩家成为代理
 * @param userId
 * @param unionId
 * @param parent
 */
public void user2Agent(long userId, String unionId, AgentBean parent) {
    GameAgent gameAgent = new GameAgent();
    gameAgent.setId(userId);
    gameAgent.setUnionId(unionId);
    // 有推荐
    // 和上级的partner是同一个
    gameAgent.setPartnerId(parent.getPartnerId());
    gameAgent.setParentId(parent.getId());
    gameAgent.setIsPartner(0);
    // 上级代理加一个child
    parent.getChildList().add(userId);
    RedisManager.getAgentRedisService().updateAgentBean(parent);
    // 保存到数据库
    gameAgentService.getGameAgentDao().save(gameAgent);
    AgentBean agentBean = AgentService.gameAgent2AgentBean(gameAgent);
    // 保存的reids
    RedisManager.getAgentRedisService().setAgent2Redis(agentBean);
    RedisManager.getAgentRedisService().updateAgentBean(agentBean);
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) GameAgent(com.code.server.db.model.GameAgent)

Example 2 with GameAgent

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

the class HomeServiceImplTest method save.

@Test
public void save() {
    GameAgent gameAgent = new GameAgent();
    // gameAgent.setChildList(new HashSet<>());
    gameAgent.setParentId(99);
    gameAgent.setIsPartner(30);
    gameAgent.setPartnerId(49);
    gameAgent.setRebate(555);
    gameAgent.setQrTicket("www");
    gameAgent.setOpenId("70");
    gameAgent.setUnionId("88");
// repository.save(gameAgent);
}
Also used : GameAgent(com.code.server.db.model.GameAgent) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with GameAgent

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

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

the class AgentService method agentBean2GameAgent.

public static GameAgent agentBean2GameAgent(AgentBean agentBean) {
    GameAgent gameAgent = new GameAgent();
    BeanUtils.copyProperties(agentBean, gameAgent);
    gameAgent.getAgentChild().setChildren(agentBean.getChildList());
    return gameAgent;
}
Also used : GameAgent(com.code.server.db.model.GameAgent)

Example 5 with GameAgent

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

the class AgentService method player2Agnet.

/**
 * 玩家成为代理
 *
 * @param userId
 * @param unionId
 */
private AgentBean player2Agnet(long userId, String unionId) {
    // fixme 修复如果成为代理前就已经是下级的情况
    GameAgent gameAgent = new GameAgent();
    gameAgent.setCreateDate(new Date());
    gameAgent.setId(userId);
    gameAgent.setUnionId(unionId);
    gameAgent.setIsPartner(0);
    gameAgent.setParentId(0);
    User user = userService.getUserByUserId(userId);
    if (user != null) {
        gameAgent.setParentId(user.getReferee());
    }
    AgentBean agentBean = gameAgent2AgentBean(gameAgent);
    // 保存到redis
    agentRedisService.setAgent2Redis(agentBean);
    // 保存到数据库
    gameAgentService.getGameAgentDao().save(gameAgent);
    return agentBean;
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) GameAgent(com.code.server.db.model.GameAgent) User(com.code.server.db.model.User) AgentUser(com.code.server.db.model.AgentUser) LocalDate(java.time.LocalDate)

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