From 11ffae1ecbe3d26863fd51262d7ffb043eb089da Mon Sep 17 00:00:00 2001
From: dd <gitluke@outlook.com>
Date: Mon, 27 Oct 2025 03:38:28 +0800
Subject: [PATCH] 1

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/product/UserPolicyController.java |   25 +++++++++++++++----------
 1 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/product/UserPolicyController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/product/UserPolicyController.java
index a825d9f..8424adb 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/product/UserPolicyController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/product/UserPolicyController.java
@@ -399,10 +399,16 @@
                 log.error("签名验证失败: {}", callbackDTO.getOrderId());
                 return "签名验证失败";
             }
-
+            PaymentRecord paymentRecord = paymentRecordService.getOne(new LambdaQueryWrapper<PaymentRecord>()
+                    .eq(PaymentRecord::getPayOrdeNo, callbackDTO.getOrderId())
+            );
+            if (paymentRecord == null) {
+                log.error("支付订单不存在: {}", paymentRecord.getPayOrdeNo());
+                return "支付订单不存在";
+            }
             // 2. 根据订单号查询保单
             UserPolicy userPolicy = userPolicyService.getOne(new LambdaQueryWrapper<UserPolicy>()
-                    .eq(UserPolicy::getOrderNo, callbackDTO.getOrderId()));
+                    .eq(UserPolicy::getId, paymentRecord.getOrderId()));
             if (userPolicy == null) {
                 log.error("订单不存在: {}", callbackDTO.getOrderId());
                 return "订单不存在";
@@ -561,17 +567,16 @@
         }
         if(byId.getPaymentStatus() == 2){
             return AjaxResult.error("订单已支付,禁止删除");
+        }else{
+            paymentRecordService.removeById(byId);
         }
         UserPolicy userPolicy = userPolicyService.getById(byId.getOrderId());
-        if(ObjectUtil.isEmpty(userPolicy)){
-            return AjaxResult.error("保单不存在!");
-        }
-        if(userPolicy.getPayStatus() == 2){
-            return AjaxResult.error("订单已支付,禁止删除");
-        }
 
-        paymentRecordService.removeById(byId);
-        userPolicyService.removeById(userPolicy);
+        if(ObjectUtil.isNotEmpty(userPolicy)  && userPolicy.getPayStatus() == 2){
+            return AjaxResult.error("订单已支付,禁止删除");
+        }else{
+            userPolicyService.removeById(userPolicy);
+        }
         return AjaxResult.success("删除成功");
     }
 

--
Gitblit v1.9.3