Search in sources :

Example 21 with AgentBean

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

the class AgentRedisService method addPartnerRebate.

public void addPartnerRebate(long agentId, double cost, double moneyRebate, double goldRebate, String date, String deleteDay) {
    AgentBean agentBean = getAgentBean(agentId);
    if (agentBean != null) {
        if (agentBean.getAgentInfo().getEveryPartnerRebate() == null) {
            agentBean.getAgentInfo().setEveryPartnerRebate(new HashMap<>());
        }
        PartnerRebate partnerRebate = agentBean.getAgentInfo().getEveryPartnerRebate().getOrDefault(date, new PartnerRebate());
        partnerRebate.cost += cost;
        partnerRebate.moneyRebate += moneyRebate;
        partnerRebate.goldRebate += goldRebate;
        partnerRebate.allRebate += moneyRebate;
        partnerRebate.allRebate += goldRebate;
        agentBean.getAgentInfo().getEveryPartnerRebate().put(date, partnerRebate);
        agentBean.getAgentInfo().getEveryPartnerRebate().remove(deleteDay);
        updateAgentBean(agentBean);
    }
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) PartnerRebate(com.code.server.constant.db.PartnerRebate)

Example 22 with AgentBean

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

the class AgentRedisService method addRebate.

// 1、直接玩家(房卡55%、金币20%)
// 2、2级代理(房卡10%、金币10%)
// 3、3级代理(房卡5%、金币10%)
public void addRebate(long userId, long parentId, int type, double num, double childCost) {
    long agentId1 = 0;
    long agentId2 = 0;
    long agentId3 = 0;
    long partnerId = 0;
    // 没有上级代理
    // if (parentId == 0) return;
    // 自己是否是代理
    AgentBean agent1 = RedisManager.getAgentRedisService().getAgentBean(userId);
    if (agent1 == null) {
        // 自己是代理则自己就是1级代理
        agent1 = RedisManager.getAgentRedisService().getAgentBean(parentId);
    }
    if (agent1 != null) {
        agentId1 = agent1.getId();
        AgentBean agent2 = RedisManager.getAgentRedisService().getAgentBean(agent1.getParentId());
        if (agent2 != null) {
            agentId2 = agent2.getId();
            agentId3 = agent2.getParentId();
        }
        // 合伙人
        partnerId = agent1.getPartnerId();
    }
    // if(agent1 == null) return;
    int scala1 = getScala(type, 1);
    int scala2 = getScala(type, 2);
    int scala3 = getScala(type, 3);
    String today = LocalDate.now().toString();
    String deleteDay = LocalDate.now().minusDays(7).toString();
    String deleteDay1 = LocalDate.now().minusDays(90).toString();
    String deleteDay2 = LocalDate.now().minusDays(3).toString();
    double allRebate = 0;
    if (agentId1 != 0) {
        double n = scala1 * num / 100;
        allRebate += n;
        addRebate(agentId1, n, today, deleteDay);
        addChildCost(agentId1, childCost, 1, today, deleteDay1);
    }
    if (agentId2 != 0) {
        double n = scala2 * num / 100;
        allRebate += n;
        addRebate(agentId2, n, today, deleteDay);
        addChildCost(agentId2, childCost, 2, today, deleteDay1);
    }
    if (agentId3 != 0) {
        double n = scala3 * num / 100;
        allRebate += n;
        addRebate(agentId3, n, today, deleteDay);
        addChildCost(agentId3, childCost, 3, today, deleteDay1);
    }
    // 合伙人 10%
    if (partnerId != 0) {
        double n = 10 * num / 100;
        allRebate += n;
        // addRebate(partnerId, n,today,deleteDay);
        // addChildCost(agentId1,childCost,0,today, deleteDay1);
        System.out.println("合伙人 返利");
        if (type == 0) {
            addPartnerRebate(partnerId, childCost, n, 0, today, deleteDay2);
        } else {
            addPartnerRebate(partnerId, childCost, 0, n, today, deleteDay2);
        }
    }
    if (type == 0) {
        // 房卡返利
        RedisManager.getLogRedisService().addChargeRebate(allRebate);
    }
}
Also used : AgentBean(com.code.server.constant.game.AgentBean)

Example 23 with AgentBean

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

the class AgentRedisService method addChildCost.

