From 5dc40fcd64b0513150f1d8335ab849e6d8cdc28e Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期五, 04 七月 2025 19:42:49 +0800
Subject: [PATCH] 支付版本更新 根据资金流向使用V2或V3服务商版本支付

---
 cloud-server-other/src/main/java/com/dsh/other/service/impl/SiteServiceImpl.java |  248 +++++++++++++++++--------------------------------
 1 files changed, 87 insertions(+), 161 deletions(-)

diff --git a/cloud-server-other/src/main/java/com/dsh/other/service/impl/SiteServiceImpl.java b/cloud-server-other/src/main/java/com/dsh/other/service/impl/SiteServiceImpl.java
index 0397da7..b49bc3e 100644
--- a/cloud-server-other/src/main/java/com/dsh/other/service/impl/SiteServiceImpl.java
+++ b/cloud-server-other/src/main/java/com/dsh/other/service/impl/SiteServiceImpl.java
@@ -457,7 +457,7 @@
         return ResultUtil.success();
     }
 
-
+    private String smidVx = "2088330203191220";//平台微信商户号
     /**
      * 课程微信支付
      *
@@ -474,98 +474,20 @@
         String merchantNumber = "";
         if (byId.getOperatorId()==null || byId.getOperatorId()==0){
             // 平台
-            isFenZhang = 0;
-        }
-        ResultUtil weixinpay = payMoneyUtil.weixinpay("预约场地-"+isFenZhang, id.toString(), code, paymentPrice.toString(),
+                    ResultUtil weixinpay = payMoneyUtil.weixinpay("预约场地-"+isFenZhang, id.toString(), code, paymentPrice.toString(),
                 "/base/site/weChatPaymentSiteCallback", "APP", "");
-        if (weixinpay.getCode() == 200) {
-            new Thread(new Runnable() {
-                @Override
-                public void run() {
-                    try {
-                        int num = 1;
-                        int wait = 0;
-                        while (num <= 10) {
-                            int min = 5000;
-                            wait += (min * num);
-                            Thread.sleep(wait);
-                            SiteBooking siteBooking = siteBookingService.getById(id);
-                            if (siteBooking.getStatus() != 0) {
-                                break;
-                            }
-                            ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(siteBooking.getOrderNo(), "");
-                            if (resultUtil.getCode() == 200 && siteBooking.getStatus() == 0) {
-                                /**
-                                 * SUCCESS—支付成功,
-                                 * REFUND—转入退款,
-                                 * NOTPAY—未支付,
-                                 * CLOSED—已关闭,
-                                 * REVOKED—已撤销(刷卡支付),
-                                 * USERPAYING--用户支付中,
-                                 * PAYERROR--支付失败(其他原因,如银行返回失败)
-                                 */
-                                Map<String, String> data1 = resultUtil.getData();
-                                String s = data1.get("trade_state");
-                                String transaction_id = data1.get("transaction_id");
-                                if ("REFUND".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s) || num == 10) {
-                                    break;
-                                }
-                                if ("SUCCESS".equals(s)) {
-                                    siteBooking.setPayTime(new Date());
-                                    siteBooking.setStatus(1);
-                                    siteBooking.setPayOrderNo(transaction_id);
-                                    siteBookingService.updateById(siteBooking);
-
-                                    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);
-                                            BigDecimal bigDecimal2 = new BigDecimal(paymentPrice);
-                                            ResultUtil fenzhang = payMoneyUtil.fenzhang(transaction_id, bigDecimal2.multiply(bigDecimal1), s2,nonce_str);
-                                            if (!fenzhang.getCode().equals(500)){
-                                                System.err.println("分账失败 原因是:"+fenzhang.getMsg());
-                                            }else{
-                                                siteBooking.setFenzhangNo(fenzhang.getMsg());
-                                                siteBooking.setFenzhangOrderNo(nonce_str);
-                                                siteBooking.setFenzhangAmount(bigDecimal2.multiply(bigDecimal1));
-                                                siteBookingService.updateById(siteBooking);
-                                            }
-                                        }
-                                    }
-
-                                    break;
-                                }
-                                if ("USERPAYING".equals(s) || "NOTPAY".equals(s)) {
-                                    num++;
-                                }
-                            }
-                        }
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                    }
-                }
-            }).start();
+                    return weixinpay;
+        }else{
+            String smidVx= operatorUserService.getmerchantNumberByOperatorId(byId.getOperatorId());
+            if (!StringUtils.hasLength(smidVx)){
+                return ResultUtil.error("运营商未配置微信商户号,获取支付失败!");
+            }
+            return payMoneyUtil.weixinpayV3(smidVx,"预约场地"
+                    ,code,"/base/site/weChatPaymentSiteCallback1",
+                    paymentPrice.toString(),id.toString());
         }
