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