Search in sources :

Example 1 with AgentBean

use of com.code.server.constant.game.AgentBean 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);
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) GameAgent(com.code.server.db.model.GameAgent)

Example 2 with AgentBean

use of com.code.server.constant.game.AgentBean in project summer by foxsugar.

the class RecommendDelegateServiceImpl method bindDelegate.

@Override
public boolean bindDelegate(long userId, long agentId) {
    AgentBean userAgentBean = RedisManager.getAgentRedisService().getAgentBean(userId);
    // todo 之前是代理
    if (userAgentBean != null) {
        logger.info("---绑定--- 之前已经是代理");
        return false;
    }
    // 必须先在公众号点击专属链接 成为下级
    AgentBean parentAgentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
    if (!parentAgentBean.getChildList().contains(userId)) {
        logger.info("---绑定--- 不是他的下级");
        return false;
    }
    String unionId = userService.getUserDao().getOpenIdById(userId);
    // 变成代理
    user2Agent(userId, unionId, parentAgentBean);
    return true;
}
Also used : AgentBean(com.code.server.constant.game.AgentBean)

Example 3 with AgentBean

use of com.code.server.constant.game.AgentBean in project summer by foxsugar.

the class RecommendDelegateServiceImpl method findRecommandUser.

@Override
public RecommandUserVo findRecommandUser(long userId, long agentId) {
    AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(userId);
    RecommandUserVo recommandUserVo = new RecommandUserVo();
    if (agentBean != null) {
        recommandUserVo.setUsername("用户不存在");
        recommandUserVo.setUserId(new Long(0));
        // 空头像
        recommandUserVo.setImage("");
    } else {
        // 推荐代理
        User user = userDao.findOne(userId);
        logger.info("user:{}", user);
        if (user == null) {
            recommandUserVo.setUsername("用户不存在");
            recommandUserVo.setUserId(new Long(0));
            // 空头像
            recommandUserVo.setImage("");
        } else {
            recommandUserVo.setImage(user.getImage() + "/96");
            recommandUserVo.setUserId(userId);
            recommandUserVo.setUsername(user.getUsername());
        }
    }
    return recommandUserVo;
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) RecommandUserVo(com.code.server.login.vo.RecommandUserVo) User(com.code.server.db.model.User)

Example 4 with AgentBean

use of com.code.server.constant.game.AgentBean in project summer by foxsugar.

the class MenuHandler method handle_clear.