-        return weixinpay;
+
+
     }
 
     private String smid = "2088330203191220";//平台支付宝商户号
@@ -594,76 +516,76 @@
         }else if (operatorId == 0){
             smid1 = smid;
         }else{
-            smid1 = siteService.getSMIDByOperatorId(operatorId);
+            smid1 = siteService.getmerchantNumberAliByOperatorId(operatorId);
 
         }
         ResultUtil alipay = payMoneyUtil.alipay(smid1,"预约场地", "预约场地", id.toString(), code, paymentPrice.toString(), "/base/site/aliPaymentSiteCallback");
         System.out.println("预约场地----" + alipay.getCode());
-        if (alipay.getCode() == 200) {
-            new Thread(new Runnable() {
-                @Override
-                public void run() {
-                    try {
-                        int num = 1;
-                        int wait = 0;
-                        while (num <= 10) {
-                            int min = 5000;
-                            wait += (min * num);
-                            Thread.sleep(wait);
-                            SiteBooking siteBooking = siteBookingService.getById(id);
-                            if (siteBooking.getStatus() != 0) {
-                                break;
-                            }
-                            AlipayTradeQueryResponse resultUtil = payMoneyUtil.queryALIOrder(code);
-                            if (resultUtil.getCode().equals("10000") && siteBooking.getStatus() == 0) {
-                                /**
-                                 * WAIT_BUYER_PAY(交易创建,等待买家付款)、
-                                 * TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、
-                                 * TRADE_SUCCESS(交易支付成功)、
-                                 * TRADE_FINISHED(交易结束,不可退款)
-                                 */
-//                                Map<String, String> data1 = resultUtil.getData();
-//                                String s = data1.get("tradeStatus");
-                                String tradeNo = resultUtil.getTradeNo();
-                                String s = resultUtil.getTradeStatus();
-                                System.out.println("ssssss" + s);
-                                if ("TRADE_CLOSED".equals(s) || "TRADE_FINISHED".equals(s) || num == 10) {
-                                    break;
-                                }
-                                if ("TRADE_SUCCESS".equals(s)) {
-                                    siteBooking.setPayTime(new Date());
-                                    siteBooking.setStatus(1);
-                                    siteBooking.setPayOrderNo(tradeNo);
-                                    siteBookingService.updateById(siteBooking);
-                                    System.err.println("======完成支付");
-                                    // 判断预约的门店 属于哪个运营商
-                                    Integer storeId = siteBooking.getStoreId();
-                                    Store byId = storeService.getById(storeId);
-                                    Integer operatorId = byId.getOperatorId();
-                                    String smid1 = "";
-                                    if (operatorId == null || operatorId == 0){
-                                        // 平台的门店 不冻结资金不做分账处理
-                                        payMoneyUtil.confirm1(smid1,code,tradeNo,paymentPrice.toString());
-                                    }else{
-                                        smid1 = siteService.getSMIDByOperatorId(operatorId);
-                                        payMoneyUtil.confirm(smid1,code,tradeNo,paymentPrice.toString());
-                                        // 分账
-                                        extracted(operatorId, new BigDecimal(paymentPrice.toString()), tradeNo);
-                                    }
-
-                                    break;
-                                }
-                                if ("WAIT_BUYER_PAY".equals(s)) {
-                                    num++;
-                                }
-                            }
-                        }
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                    }
-                }
-            }).start();
-        }
+//        if (alipay.getCode() == 200) {
+//            new Thread(new Runnable() {
+//                @Override
+//                public void run() {
+//                    try {
+//                        int num = 1;
+//                        int wait = 0;
+//                        while (num <= 10) {
+//                            int min = 5000;
+//                            wait += (min * num);
+//                            Thread.sleep(wait);
+//                            SiteBooking siteBooking = siteBookingService.getById(id);
+//                            if (siteBooking.getStatus() != 0) {
+//                                break;
+//                            }
+//                            AlipayTradeQueryResponse resultUtil = payMoneyUtil.queryALIOrder(code);
+//                            if (resultUtil.getCode().equals("10000") && siteBooking.getStatus() == 0) {
+//                                /**
+//                                 * WAIT_BUYER_PAY(交易创建,等待买家付款)、
+//                                 * TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、
+//                                 * TRADE_SUCCESS(交易支付成功)、
+//                                 * TRADE_FINISHED(交易结束,不可退款)
+//                                 */
+////                                Map<String, String> data1 = resultUtil.getData();
+////                                String s = data1.get("tradeStatus");
+//                                String tradeNo = resultUtil.getTradeNo();
+//                                String s = resultUtil.getTradeStatus();
+//                                System.out.println("ssssss" + s);
+//                                if ("TRADE_CLOSED".equals(s) || "TRADE_FINISHED".equals(s) || num == 10) {
+//                                    break;
+//                                }
+//                                if ("TRADE_SUCCESS".equals(s)) {
+//                                    siteBooking.setPayTime(new Date());
+//                                    siteBooking.setStatus(1);
+//                                    siteBooking.setPayOrderNo(tradeNo);
+//                                    siteBookingService.updateById(siteBooking);
+//                                    System.err.println("======完成支付");
+//                                    // 判断预约的门店 属于哪个运营商
+//                                    Integer storeId = siteBooking.getStoreId();
+//                                    Store byId = storeService.getById(storeId);
+//                                    Integer operatorId = byId.getOperatorId();
+//                                    String smid1 = "";
+//                                    if (operatorId == null || operatorId == 0){
+//                                        // 平台的门店 不冻结资金不做分账处理
+//                                        payMoneyUtil.confirm1(smid1,code,tradeNo,paymentPrice.toString());
+//                                    }else{
+//                                        smid1 = siteService.getSMIDByOperatorId(operatorId);
+//                                        payMoneyUtil.confirm(smid1,code,tradeNo,paymentPrice.toString());
+//                                        // 分账
+//                                        extracted(operatorId, new BigDecimal(paymentPrice.toString()), tradeNo);
+//                                    }
+//
+//                                    break;
+//                                }
+//                                if ("WAIT_BUYER_PAY".equals(s)) {
+//                                    num++;
+//                                }
+//                            }
+//                        }
+//                    } catch (Exception e) {
+//                        e.printStackTrace();
+//                    }
+//                }
+//            }).start();
+//        }
         return alipay;
     }
 
