Search in sources :

Example 26 with AgentBean

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;
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) ThreeLevelInfoVo(com.code.server.login.vo.ThreeLevelInfoVo) User(com.code.server.db.model.User) ArrayList(java.util.ArrayList)

Example 27 with AgentBean

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;
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) OneLevelInfoVo(com.code.server.login.vo.OneLevelInfoVo) User(com.code.server.db.model.User) ArrayList(java.util.ArrayList)

Example 28 with AgentBean

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) {
    }
}
Also used : WxMpOAuth2AccessToken(me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken) AgentBean(com.code.server.constant.game.AgentBean) User(com.code.server.db.model.User) WxMpUser(me.chanjar.weixin.mp.bean.result.WxMpUser) UserBean(com.code.server.constant.game.UserBean) Recommend(com.code.server.db.model.Recommend) WxMpUser(me.chanjar.weixin.mp.bean.result.WxMpUser) WxErrorException(me.chanjar.weixin.common.exception.WxErrorException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 29 with AgentBean

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);
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) WxMpQrCodeTicket(me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket) WxErrorException(me.chanjar.weixin.common.exception.WxErrorException)

Example 30 with AgentBean

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;
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) User(com.code.server.db.model.User) WxMpUser(me.chanjar.weixin.mp.bean.result.WxMpUser) UserBean(com.code.server.constant.game.UserBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

AgentBean (com.code.server.constant.game.AgentBean)37 User (com.code.server.db.model.User)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 UserBean (com.code.server.constant.game.UserBean)6 WxErrorException (me.chanjar.weixin.common.exception.WxErrorException)6 Recommend (com.code.server.db.model.Recommend)5 WxMpUser (me.chanjar.weixin.mp.bean.result.WxMpUser)5 AgentUser (com.code.server.db.model.AgentUser)4 GameAgent (com.code.server.db.model.GameAgent)4 ChildCost (com.code.server.constant.db.ChildCost)3 LocalDate (java.time.LocalDate)3 ArrayList (java.util.ArrayList)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 AgentInfo (com.code.server.constant.db.AgentInfo)2 Charge (com.code.server.db.model.Charge)2 DemoChecker (com.code.server.login.anotation.DemoChecker)2 TextBuilder (com.code.server.login.wechat.builder.TextBuilder)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Random (java.util.Random)2