From c4664502dfdaffff555b532e65b51a57ac8b29c2 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期三, 16 十月 2024 17:51:32 +0800
Subject: [PATCH] 合并代码

---
 ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/controller/WxPayController.java |   96 +++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 83 insertions(+), 13 deletions(-)

diff --git a/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/controller/WxPayController.java b/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/controller/WxPayController.java
index d51b017..546a0b7 100644
--- a/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/controller/WxPayController.java
+++ b/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/controller/WxPayController.java
@@ -3,9 +3,13 @@
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.web.domain.AjaxResult;
+import com.ruoyi.order.api.feignClient.ChargingOrderClient;
+import com.ruoyi.order.api.feignClient.OrderClient;
+import com.ruoyi.order.api.feignClient.ShoppingOrderClient;
 import com.ruoyi.payment.api.vo.PaymentOrder;
+import com.ruoyi.payment.api.vo.WxRefundNotifyResp;
 import com.ruoyi.payment.wx.enums.RefundEnum;
-import com.ruoyi.payment.wx.model.WxPaymentRefundModel;
+import com.ruoyi.payment.api.model.WxPaymentRefundModel;
 import com.ruoyi.payment.wx.resp.NotifyV3PayDecodeRespBody;
 import com.ruoyi.payment.wx.utils.WxV3Pay;
 import io.swagger.annotations.Api;
@@ -14,6 +18,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
 import java.math.BigDecimal;
@@ -31,6 +36,16 @@
 public class WxPayController {
     @Autowired
     private WxV3Pay wxV3Pay;
+
+    @Resource
+    private OrderClient orderClient;
+    
+    @Resource
+    private ChargingOrderClient chargingOrderClient;
+
+    @Resource
+    private ShoppingOrderClient shoppingOrderClient;
+
 
 
     /**
@@ -79,32 +94,63 @@
         // TODO 退款业务处理
         return AjaxResult.success();
     }
-
+    /**
+     * 微信v3支付-订单退款 远程调用
+     *
+     * @return
+     */
+    @ApiOperation("订单退款")
+    @PostMapping(value = "refundOrderR")
+    public R<String> refundOrderR(@RequestBody WxPaymentRefundModel model) {
+        Map<String, Object> result = wxV3Pay.refund(model);
+        log.info("退款结果:{}", result);
+        // 微信支付退款单号
+        String refund_id = result.get("refund_id").toString();
+        // 商户退款单号
+        String out_refund_no = result.get("out_refund_no").toString();
+        // 微信支付订单号
+        String transaction_id = result.get("transaction_id").toString();
+        // 商户订单号 tradeNo
+        String out_trade_no = result.get("out_trade_no").toString();
+        // 退款成功时间
+        String success_time = Objects.nonNull(result.get("success_time")) ? result.get("success_time").toString() : null;
+        // 退款状态 RefundEnum
+        String status = result.get("status").toString();
+        return R.ok(status);
+    }
     /**
      * 支付回调
      */
     @PostMapping("pay/notify")
-    public R<Map<String, Object>> payNotify(HttpServletRequest request) throws Exception {
+    @ApiOperation("订单回调")
+    public void payNotify(HttpServletRequest request) throws Exception {
         try {
             Map<String, Object> params = wxV3Pay.verifyNotify(request, new TypeReference<Map<String, Object>>() {});
             log.info("支付回调:{}", params);
-            String outRefundNo = (String) params.get("out_refund_no");
+            String outRefundNo = (String) params.get("transaction_id");
             String out_trade_no = params.get("out_trade_no").toString();
-            String substring = outRefundNo.substring(0, 2);
+            String attach = params.get("attach").toString();
+            String substring = out_trade_no.substring(0, 2);
             switch (substring){
                 //购物订单
                 case "GW":
-
+                    R r = orderClient.callBack(out_trade_no, outRefundNo);
+                    System.err.println("----收到购物回调");
+                    break;
+                case "HY":
+                    orderClient.vipCallBack(out_trade_no,outRefundNo);
+                    System.err.println("----收到会员回调");
+                    break;
+                case "CD":
+                    chargingOrderClient.chargingOrderWXCallback(out_trade_no, outRefundNo, attach);
+                    System.err.println("----充电支付回调");
                     break;
             }
-
-            return R.ok(params);
+            wxV3Pay.ack();
         } catch (Exception e) {
             log.error("支付回调异常:{}", e, e);
             wxV3Pay.ack(false, e.getMessage());
-            return R.fail("回调异常");
         }
-
     }
     
     /**
@@ -131,7 +177,7 @@
             Map<String, Object> params = wxV3Pay.verifyNotify(request, new TypeReference<Map<String, Object>>() {
             });
             // 商户订单号
-            String tradeNo = params.get("out_trade_no").toString();
+            String out_trade_no = params.get("out_trade_no").toString();
             // 商户退款单号
             String out_refund_no = params.get("out_refund_no").toString();
             // 微信支付订单号
@@ -144,15 +190,39 @@
             // 时间不对的话,可以调用  WxTimeUtils.toRfc3339Date(success_time)转换一下
             String success_time = params.get("success_time").toString();
             if (tradeState.equals(RefundEnum.SUCCESS.name())) {
-                // TODO 退款成功处理
+                String substring = out_refund_no.substring(0, 3);
+                switch (substring){
+                    //充电订单
+                    case "CDF":
+                        chargingOrderClient.chargingOrderStartupFailureWxRefund(out_refund_no, refund_id, tradeState, success_time);
+                        System.err.println("----充电启动失败退款回调通知");
+                        break;
+                    case "GDF":
+                        shoppingOrderClient.cancelShoppingOrderWxRefund(out_refund_no, refund_id, tradeState, success_time);
+                        System.err.println("----商城订单取消退款回调通知");
+                        break;
+                    //充电订单
+                    case "GWF":
+                        chargingOrderClient.shoppingOrderWxRefund(out_refund_no, refund_id, tradeState, success_time);
+                        System.err.println("----管理后台取消购物订单退款回调通知");
+                        break;
+                }
+                
+                WxRefundNotifyResp resp = new WxRefundNotifyResp();
+                resp.setOut_trade_no(out_trade_no);
+                resp.setOut_refund_no(out_refund_no);
+                resp.setTradeState(tradeState);
+                resp.setTransaction_id(transaction_id);
+                resp.setRefund_id(refund_id);
+                resp.setSuccess_time(success_time);
                 wxV3Pay.ack();
             } else {
                 wxV3Pay.ack(false, "不是成功的退款状态");
             }
         } catch (Exception e) {
+            e.printStackTrace();
             wxV3Pay.ack(false, e.getMessage());
         }
-
     }
     
     /**

--
Gitblit v1.7.1