use of com.code.server.constant.game.AgentBean in project summer by foxsugar.
the class DelegateRelataionServiceImpl method fetchThreeLevelDelegateList.
@Override
public List<ThreeLevelInfoVo> fetchThreeLevelDelegateList(long agentId) {
AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
logger.info("》》》》》》》》》》》》》{}", agentBean);
List<Long> aList = new ArrayList<>();
for (long uid : agentBean.getChildList()) {
if (RedisManager.getAgentRedisService().isExit(uid)) {
aList.add(uid);
}
}
// List<Long> bList = new ArrayList<>();
// for (Long id : aList){
// AgentBean bean = RedisManager.getAgentRedisService().getAgentBean(id);
// for (Long uid : bean.getChildList()){
// if (RedisManager.getAgentRedisService().isExit(uid)){
// bList.add(uid);
// }
// }
// }
// List<User> cList = userDao.findUsersByIdIn(bList);
// List<ThreeLevelInfoVo> resultList = new ArrayList<>();
// for (User user : cList){
// ThreeLevelInfoVo threeLevelInfoVo = new ThreeLevelInfoVo();
// threeLevelInfoVo.setImage(user.getImage() + "/96");
// threeLevelInfoVo.setUsername(user.getUsername());
// threeLevelInfoVo.setUid(user.getId());
// resultList.add(threeLevelInfoVo);
// }
List<User> cList = userDao.findUsersByIdIn(aList);
List<ThreeLevelInfoVo> resultList = new ArrayList<>();
for (User user : cList) {
ThreeLevelInfoVo threeLevelInfoVo = new ThreeLevelInfoVo();
threeLevelInfoVo.setImage(user.getImage() + "/96");
threeLevelInfoVo.setUsername(user.getUsername());
threeLevelInfoVo.setUid(user.getId());
resultList.add(threeLevelInfoVo);
}
return resultList;
}
use of com.code.server.constant.game.AgentBean in project summer by foxsugar.
the class DelegateRelataionServiceImpl method fetchSelfPlayerList.
@Override
public List<OneLevelInfoVo> fetchSelfPlayerList(long agentId) {
AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
List<Long> aList = new ArrayList<>();
for (long uid : agentBean.getChildList()) {
if (RedisManager.getAgentRedisService().isExit(uid))
continue;
aList.add(uid);
}
List<OneLevelInfoVo> result = new ArrayList<>();
List<User> userList = this.userDao.findUsersByIdIn(aList);
System.out.println("===========++++aList:" + aList);
System.out.println("===========++++aList:" + userList);
for (User user : userList) {
OneLevelInfoVo oneLevelInfoVo = new OneLevelInfoVo();
oneLevelInfoVo.setImage(user.getImage() + "/96");
oneLevelInfoVo.setUsername(user.getUsername());
oneLevelInfoVo.setUid(user.getId());
result.add(oneLevelInfoVo);
}
return result;
}
use of com.code.server.constant.game.AgentBean in project summer by foxsugar.
the class WechatAction method clickLink.
/**
* 点击分享链接
*
* @param code
* @param state
* @param request
* @param response
* @throws IOException
*/
@GetMapping("/clickLink")
public void clickLink(@RequestParam("code") String code, @RequestParam("state") String state, HttpServletRequest request, HttpServletResponse response) throws IOException {
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = new WxMpOAuth2AccessToken();
try {
logger.info("------------- 点击分享链接-----------");
wxMpOAuth2AccessToken = wxMpService.oauth2getAccessToken(code);
WxMpUser wxMpUser = wxMpService.oauth2getUserInfo(wxMpOAuth2AccessToken, null);
// state 是id
long agentId = Long.valueOf(state);
// 代理不存在 直接退出
AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
if (agentBean == null)
return;
String unionId = wxMpUser.getUnionId();
boolean isSelf = agentBean.getUnionId().equals(unionId);
if (isSelf) {
// 处理跳转
handle_link_redirect(agentId, response);
return;
}
// 通知 代理 有人绑定他
String name = wxMpUser.getNickname();
StringBuilder sb = new StringBuilder();
sb.append(name).append(" 已点击您的专属链接,");
// 这个人是否已经点过
// 这个人如果已经是玩家 并且玩家没有上级 那么成为这个人的下级
User user = userService.getUserDao().getUserByOpenId(unionId);
if (user != null) {
long userId = user.getId();
boolean userIsAgnet = RedisManager.getAgentRedisService().isExit(userId);
// 点击者已经是代理
if (userIsAgnet) {
sb.append("但已成为代理");
} else {
UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
if (userBean != null) {
if (userBean.getReferee() == 0) {
userBean.setReferee((int) agentId);
RedisManager.getUserRedisService().updateUserBean(userBean.getId(), userBean);
agentBean.getChildList().add(userId);
RedisManager.getAgentRedisService().updateAgentBean(agentBean);
sb.append("已和您成功绑定");
} else {
if (userBean.getReferee() == agentId) {
sb.append("已经和您建立过绑定关系");
} else {
sb.append("但已绑定其他代理");
}
}
} else {
if (user.getReferee() == 0) {
user.setReferee((int) agentId);
userService.save(user);
agentBean.getChildList().add(userId);
RedisManager.getAgentRedisService().updateAgentBean(agentBean);
sb.append("已和您成功绑定");
} else {
if (user.getReferee() == agentId) {
sb.append("已经和您建立过绑定关系");
} else {
sb.append("但已绑定其他代理");
}
}
}
}
} else {
Recommend recommend = recommendService.getRecommendDao().getByUnionId(unionId);
if (recommend == null) {
recommend = new Recommend();
recommend.setUnionId(unionId).setAgentId(agentId);
// 保存
recommendService.getRecommendDao().save(recommend);
sb.append("已和您成功绑定");
}
}
try {
wxMpService.getKefuService().sendKefuMessage(WxMpKefuMessage.TEXT().toUser(agentBean.getOpenId()).content(sb.toString()).build());
} catch (WxErrorException e) {
logger.error("【clickLink】{}", e);
}
// 处理跳转
handle_link_redirect(agentId, response);
} catch (WxErrorException e) {
}
}
use of com.code.server.constant.game.AgentBean in project summer by foxsugar.
the class WechatAction method handleLoginAgent.
private void handleLoginAgent(WxMpUser wxMpUser, HttpServletRequest request, HttpServletResponse response) throws IOException {
Long agentId = gameAgentService.getGameAgentDao().getUserIdByUnionId(wxMpUser.getUnionId());
if (agentId == null || agentId == 0) {
// 不是代理
try {
wxMpService.getKefuService().sendKefuMessage(WxMpKefuMessage.TEXT().toUser(wxMpUser.getOpenId()).content("您还不是代理").build());
} catch (WxErrorException e) {
e.printStackTrace();
}
System.out.println(request.getRequestURL());
response.getOutputStream().write("您不是代理".getBytes());
return;
}
AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
if (agentBean != null) {
if (agentBean.getOpenId() == null || agentBean.getQrTicket() == null || "".equals(agentBean.getQrTicket())) {
agentBean.setImage(wxMpUser.getHeadImgUrl());
agentBean.setOpenId(wxMpUser.getOpenId());
// 根据unionId生成二维码 todo 加上游戏key
WxMpQrCodeTicket ticket = null;
try {
ticket = wxMpService.getQrcodeService().qrCodeCreateLastTicket(serverConfig.getDomainMapKey() + "|" + wxMpUser.getUnionId());
} catch (WxErrorException e) {
e.printStackTrace();
}
agentBean.setQrTicket(ticket.getTicket());
RedisManager.getAgentRedisService().updateAgentBean(agentBean);
}
}
// 设置cookie
Map<String, String> agent = getAgentByToken(request);
if (agent == null) {
setTokenCookie2Redis(wxMpUser, response, agentId);
}
String url = "http://" + serverConfig.getDomain() + "/agent/#/";
response.sendRedirect(url);
}
use of com.code.server.constant.game.AgentBean in project summer by foxsugar.
the class WechatAction method addChild.
@RequestMapping("/addChild")
@ResponseBody
public AgentResponse addChild(long agentId, long userId) {
AgentResponse agentResponse = new AgentResponse();
AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
if (agentBean == null) {
return new AgentResponse().setData("不是代理");
}
UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
if (userBean != null) {
userBean.setReferee((int) agentId);
} else {
User user = userService.getUserByUserId(userId);
user.setReferee((int) agentId);
}
AgentBean userAgentBean = RedisManager.getAgentRedisService().getAgentBean(userId);
// 自己也是代理
if (userAgentBean != null) {
userAgentBean.setParentId(agentId);
userAgentBean.setPartnerId(agentBean.getPartnerId());
RedisManager.getAgentRedisService().updateAgentBean(userAgentBean);
}
agentBean.getChildList().add(userId);
RedisManager.getAgentRedisService().updateAgentBean(agentBean);
return agentResponse;
}
Aggregations