private WxMpXmlOutMessage handle_clear(WxMpXmlMessage wxMessage, WxMpService wxService) {
    WxMpUser wxMpUser = null;
    try {
        wxMpUser = wxService.getUserService().userInfo(wxMessage.getFromUser());
        String unionId = wxMpUser.getUnionId();
        String openId = wxMpUser.getOpenId();
        Long agentId = gameAgentService.getGameAgentDao().getUserIdByUnionId(unionId);
        if (agentId == null || agentId == 0) {
            return new TextBuilder().build("代理不存在", wxMessage, wxService);
        }
        // gameAgent 是否已经生成ticket
        AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
        // 金额小于 100 不能提
        if (agentBean.getRebate() < 100) {
            return new TextBuilder().build("金额小于100,不能提现", wxMessage, wxService);
        }
        double rebate = agentBean.getRebate();
        // 不能大于20000
        if (rebate > 20000) {
            rebate = 20000;
        }
        Double amount = rebate * 100;
        DecimalFormat df = new DecimalFormat("######0.00");
        // 到账金额
        double amountInt = Double.valueOf(df.format(amount / 100));
        // 手续费
        // double poundage =  Double.valueOf(df.format((rebate *100 - amountInt *100)/100));
        double poundage = 0;
        long tradeId = createOrderId();
        String ip = Utils.getLocalIp();
        EntPayRequest wxEntPayRequest = new EntPayRequest();
        wxEntPayRequest.setAppid(wechatConfig.getMpAppId());
        wxEntPayRequest.setMchId(wechatConfig.getMchId());
        wxEntPayRequest.setNonceStr(Sha1Util.getNonceStr());
        wxEntPayRequest.setPartnerTradeNo("" + tradeId);
        wxEntPayRequest.setOpenid(openId);
        wxEntPayRequest.setCheckName("NO_CHECK");
        // 金额 为分
        wxEntPayRequest.setAmount(amount.intValue());
        wxEntPayRequest.setDescription("提现");
        wxEntPayRequest.setSpbillCreateIp(ip);
        try {
            EntPayResult wxEntPayResult = payService.getEntPayService().entPay(wxEntPayRequest);
            if ("SUCCESS".equals(wxEntPayResult.getResultCode().toUpperCase()) && "SUCCESS".equals(wxEntPayResult.getReturnCode().toUpperCase())) {
                this.logger.info("企业对个人付款成功!\n付款信息:\n" + wxEntPayResult.toString());
                RedisManager.getAgentRedisService().addRebate(agentId, -rebate, null, null);
                // 充值记录
                Charge charge = new Charge();
                charge.setOrderId("" + tradeId);
                charge.setUserid(agentId);
                charge.setMoney(rebate);
                charge.setMoney_point(rebate);
                charge.setStatus(1);
                charge.setSp_ip(ip);
                charge.setRecharge_source("11");
                // 充值类型
                charge.setChargeType(0);
                charge.setCreatetime(new Date());
                chargeService.save(charge);
                // redis 提现记录
                RedisManager.getLogRedisService().logTakeOutNum(rebate);
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
                WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder().toUser(wxMpUser.getOpenId()).templateId("fT9wgjkN5Wfm8dtbPQiozDg7uftEaE6AoMq3YLDeUxc").url("").build();
                String date = dateFormat.format(new Date());
                templateMessage.addData(new WxMpTemplateData("first", "您申请的提现金额已到帐.")).addData(new WxMpTemplateData("keyword1", date)).addData(new WxMpTemplateData("keyword2", "提现到零钱")).addData(new WxMpTemplateData("keyword3", "" + amountInt)).addData(new WxMpTemplateData("remark", "感谢您的使用"));
                wxService.getTemplateMsgService().sendTemplateMsg(templateMessage);
                // 发送消息
                return null;
            // {{first.DATA}}{{fi
            // 申请时间:{{keyword1.DATA}}
            // 提现方式:{{keyword2.DATA}}
            // 提现金额:{{keyword3.DATA}}
            // 手续费用:{{keyword4.DATA}}
            // 到账金额:{{keyword5.DATA}}
            // {{remark.DATA}}
            } else {
                this.logger.error("err_code: " + wxEntPayResult.getErrCode() + "  err_code_des: " + wxEntPayResult.getErrCodeDes());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } catch (WxErrorException e) {
        logger.error("提现出错", e);
        return new TextBuilder().build(e.getMessage(), wxMessage, wxService);
    } catch (SocketException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : SocketException(java.net.SocketException) WxMpTemplateData(me.chanjar.weixin.mp.bean.template.WxMpTemplateData) WxMpUser(me.chanjar.weixin.mp.bean.result.WxMpUser) DecimalFormat(java.text.DecimalFormat) Charge(com.code.server.db.model.Charge) Date(java.util.Date) SocketException(java.net.SocketException) IOException(java.io.IOException) WxErrorException(me.chanjar.weixin.common.exception.WxErrorException) EntPayRequest(com.github.binarywang.wxpay.bean.entpay.EntPayRequest) WxErrorException(me.chanjar.weixin.common.exception.WxErrorException) AgentBean(com.code.server.constant.game.AgentBean) TextBuilder(com.code.server.login.wechat.builder.TextBuilder) WxMpTemplateMessage(me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage) EntPayResult(com.github.binarywang.wxpay.bean.entpay.EntPayResult) SimpleDateFormat(java.text.SimpleDateFormat)

Example 5 with AgentBean

use of com.code.server.constant.game.AgentBean in project summer by foxsugar.

the class SubscribeHandler method handleSpecial.

/**
 * 处理特殊请求,比如如果是扫码进来的,可以做相应处理
 */
private WxMpXmlOutMessage handleSpecial(WxMpXmlMessage wxMessage, WxMpUser wxMpUser, WxMpService wxMpService) {
    // 如果是扫码登录
    String eventKey = wxMessage.getEventKey();
    if (eventKey == null || "".equals(eventKey)) {
        return null;
    }
    String[] s = eventKey.split("_");
    logger.info("eventKey = " + eventKey);
    if ("qrscene".equals(s[0])) {
        String referrerUnionId = eventKey.split("qrscene_")[1];
        // "|" 的分隔符要转义
        String[] sp = referrerUnionId.split("\\|");
        if (sp.length > 1) {
            referrerUnionId = sp[1];
        }
        String unionId = wxMpUser.getUnionId();
        // 这个人是否已经点过
        // todo 自己不能推荐自己
        Recommend recommend = recommendService.getRecommendDao().getByUnionId(unionId);
        long agentId = userService.getUserDao().getIdByOpenId(referrerUnionId);
        AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
        if (agentBean == null) {
            return null;
        }
        boolean isSelf = referrerUnionId.equals(unionId);
        StringBuilder sb = new StringBuilder(wxMpUser.getNickname() + "扫描您的专属二维码,");
        if (recommend == null && !isSelf) {
            recommend = new Recommend();
            recommend.setUnionId(unionId).setAgentId(agentId);
            // 保存
            recommendService.getRecommendDao().save(recommend);
            sb.append("成功绑定");
        } else {
            // 通知 代理 有人绑定他
            // String name = wxMpUser.getNickname();
            // 这个人如果已经是玩家 并且玩家没有上级 那么成为这个人的下级
            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("但已绑定其他代理");
                            }
                        }
                    }
                }
            }
            try {
                wxMpService.getKefuService().sendKefuMessage(WxMpKefuMessage.TEXT().toUser(agentBean.getOpenId()).content(sb.toString()).build());
            } catch (WxErrorException e) {
                e.printStackTrace();
            }
        }
        // TODO
        return null;
    }
    return null;
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) User(com.code.server.db.model.User) WxMpUser(me.chanjar.weixin.mp.bean.result.WxMpUser) Recommend(com.code.server.db.model.Recommend) UserBean(com.code.server.constant.game.UserBean) WxErrorException(me.chanjar.weixin.common.exception.WxErrorException)

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