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;
}
Aggregations