无关风月
2025-05-08 9486766c806fe1d9e082b2fd02ea1cc558f1b443
cloud-server-other/src/main/java/com/dsh/other/controller/GameController.java
@@ -150,10 +150,11 @@
            if (null == uid) {
                return ResultUtil.tokenErr();
            }
            //判断当前用户是否是员工
            AppUser appUser1 = appUserClient.queryAppUser(uid);
            User one = userService.getOne(new QueryWrapper<User>().eq("phone", appUser1.getPhone()).eq("status", 1));
            if (null != one) {
            //判断当前用户是否是员工
            List<User> one = userService.list(new QueryWrapper<User>().eq("phone", appUser1.getPhone()).eq("status", 1));
            if (!one.isEmpty()) {
                return ResultUtil.success(1);
            }
            //普通用户校验当前时间是否在预约时间段内
@@ -198,17 +199,19 @@
                return ResultUtil.tokenErr();
            }
            Site byId = siteService.getById(spaceId);
            Store byId1 = storeService.getById(byId.getStoreId());
            // 是否分账 0否1是
            int isFenZhang= 1;
            String merchantNumber = "";
            if (byId.getOperatorId()==null || byId.getOperatorId()==0){
            if (byId1.getOperatorId()==null || byId1.getOperatorId()==0){
                // 平台
                isFenZhang = 0;
            }
            //判断当前用户是否是员工
            AppUser appUser1 = appUserClient.queryAppUser(uid);
            User one = userService.getOne(new QueryWrapper<User>().eq("phone", appUser1.getPhone()).eq("status", 1));
            if (null != one) {
            List<User> one = userService.list(new QueryWrapper<User>().eq("phone", appUser1.getPhone()).eq("status", 1));
            if (!one.isEmpty()) {
                Integer integer = startGame(uid, gameType, gameId, spaceId, sutuId);
                return ResultUtil.success();
            }
@@ -221,14 +224,17 @@
            tGameRecord.setUserId(uid);
            tGameRecord.setNumber(code);
            tGameRecord.setTime(new Date());
            tGameRecord.setSiteId(spaceId);
            gameRecordService.save(tGameRecord);
            System.err.println("启动游戏支付");
            if (type == 1) {
                tGameRecord.setMoney(config.getCash());
                gameRecordService.updateById(tGameRecord);
                String params = uid + "_" + gameId + "_" + spaceId + "_" + sutuId+"_"+code+"_"+configId + "_" + gameType;
                ResultUtil weixinpay = payMoneyUtil.weixinpay("游戏支付-"+isFenZhang, params, code, config.getCash().toString(),
                        "/base/game/wechatPaymentGameCallback", "APP", "");
                System.err.println("启动游戏支付");
                if (weixinpay.getCode() == 200) {
                    new Thread(new Runnable() {
                        @Override
@@ -271,41 +277,7 @@
                                            }
                                            gameRecordService.updateBatchById(list);
                                            Integer integer = startGame(uid, gameType, gameId, spaceId, sutuId);
                                            if (byId.getOperatorId()!=null && byId.getOperatorId()!=0){
                                                // 休眠两分钟后再调用分账接口 避免提示订单正在处理中
                                                Thread.sleep(120000);
                                                // 根据运营商id获取对应运营商分账比例 返回格式: 微信分账比例,支付宝分账比例
                                                OperatorUser operatorId = operatorUserService.getOne(
                                                        new QueryWrapper<OperatorUser>().eq("operatorId",byId.getOperatorId())
                                                );
                                                if (operatorId.getWechatProportion() == null){
                                                    operatorId.setWechatProportion("0");
                                                }
                                                if (operatorId.getAlipayProportion() == null){
                                                    operatorId.setAlipayProportion("0");
                                                }
                                                String proportion=  operatorId.getWechatProportion()+","+operatorId.getAlipayProportion();
                                                String[] split = proportion.split(",");
                                                String s1 = split[0];
                                                if (!s1.equals("未设置")){
                                                    BigDecimal bigDecimal = new BigDecimal(s1);
                                                    // 分账比例
                                                    BigDecimal bigDecimal1 = bigDecimal.divide(new BigDecimal(100)).setScale(2);
                                                    // 微信商户号
                                                    String s2 =siteService.getmerchantNumberByOperatorId(byId.getOperatorId());
                                                    String nonce_str = UUIDUtil.getRandomCode(16);
                                                    ResultUtil fenzhang = payMoneyUtil.fenzhang(transaction_id, config.getCash().multiply(bigDecimal1), s2,nonce_str);
                                                    if (!fenzhang.getCode().equals(500)){
                                                        System.err.println("分账失败 原因是:"+fenzhang.getMsg());
                                                    }else{
                                                            tGameRecord.setFenzhangNo(fenzhang.getMsg());
                                                            tGameRecord.setFenzhangOrderNo(nonce_str);
                                                            tGameRecord.setFenzhangAmount(config.getCash().multiply(bigDecimal1));
                                                            gameRecordService.updateById(tGameRecord);
                                                    }
                                                }
                                            }
                                            break;
                                        }
@@ -507,11 +479,15 @@
    }
    @Resource
    private StoreService storeService;
    @ResponseBody
    @PostMapping("/base/game/wechatPaymentGameCallback")
    public void wechatPaymentGameCallback(HttpServletRequest request, HttpServletResponse response){
    public void wechatPaymentGameCallback(HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.err.println("进入游戏回调");
        Map<String, String> map = payMoneyUtil.weixinpayCallback(request);
        System.err.println("回调参数"+map);
        if(null != map){
            String out_trade_no = map.get("out_trade_no");
            String transaction_id = map.get("transaction_id");
@@ -537,6 +513,51 @@
            gameRecordService.updateBatchById(list);
            String[] s = attach.split("_");
            Integer integer = startGame(Integer.valueOf(s[0]), Integer.valueOf(s[6]), Integer.valueOf(s[1]), Integer.valueOf(s[2]), Integer.valueOf(s[3]));
            TGameRecord one = gameRecordService.getOne(new QueryWrapper<TGameRecord>().eq("number", out_trade_no).eq("payType", 1));
            System.err.println("游戏支付记录"+one);
            if (one!=null){
                Integer gameId = one.getGameId();
                Site byId1 = siteService.getById(one.getSiteId());
                Store byId = storeService.getById(byId1.getStoreId());
                if (byId!=null){
                    if (byId.getOperatorId()!=null && byId.getOperatorId()!=0){
                        // 休眠两分钟后再调用分账接口 避免提示订单正在处理中
                        Thread.sleep(120000);
                        // 根据运营商id获取对应运营商分账比例 返回格式: 微信分账比例,支付宝分账比例
                        OperatorUser operatorId = operatorUserService.getOne(
                                new QueryWrapper<OperatorUser>().eq("operatorId",byId.getOperatorId())
                        );
                        if (operatorId.getWechatProportion() == null){
                            operatorId.setWechatProportion("0");
                        }
                        if (operatorId.getAlipayProportion() == null){
                            operatorId.setAlipayProportion("0");
                        }
                        String proportion=  operatorId.getWechatProportion()+","+operatorId.getAlipayProportion();
                        String[] split = proportion.split(",");
                        String s1 = split[0];
                        if (!s1.equals("未设置")){
                            BigDecimal bigDecimal = new BigDecimal(s1);
                            // 分账比例
                            BigDecimal bigDecimal1 = bigDecimal.divide(new BigDecimal(100)).setScale(2);
                            // 微信商户号
                            String s2 =siteService.getmerchantNumberByOperatorId(byId.getOperatorId());
                            String nonce_str = UUIDUtil.getRandomCode(16);
                            ResultUtil fenzhang = payMoneyUtil.fenzhang(transaction_id, one.getMoney().multiply(bigDecimal1), s2,nonce_str,"玩游戏分账");
                            if (!fenzhang.getCode().equals(200)){
                                System.err.println("分账失败 原因是:"+fenzhang.getMsg());
                            }else{
                                one.setFenzhangNo(fenzhang.getData().toString());
                                one.setFenzhangOrderNo(nonce_str);
                                one.setFenzhangAmount(one.getMoney().multiply(bigDecimal1));
                                gameRecordService.updateById(one);
                            }
                        }
                    }
                }
            }
            PrintWriter out = null;
            try {