From bbc55de9bb0f6e5d3d8267c628d25780c19ebf36 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期六, 08 二月 2025 17:20:06 +0800
Subject: [PATCH] 冥想2.0新增代码

---
 xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/controller/client/ClientOrderController.java |   95 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 95 insertions(+), 0 deletions(-)

diff --git a/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/controller/client/ClientOrderController.java b/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/controller/client/ClientOrderController.java
index 0e6e7d2..8dfb209 100644
--- a/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/controller/client/ClientOrderController.java
+++ b/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/controller/client/ClientOrderController.java
@@ -471,6 +471,101 @@
 
         return R.ok();
     }
+    /**
+     * 处理苹果退款 回调通知
+     * @param request
+     * @param response
+     */
+    @ResponseBody
+    @PostMapping("/refundApple")
+    public void refundApple(HttpServletRequest request, HttpServletResponse response) {
+        try {
+            System.err.println("请求"+request);
+            BufferedReader reader = request.getReader();
+            String string1 = reader.toString();
+            System.err.println("请求reader"+string1);
+            StringBuilder requestBody = new StringBuilder();
+            String line;
+            while ((line = reader.readLine()) != null) {
+                requestBody.append(line);
+            }
+            System.err.println("全部请求体"+requestBody);
+            org.json.JSONObject jsonObject1 = new org.json.JSONObject(requestBody.toString());
+            System.err.println("json串"+jsonObject1);
+            String o = jsonObject1.getString("signedPayload");
+            com.alibaba.fastjson.JSONObject payload = verifyAndGet(o);
+            String notificationType = payload.get("notificationType").toString();
+
+            com.alibaba.fastjson.JSONObject data = payload.getJSONObject("data");
+            String signedTransactionInfo = data.get("signedTransactionInfo").toString();
+            com.alibaba.fastjson.JSONObject transactionInfo = verifyAndGet(signedTransactionInfo);
+            System.err.println("解签后的json串"+transactionInfo);
+            System.err.println("data"+data);
+            // 苹果流水号
+            String string = transactionInfo.getString("originalTransactionId");
+            OrderPaymentRecord one = orderPaymentRecordService.getOne(new QueryWrapper<OrderPaymentRecord>()
+                    .eq("pay_order_no", string)
+                    .eq("payment_type", 3));
+            Order order = orderService.getById(one.getOrderId());
+
+            if (one!=null && one.getPaymentStatus() == 2){
+                one.setPaymentStatus(3);
+
+                switch (order.getOrderFrom()){
+                    case 1:
+                        // 冥想订单 删除
+                        break;
+                    case 2:
+                        // 删除用户与课程的关系表
+                        remoteAppUserService.deleteAppUserCourse(order.getBusinessId(),order.getAppUserId());
+                        break;
+                    case 3:
+                        // 会员订单 将用户会员到期时间回退
+                        if (order.getBuyContent().contains("月")){
+                            remoteAppUserService.subVipExpireTime(order.getAppUserId(),1);
+                        }else if (order.getBuyContent().contains("季")){
+                            remoteAppUserService.subVipExpireTime(order.getAppUserId(),2);
+                        }else if (order.getBuyContent().contains("年")){
+                            remoteAppUserService.subVipExpireTime(order.getAppUserId(),3);
+                        }
+                        break;
+                }
+                // 内购+余额支付 需要退回余额 并删除余额支付记录
+                if (order.getPayType() == 7){
+                    // 查询余额支付
+                    OrderPaymentRecord two = orderPaymentRecordService.getOne(new QueryWrapper<OrderPaymentRecord>()
+                            .eq("order_id", order.getId())
+                            .eq("payment_type", 4)
+                            .eq("payment_status", 2)
+                    );
+                    two.setPaymentStatus(3);
+                    orderPaymentRecordService.updateById(two);
+                    AppUserWalletRecord appUserWalletRecord = new AppUserWalletRecord();
+                    appUserWalletRecord.setAppUserId(order.getAppUserId());
+                    appUserWalletRecord.setChangeType(1);
+                    appUserWalletRecord.setReason("后台退款");
+                    appUserWalletRecord.setOrderId(order.getId());
+                    appUserWalletRecord.setAmount(two.getPayAmount());
+                    remoteAppUserService.addBalanceRecord(appUserWalletRecord);
+                    remoteAppUserService.addBalance(order.getAppUserId(),two.getPayAmount());
+                }
+                order.setRefundStatus(3);
+                order.setRefundRemark("后台退款");
+                order.setRefundTime(LocalDateTime.now());
+                order.setPaymentStatus(3);
+                order.setCancelTime(LocalDateTime.now());
+                orderPaymentRecordService.updateById(one);
+                orderService.updateById(order);
+            }
+            System.err.println("苹果流水号"+string);
+            PrintWriter out = response.getWriter();
+            out.write("success");
+            out.flush();
+            out.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
     private static final TrustManager myX509TrustManager = new X509TrustManager() {
         @Override
         public X509Certificate[] getAcceptedIssuers() {

--
Gitblit v1.7.1