public void addChildCost(long agentId, double cost, int level, String date, String deleteDay) {
    AgentBean agentBean = getAgentBean(agentId);
    if (agentBean != null) {
        if (cost > 0) {
            if (agentBean.getAgentInfo().getEveryDayCost() == null) {
                agentBean.getAgentInfo().setEveryDayCost(new HashMap<>());
            }
            ChildCost childCost = agentBean.getAgentInfo().getEveryDayCost().getOrDefault(date, new ChildCost());
            switch(level) {
                case 0:
                    childCost.partner += cost;
                    break;
                case 1:
                    childCost.firstLevel += cost;
                    break;
                case 2:
                    childCost.secondLevel += cost;
                    break;
                case 3:
                    childCost.thirdLevel += cost;
                    break;
            }
            agentBean.getAgentInfo().getEveryDayCost().put(date, childCost);
            agentBean.getAgentInfo().getEveryDayRebate().remove(deleteDay);
            // 
            // //历史总返利
            // double allRebate = agentBean.getAgentInfo().getAllRebate();
            // allRebate += rebate;
            // agentBean.getAgentInfo().setAllRebate(allRebate);
            // //每日返利
            // Map<String,Double> everyDayRebate = agentBean.getAgentInfo().getEveryDayRebate();
            // 
            // double todayRebate = everyDayRebate.getOrDefault(date, 0D);
            // todayRebate += rebate;
            // everyDayRebate.putIfAbsent(date, todayRebate);
            // //删除记录
            // everyDayRebate.remove(deleteDay);
            updateAgentBean(agentBean);
        }
    }
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) ChildCost(com.code.server.constant.db.ChildCost)

Example 24 with AgentBean

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

the class WechatPayController method pay.