@@ -807,12 +729,11 @@
                     String randomCode = UUIDUtil.getRandomCode(16);
                     String randomCode1 = UUIDUtil.getRandomCode(16);
                     if (byId.getOperatorId()!=null && byId.getOperatorId()!=0){
-                        // 休眠两分钟后再调用分账接口 避免提示订单正在处理中
                         // 微信商户号
                         String s2 =siteService.getmerchantNumberByOperatorId(byId.getOperatorId());
-                        ResultUtil resultUtil = payMoneyUtil.fenzhangRefund(siteBooking.getFenzhangNo(), siteBooking.getFenzhangAmount(), s2, randomCode, randomCode1);
-                        if (!resultUtil.getCode().equals(500)){
-                            System.err.println("分账回退失败 原因是:"+resultUtil.getMsg());
+                        ResultUtil resultUtil = payMoneyUtil.fenzhangRefund(siteBooking.getFenzhangNo(), siteBooking.getFenzhangAmount().multiply(new BigDecimal("100")), s2, randomCode, randomCode1);
+                        if (!resultUtil.getCode().equals(200)){
+                            System.err.println("分账回退失败 原因是:"+resultUtil.getMsg()+resultUtil.getData());
                         }else{
                             siteBooking.setFenzhangRefundNo(resultUtil.getMsg());
                             siteBookingService.updateById(siteBooking);
@@ -1046,4 +967,9 @@
     public String getmerchantNumberByOperatorId(Integer id) {
         return siteMapper.getmerchantNumberByOperatorId(id);
     }
+
+    @Override
+    public String getmerchantNumberAliByOperatorId(Integer id) {
+        return siteMapper.getmerchantNumberAliByOperatorId(id);
+    }
 }

--
Gitblit v1.7.1