فهرست منبع

更改订单支付后为已支付 完成状态需要人为操作

lutong 2 ماه پیش
والد
کامیت
d8e9c1fb24

+ 2 - 6
alien-dining/src/main/java/shop/alien/dining/controller/StoreOrderController.java

@@ -276,7 +276,7 @@ public class StoreOrderController {
         }
     }
 
-    @ApiOperation(value = "支付订单", notes = "支付订单,支付成后订单状态变为已完成")
+    @ApiOperation(value = "支付订单", notes = "支付订单,支付成后订单状态变为已支付(1),需要单独调用完成订单接口将订单状态改为已完成(3)")
     @PostMapping("/pay/{orderId}")
     public R<Object> payOrder(
             @ApiParam(value = "订单ID", required = true) @PathVariable Integer orderId,
@@ -304,14 +304,10 @@ public class StoreOrderController {
                 // 支付成功后通过回调接口更新订单状态
                 // 暂时先更新订单状态为已支付(实际应该等支付回调)
                 order = orderService.payOrder(orderId, payType);
-                // 支付完成后,订单状态变为已完成
-                orderService.completeOrder(orderId);
                 return R.data(order);
             } else {
                 // 其他支付方式(支付宝、现金)直接更新为已支付
                 order = orderService.payOrder(orderId, payType);
-                // 支付完成后,订单状态变为已完成
-                orderService.completeOrder(orderId);
                 return R.data(order);
             }
         } catch (Exception e) {
@@ -487,7 +483,7 @@ public class StoreOrderController {
         return sseService.createConnection(tableId);
     }
 
-    @ApiOperation(value = "完成订单", notes = "支付完成后调用,将订单状态改为已完成")
+    @ApiOperation(value = "完成订单", notes = "完成订单,将已支付状态的订单改为已完成状态。订单状态:0-待支付,1-已支付,3-已完成。只有已支付状态的订单才能完成")
     @PostMapping("/complete/{orderId}")
     public R<Boolean> completeOrder(@ApiParam(value = "订单ID", required = true) @PathVariable Integer orderId) {
         try {

+ 6 - 0
alien-dining/src/main/java/shop/alien/dining/service/impl/StoreOrderServiceImpl.java

@@ -645,6 +645,12 @@ public class StoreOrderServiceImpl extends ServiceImpl<StoreOrderMapper, StoreOr
             throw new RuntimeException("订单不存在");
         }
 
+        // 检查订单状态:只有已支付状态(1)的订单才能完成
+        if (order.getOrderStatus() != 1) {
+            throw new RuntimeException("订单状态不正确,只有已支付状态的订单才能完成");
+        }
+
+        // 检查支付状态:确保订单已支付
         if (order.getPayStatus() != 1) {
             throw new RuntimeException("订单未支付,无法完成");
         }