Search in sources :

Example 6 with ChildCost

use of com.code.server.constant.db.ChildCost in project summer by foxsugar.

the class PayCallback method callback.

/**
 * 接受微信回调
 *
 * @param
 */
@RequestMapping(value = "/callback")
public String callback(HttpServletRequest request, HttpServletResponse response) {
    System.out.println("接受回调参数");
    // 获取微信返回结果
    String parameterstr = PayUtil.ObtainParameterString(request);
    System.out.println("parameterstr:" + parameterstr);
    // 解析xmlString
    Element element = PayUtil.ParsingXML(parameterstr);
    SortedMap<String, String> secondParams = new TreeMap<>();
    secondParams.put("appid", element.elementText("appid"));
    secondParams.put("bank_type", element.elementText("bank_type"));
    secondParams.put("cash_fee", element.elementText("cash_fee"));
    secondParams.put("fee_type", element.elementText("fee_type"));
    secondParams.put("is_subscribe", element.elementText("is_subscribe"));
    secondParams.put("mch_id", element.elementText("mch_id"));
    secondParams.put("nonce_str", element.elementText("nonce_str"));
    secondParams.put("openid", element.elementText("openid"));
    secondParams.put("out_trade_no", element.elementText("out_trade_no"));
    secondParams.put("result_code", element.elementText("result_code"));
    secondParams.put("return_code", element.elementText("return_code"));
    secondParams.put("time_end", element.elementText("time_end"));
    secondParams.put("total_fee", element.elementText("total_fee"));
    secondParams.put("trade_type", element.elementText("trade_type"));
    secondParams.put("transaction_id", element.elementText("transaction_id"));
    String paySign = PayUtil.createSign("UTF-8", serverConfig.getKey(), secondParams);
    System.out.println(paySign);
    // 解析返回结果
    String returnXML = null;
    System.out.println("回调成功");
    // 业务返回成功
    Charge charge = chargeService.getChargeByOrderid(element.elementText("out_trade_no"));
    if ("SUCCESS".equals(element.elementText("result_code"))) {
        String transaction_id = element.elementText("transaction_id");
        charge.setTransaction_id(transaction_id);
        System.out.println("业务成功");
        System.out.println(charge.getMoney());
        System.out.println(element.elementText("cash_fee"));
        System.out.println(paySign);
        System.out.println(element.elementText("sign"));
        int money_total = Integer.valueOf(element.elementText("total_fee")) / 100;
        if (paySign.equals(element.elementText("sign")) && charge.getMoney() == money_total) {
            if (0 == charge.getStatus()) {
                System.out.println("修改订单状态");
                // 修改支付订单状态 已支付
                charge.setStatus(1);
                charge.setCallbacktime(new Date());
                double money = charge.getMoney();
                String dayStr = DateUtil.convert2DayString(new Date());
                Constant constant = constantDao.findOne(1l);
                User u = userService.getUserByUserId(charge.getUserid());
                logger.info("user is :{}", u);
                AgentUser agentUser1 = agentUserDao.findAgentUserByInvite_code(u.getReferee() + "");
                AgentInfo agentInfo1 = null;
                logger.info("AgentUser1 is :{}", agentUser1);
                if (agentUser1 != null) {
                    agentInfo1 = agentUser1.getAgentInfo();
                    logger.info("AgentInfo1 is :{}", agentInfo1);
                    Map<String, ChildCost> rs1 = agentInfo1.getEveryDayCost();
                    ChildCost childCost1 = rs1.get(dayStr);
                    if (childCost1 == null) {
                        childCost1 = new ChildCost();
                    }
                    logger.info("childCost1  is :{}", childCost1);
                    // 今日来源于玩家的收入
                    childCost1.firstLevel += money * constant.getIncome1() * 0.01;
                    rs1.put(dayStr, childCost1);
                    agentUserDao.save(agentUser1);
                }
                AgentUser agentUser2 = null;
                if (agentUser1 != null) {
                    agentUser2 = agentUserDao.findOne(agentUser1.getParentId());
                }
                logger.info("AgentUser2 is :{}", agentUser2);
                if (agentUser2 != null) {
                    AgentInfo agentInfo2 = agentUser2.getAgentInfo();
                    logger.info("AgentInfo2 is :{}", agentInfo2);
                    Map<String, ChildCost> rs2 = agentInfo2.getEveryDayCost();
                    ChildCost childCost2 = rs2.get(dayStr);
                    if (childCost2 == null) {
                        childCost2 = new ChildCost();
                    }
                    logger.info("childCost2  is :{}", childCost2);
                    // 今日来源于代理的收入
                    childCost2.secondLevel += money * constant.getIncome2() * 0.01;
                    rs2.put(dayStr, childCost2);
                    agentUserDao.save(agentUser2);
                }
                // 更新订单结算是否已经返利
                charge.setFinishTime(dayStr);
                // chargeDao.save(charge);
                logger.info("Charge  is :{}", charge);
                UserBean UserBeanRedis = userRedisService.getUserBean(charge.getUserid());
                int addMoney = Integer.valueOf(element.elementText("total_fee")) / 10;
                ServerConfig serverConfig = SpringUtil.getBean(ServerConfig.class);
                if (serverConfig.getChargeMap().containsKey(money_total)) {
                    addMoney = serverConfig.getChargeMap().get(money_total);
                }
                if (UserBeanRedis != null) {
                    // userRedisService.setUserMoney(charge.getUserid(),UserBeanRedis.getMoney() + Double.valueOf(element.elementText("total_fee")) / 10);
                    userRedisService.addUserMoney(charge.getUserid(), addMoney);
                    charge.setUsername(UserBeanRedis.getUsername());
                } else {
                    // 查询玩家
                    User user = userService.getUserByUserId(charge.getUserid());
                    System.out.println("修改玩家豆豆");
                    // 修改玩家豆豆
                    user.setMoney(user.getMoney() + addMoney);
                    charge.setUsername(user.getUsername());
                    userService.save(user);
                }
                // 保存订单
                chargeService.save(charge);
                System.out.println("通知客户端刷新充值");
                Map<String, String> rs = new HashMap<>();
                MsgSender.sendMsg2Player(new ResponseVo("userService", "refresh", rs), charge.getUserid());
            } else {
                Map<String, String> rs = new HashMap<>();
                rs.put("err_code", element.elementText("err_code"));
                rs.put("err_code_des", element.elementText("err_code_des"));
                ResponseVo vo = new ResponseVo("userService", "refresh", rs);
                vo.setCode(ErrorCode.ORDER_WAS_PAID);
                MsgSender.sendMsg2Player(vo, charge.getUserid());
            }
            /*returnXML = "<xml>";
                        returnXML += "<return_code>![CDATA[SUCCESS]]</return_code>";
		    		    returnXML += "<return_msg>![CDATA[OK]]</return_msg>";
		    		    returnXML += "</xml>";*/
            returnXML = "SUCCESS";
        } else {
            Map<String, String> rs = new HashMap<>();
            rs.put("err_code", element.elementText("err_code"));
            rs.put("err_code_des", element.elementText("err_code_des"));
            ResponseVo vo = new ResponseVo("userService", "refresh", rs);
            vo.setCode(ErrorCode.PARAMETER_SIGN_MONEY_ERROR);
            MsgSender.sendMsg2Player(vo, charge.getUserid());
            returnXML = "SUCCESS";
        }
    } else {
        // 余额不足
        if ("NOTENOUGH".equals(element.elementText("err_code"))) {
            Map<String, String> rs = new HashMap<>();
            rs.put("err_code", element.elementText("err_code"));
            rs.put("err_code_des", element.elementText("err_code_des"));
            ResponseVo vo = new ResponseVo("userService", "refresh", rs);
            vo.setCode(ErrorCode.BALANCE_INSUFFICIENT);
            MsgSender.sendMsg2Player(vo, charge.getUserid());
        // 订单已支付
        } else if ("ORDERPAID".equals(element.elementText("err_code"))) {
            Map<String, String> rs = new HashMap<>();
            rs.put("err_code", element.elementText("err_code"));
            rs.put("err_code_des", element.elementText("err_code_des"));
            ResponseVo vo = new ResponseVo("userService", "refresh", rs);
            vo.setCode(ErrorCode.ORDER_WAS_PAID);
            MsgSender.sendMsg2Player(vo, charge.getUserid());
        // 订单已关闭
        } else if ("ORDERCLOSED".equals(element.elementText("err_code"))) {
            Map<String, String> rs = new HashMap<>();
            rs.put("err_code", element.elementText("err_code"));
            rs.put("err_code_des", element.elementText("err_code_des"));
            ResponseVo vo = new ResponseVo("userService", "refresh", rs);
            vo.setCode(ErrorCode.ORDER_WAS_CLOSED);
            MsgSender.sendMsg2Player(vo, charge.getUserid());
        }
        returnXML = "SUCCESS";
    }
    System.out.println("回调结束,返回微信成功信息");
    System.out.println(returnXML);
    try {
        response.getWriter().write(returnXML);
        response.getWriter().flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return returnXML;
}
Also used : Element(org.dom4j.Element) IOException(java.io.IOException) ResponseVo(com.code.server.constant.response.ResponseVo) ServerConfig(com.code.server.login.config.ServerConfig) UserBean(com.code.server.constant.game.UserBean) ChildCost(com.code.server.constant.db.ChildCost) AgentInfo(com.code.server.constant.db.AgentInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with ChildCost

use of com.code.server.constant.db.ChildCost in project summer by foxsugar.

the class CenterMsgService method add51Rebate.

/**
 * 51号返利
 */
public static void add51Rebate(long userId, double num, boolean isAA) {
    UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
    int parent = userBean.getReferee();
    AgentUser agentUser1 = agentUserService.getAgentUserDao().findOne(parent);
    if (agentUser1 == null)
        return;
    String dayStr = DateUtil.convert2DayString(new Date());
    ServerConfig serverConfig = SpringUtil.getBean(ServerConfig.class);
    AgentInfo agentInfo1 = agentUser1.getAgentInfo();
    Map<String, ChildCost> rs1 = agentInfo1.getEveryDayCost();
    ChildCost childCost1 = rs1.getOrDefault(dayStr, new ChildCost());
    double rebateNum = getRebateNum(serverConfig, isAA, 1, agentUser1.getLevel(), num, agentUser1.getAgentType());
    childCost1.firstLevel += rebateNum;
    rs1.put(dayStr, childCost1);
    agentUserService.getAgentUserDao().save(agentUser1);
    rebateRecord(userBean, agentUser1, 1, num, rebateNum, isAA);
    AgentUser agentUser2 = agentUserService.getAgentUserDao().findOne(agentUser1.getParentId());
    if (agentUser2 != null) {
        AgentInfo agentInfo2 = agentUser2.getAgentInfo();
        Map<String, ChildCost> rs2 = agentInfo2.getEveryDayCost();
        ChildCost childCost2 = rs2.getOrDefault(dayStr, new ChildCost());
        double rebateNum2 = getRebateNum(serverConfig, isAA, 2, agentUser2.getLevel(), num, agentUser2.getAgentType());
        childCost2.secondLevel += rebateNum2;
        rs2.put(dayStr, childCost2);
        agentUserService.getAgentUserDao().save(agentUser2);
        rebateRecord(userBean, agentUser2, 2, num, rebateNum2, isAA);
        AgentUser agentUser3 = agentUserService.getAgentUserDao().findOne(agentUser2.getParentId());
        if (agentUser3 != null) {
            AgentInfo agentInfo3 = agentUser3.getAgentInfo();
            Map<String, ChildCost> rs3 = agentInfo3.getEveryDayCost();
            ChildCost childCost3 = rs3.getOrDefault(dayStr, new ChildCost());
            double rebate3 = getRebateNum(serverConfig, isAA, 3, agentUser3.getLevel(), num, agentUser3.getAgentType());
            childCost3.thirdLevel += rebate3;
            rs3.put(dayStr, childCost3);
            agentUserService.getAgentUserDao().save(agentUser3);
            rebateRecord(userBean, agentUser3, 3, num, rebate3, isAA);
        }
    }
}
Also used : ServerConfig(com.code.server.login.config.ServerConfig) UserBean(com.code.server.constant.game.UserBean) ChildCost(com.code.server.constant.db.ChildCost) AgentInfo(com.code.server.constant.db.AgentInfo) LocalDate(java.time.LocalDate)

Example 8 with ChildCost

use of com.code.server.constant.db.ChildCost in project summer by foxsugar.

the class HomeServiceImpl method showHomePage.

@Override
public HomePageVo showHomePage(long agentId) {
    AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
    HomePageVo homePageVo = new HomePageVo();
    homePageVo.setRebate(agentBean.getRebate());
    homePageVo.setInvitationCode("" + agentId);
    HomeChargeVo homeChargeVo = todayChargeService.showCharge(agentId);
    String total = homeChargeVo.getTotal();
    homePageVo.setTotalMoney((Double.parseDouble(total)));
    // 收益
    AgentInfo agentInfo = agentBean.getAgentInfo();
    String today = DateUtil.convert2DayString(new Date());
    Map<String, ChildCost> everyDayCos = agentInfo.getEveryDayCost();
    ChildCost childCost = everyDayCos.get(today);
    if (childCost != null) {
        homePageVo.setFirstLevel(childCost.getFirstLevel() * 0.01 * 0.2);
        homePageVo.setSecondLevel(childCost.getSecondLevel() * 0.01 * 0.1);
        homePageVo.setThirdLevel(childCost.getThirdLevel() * 0.01 * 0.1);
        // homePageVo.setAllCost(childCost.getFirstLevel() * 0.01 * 0.2 + childCost.getSecondLevel()* 0.01 * 0.1 + childCost.getThirdLevel() * 0.01 * 0.1);
        double allCost = (childCost.getFirstLevel() + childCost.getSecondLevel() + childCost.getThirdLevel()) * 0.01;
        homePageVo.setAllCost(allCost);
    }
    return homePageVo;
}
Also used : AgentBean(com.code.server.constant.game.AgentBean) HomePageVo(com.code.server.login.vo.HomePageVo) HomeChargeVo(com.code.server.login.vo.HomeChargeVo) ChildCost(com.code.server.constant.db.ChildCost) AgentInfo(com.code.server.constant.db.AgentInfo)

Aggregations

ChildCost (com.code.server.constant.db.ChildCost)8 AgentInfo (com.code.server.constant.db.AgentInfo)7 AgentBean (com.code.server.constant.game.AgentBean)3 UserBean (com.code.server.constant.game.UserBean)2 ServerConfig (com.code.server.login.config.ServerConfig)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseVo (com.code.server.constant.response.ResponseVo)1 AuthChecker (com.code.server.login.anotation.AuthChecker)1 HomeChargeVo (com.code.server.login.vo.HomeChargeVo)1 HomePageVo (com.code.server.login.vo.HomePageVo)1 IOException (java.io.IOException)1 LocalDate (java.time.LocalDate)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Element (org.dom4j.Element)1 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)1