private void pay(HttpServletRequest request, HttpServletResponse response, String mchKey) {
    try {
        synchronized (lock) {
            Map<String, String> kvm = XMLUtil.parseRequestXmlToMap(request);
            if (SignUtils.checkSign(kvm, null, mchKey)) {
                if (kvm.get("result_code").equals("SUCCESS")) {
                    String orderId = kvm.get("out_trade_no");
                    Charge charge = chargeService.getChargeByOrderid(orderId);
                    if (0 == charge.getStatus()) {
                        long userId = charge.getUserid();
                        // System.out.println("修改订单状态");
                        // 修改支付订单状态 已支付
                        charge.setStatus(1);
                        charge.setCallbacktime(new Date());
                        UserBean userBeanRedis = userRedisService.getUserBean(userId);
                        double rmb = charge.getMoney();
                        double addMoney = charge.getMoney_point();
                        double before = 0;
                        double after = 0;
                        int referee = 0;
                        long a1 = 0;
                        long a2 = 0;
                        long a3 = 0;
                        if (userBeanRedis != null) {
                            referee = userBeanRedis.getReferee();
                            UserInfo userInfo = userBeanRedis.getUserInfo();
                            if (charge.getChargeType() == 0) {
                                userInfo.setChargeMoneyNum(userInfo.getChargeMoneyNum() + rmb);
                                before = userBeanRedis.getMoney();
                                after = userRedisService.addUserMoney(userId, addMoney);
                            } else {
                                userInfo.setChargeGoldNum(userInfo.getChargeGoldNum() + rmb);
                                before = userBeanRedis.getGold();
                                after = userRedisService.addUserGold(userId, addMoney);
                            }
                        } else {
                            // 查询玩家
                            User user = userService.getUserByUserId(userId);
                            referee = user.getReferee();
                            UserInfo userInfo = user.getUserInfo();
                            // 修改玩家货币
                            if (charge.getChargeType() == 0) {
                                before = user.getMoney();
                                user.setMoney(user.getMoney() + addMoney);
                                after = user.getMoney() + addMoney;
                                userInfo.setChargeMoneyNum(userInfo.getChargeMoneyNum() + rmb);
                            } else {
                                before = user.getGold();
                                user.setGold(user.getGold() + addMoney);
                                after = user.getGold() + addMoney;
                                userInfo.setChargeGoldNum(userInfo.getChargeGoldNum() + rmb);
                            }
                            userService.save(user);
                        }
                        AgentBean agent1 = RedisManager.getAgentRedisService().getAgentBean(userId);
                        if (agent1 == null) {
                            agent1 = RedisManager.getAgentRedisService().getAgentBean(referee);
                        }
                        if (agent1 != null) {
                            a1 = agent1.getId();
                            a2 = agent1.getParentId();
                            AgentBean agent2 = RedisManager.getAgentRedisService().getAgentBean(a2);
                            if (agent2 != null) {
                                a3 = agent2.getParentId();
                            }
                        }
                        charge.setA1(a1);
                        charge.setA2(a2);
                        charge.setA3(a3);
                        // 保存充值记录
                        charge.setCharge_before_money(before);
                        charge.setCharge_after_money(after);
                        chargeService.save(charge);
                        // 记录到reids
                        RedisManager.getLogRedisService().logCharge(1, charge.getChargeType(), charge.getMoney());
                        Map<String, String> rs = new HashMap<>();
                        MsgSender.sendMsg2Player(new ResponseVo("userService", "refresh", rs), charge.getUserid());
                        // 如果在游戏中 刷新
                        String roomId = RedisManager.getUserRedisService().getRoomId(userId);
                        if (roomId != null) {
                            String serverId = RedisManager.getRoomRedisService().getServerId(roomId);
                            if (serverId != null) {
                                KafkaMsgKey msgKey = new KafkaMsgKey();
                                msgKey.setRoomId(roomId);
                                int partitionId = Integer.valueOf(serverId);
                                msgKey.setPartition(partitionId);
                                msgKey.setUserId(userId);
                                MsgProducer msgProducer = SpringUtil.getBean(MsgProducer.class);
                                ResponseVo responseVo = new ResponseVo();
                                responseVo.setService("roomService");
                                responseVo.setMethod("pushScoreChange");
                                responseVo.setParams("inner");
                                msgProducer.send2Partition("roomService", partitionId, msgKey, responseVo);
                            }
                        }
                        // 扣6%的税
                        if (charge.getChargeType() == 0) {
                            // double num = charge.getMoney() * 94 / 100;
                            double num = charge.getMoney();
                            RedisManager.getAgentRedisService().addRebate(userId, referee, charge.getChargeType(), num, 0);
                        }
                    }
                    logger.info("out_trade_no: " + kvm.get("out_trade_no") + " pay SUCCESS!");
                    response.getWriter().write("<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[ok]]></return_msg></xml>");
                } else {
                    this.logger.error("out_trade_no: " + kvm.get("out_trade_no") + " result_code is FAIL");
                    response.getWriter().write("<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[result_code is FAIL]]></return_msg></xml>");
                }
            } else {
                response.getWriter().write("<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[check signature FAIL]]></return_msg></xml>");
                this.logger.error("out_trade_no: " + kvm.get("out_trade_no") + " check signature FAIL");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : User(com.code.server.db.model.User) MsgProducer(com.code.server.kafka.MsgProducer) Charge(com.code.server.db.model.Charge) UserInfo(com.code.server.constant.db.UserInfo) ResponseVo(com.code.server.constant.response.ResponseVo) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AgentBean(com.code.server.constant.game.AgentBean) UserBean(com.code.server.constant.game.UserBean) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey)

Example 25 with AgentBean

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

the class LoginAction method login4sqlByOpenId.

private int login4sqlByOpenId(String openId, String unionId, String userName, String img, int sex, Map<String, Object> params) {
    User user = userService.getUserByOpenId(openId);
    // 查询数据库,没有新建玩家
    if (user == null) {
        // 新建玩家
        user = createUser(openId, unionId, userName, img, sex);
        // 代理推荐情况
        Recommend recommend = recommendService.getRecommendDao().getByUnionId(openId);
        if (recommend != null) {
            // 玩家设置代理
            user.setReferee((int) recommend.getAgentId());
        }
        // 保存
        userService.save(user);
        ServerConfig serverConfig = SpringUtil.getBean(ServerConfig.class);
        if (!"".equals(serverConfig.getQrDir())) {
            ZXingUtil.createQrCode(user.getId());
        }
        // reids 记录新增玩家
        RedisManager.getLogRedisService().logRegisterUser();
        if (recommend != null) {
            // 代理多了一个玩家
            AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(recommend.getAgentId());
            if (agentBean != null) {
                if (!agentBean.getChildList().contains(user.getId())) {
                    agentBean.getChildList().add(user.getId());
                    RedisManager.getAgentRedisService().updateAgentBean(agentBean);
                }
                // 通知
                try {
                    wxMpService.getKefuService().sendKefuMessage(WxMpKefuMessage.TEXT().toUser(agentBean.getOpenId()).content(userName + " 下载并进入游戏,和您成功绑定").build());
                } catch (WxErrorException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    String token = getToken(user.getId());
    saveUser2Redis(user, token);
    params.put("token", token);
    params.put("userId", "" + user.getId());
    return 0;
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) ServerConfig(com.code.server.login.config.ServerConfig) User(com.code.server.db.model.User) Recommend(com.code.server.db.model.Recommend) 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