use of com.code.server.constant.game.AgentBean in project summer by foxsugar.
the class WechatAction method getAgentQr.
@RequestMapping("/getAgentQr")
@ResponseBody
public AgentResponse getAgentQr(HttpServletRequest request) {
Map<String, String> map = new HashMap<>();
AgentResponse agentResponse = new AgentResponse();
long agentId = Long.valueOf(request.getParameter("agentId"));
AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
map.put("qr", agentBean.getQrTicket());
map.put("icon", agentBean.getImage());
return agentResponse.setData(map);
}
use of com.code.server.constant.game.AgentBean in project summer by foxsugar.
the class AgentService method change2Agent.
/**
* 变成代理
*
* @param userId
*/
public void change2Agent(long userId) {
AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(userId);
String unionId = userService.getUserDao().getOpenIdById(userId);
// 玩家
if (agentBean == null) {
player2Agnet(userId, unionId);
} else {
// 如果是合伙人的处理 合伙人降级
if (agentBean.getIsPartner() == 1) {
agentBean.setIsPartner(0);
agentBean.setPartnerId(0);
RedisManager.getAgentRedisService().updateAgentBean(agentBean);
// 合伙人下面所有代理的合伙人 全变成0
Set<AgentBean> subAgents = new HashSet<>();
findAllClildAgent(agentBean, subAgents);
for (AgentBean subAgent : subAgents) {
subAgent.setPartnerId(0);
// 加到保存列表
RedisManager.getAgentRedisService().updateAgentBean(subAgent);
}
}
}
}
use of com.code.server.constant.game.AgentBean in project summer by foxsugar.
the class AgentService method change2Player.
/**
* 变成玩家
*
* @param userId
*/
public void change2Player(long userId) {
AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(userId);
// 玩家
if (agentBean == null) {
// 玩家转换成玩家 没意思
// do nothing
} else {
// 如果是合伙人的处理
if (agentBean.getIsPartner() == 1) {
// 合伙人下面所有代理的合伙人 全变成0
Set<AgentBean> subAgents = new HashSet<>();
findAllClildAgent(agentBean, subAgents);
for (AgentBean subAgent : subAgents) {
// 合伙人id变为0
subAgent.setPartnerId(0);
// 合伙人下面一层代理的上级变为0
if (subAgent.getParentId() == userId) {
changePlayerReferee(subAgent.getParentId(), 0);
subAgent.setParentId(0);
}
// 加到保存列表
RedisManager.getAgentRedisService().updateAgentBean(subAgent);
}
} else {
// 普通代理
// 所有下级的上级 变成 这个代理的上级
Set<AgentBean> subAgents = new HashSet<>();
findAllClildAgent(agentBean, subAgents);
// 上级代理id
long parentId = agentBean.getParentId();
AgentBean parentAgentBean = RedisManager.getAgentRedisService().getAgentBean(parentId);
// 改变一级下级的上级代理
for (AgentBean subAgent : subAgents) {
// 合伙人下面一层代理的上级变为个代理的上级
if (subAgent.getParentId() == userId) {
subAgent.setParentId(parentId);
changePlayerReferee(subAgent.getParentId(), (int) parentId);
if (parentAgentBean != null) {
parentAgentBean.getChildList().add(subAgent.getId());
}
// 保存
RedisManager.getAgentRedisService().updateAgentBean(subAgent);
}
}
// 从列表中删除
if (parentAgentBean != null) {
parentAgentBean.getChildList().remove(userId);
RedisManager.getAgentRedisService().updateAgentBean(parentAgentBean);
}
}
// 删除代理
RedisManager.getAgentRedisService().removeAgentBean("" + userId);
// 删除数据库
gameAgentService.getGameAgentDao().delete(userId);
}
// 删除玩家自己的代理信息
UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
if (userBean != null) {
userBean.setReferee(0);
RedisManager.getUserRedisService().updateUserBean(userBean.getId(), userBean);
} else {
User user = userService.getUserByUserId(userId);
user.setReferee(0);
userService.save(user);
}
}
use of com.code.server.constant.game.AgentBean in project summer by foxsugar.
the class AgentService method change2Partner.
/**
* 改变为合伙人
*
* @param userId
*/
public void change2Partner(long userId) {
AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(userId);
String unionId = userService.getUserDao().getOpenIdById(userId);
// 如果不是代理,先成为代理
if (agentBean == null) {
agentBean = player2Agnet(userId, unionId);
}
// 已经是合伙人 返回
if (agentBean.getIsPartner() == 1)
return;
// 如果有上级代理
long parentId = agentBean.getParentId();
if (parentId != 0) {
AgentBean parentAgentBean = RedisManager.getAgentRedisService().getAgentBean(parentId);
// 删掉这个下级代理
parentAgentBean.getChildList().remove(userId);
RedisManager.getAgentRedisService().updateAgentBean(parentAgentBean);
}
// 自己变成合伙人
agentBean.setIsPartner(1);
// 合伙人id 改成自己
agentBean.setPartnerId(userId);
// 上级变为0
agentBean.setParentId(0);
RedisManager.getAgentRedisService().updateAgentBean(agentBean);
// user 上的改变 把上级去掉
changePlayerReferee(userId, 0);
// 自己下级的合伙人 全部改成自己
Set<AgentBean> allChild = new HashSet<>();
findAllClildAgent(agentBean, allChild);
for (AgentBean subAgentBean : allChild) {
subAgentBean.setPartnerId(userId);
// 加入保存列表
RedisManager.getAgentRedisService().updateAgentBean(subAgentBean);
}
// 在agent_user 生产合伙人表
AgentUser agentUser = agentUserService.agentUserDao.findAgentUserByUsername("" + userId);
if (agentUser == null) {
agentUser = new AgentUser();
agentUser.setCreateTime(new Date()).setUsername("" + userId).setPassword("" + userId).setLevel(1);
agentUserService.agentUserDao.save(agentUser);
}
}
use of com.code.server.constant.game.AgentBean in project summer by foxsugar.
the class CenterService method saveAllAgent.
public static void saveAllAgent() {
Set<String> agents = RedisManager.getAgentRedisService().getAllAgentBeanKey();
if (agents != null) {
GameAgentService gameAgentService = SpringUtil.getBean(GameAgentService.class);
agents.forEach(agent -> {
long agentId = Long.valueOf(agent);
AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
if (agentBean != null) {
GameAgent gameAgent = AgentService.agentBean2GameAgent(agentBean);
gameAgentService.getGameAgentDao().save(gameAgent);
if (gameAgent.getIsPartner() == 1) {
saveAgentRecord(agentBean);
}
}
});
}
}
Aggregations