Просмотр исходного кода

fix(order): 修复购物车下单逻辑错误

- 修复placeOrderType为1时productNumMap未正确赋值的问题
- 修正购物车项删除时使用错误的参数productShoppingCartIds
- 完善购物车数据流处理逻辑,确保订单创建后正确清理购物车项
- 优化代码格式和条件判断结构
hurx 1 месяц назад
Родитель
Сommit
583663e0bf

+ 5 - 6
ruoyi-modules/ruoyi-order/src/main/java/org/dromara/order/controller/pc/PcOrderController.java

@@ -282,8 +282,7 @@ public class PcOrderController extends BaseController {
             // mainBo.setOrderProductBos(bo.getOrderProductBos());
             Map<Long, Long> productNumMap;
             // 1. 获取购物车项
-            if(bo.getPlaceOrderType() == 1){
-                productNumMap = Map.of();
+            if (bo.getPlaceOrderType() == 1) {
                 Set<Long> productShoppingCartIds = bo.getProductShoppingCartId();
                 if (productShoppingCartIds == null || productShoppingCartIds.isEmpty()) {
                     throw new IllegalArgumentException("购物车项ID不能为空");
@@ -295,14 +294,14 @@ public class PcOrderController extends BaseController {
                 }
 
                 // 2. 构建 productId -> productNum 映射(防御性:过滤 null key)
-                shoppingCartList.stream()
+                productNumMap = shoppingCartList.stream()
                     .filter(item -> item.getProductId() != null && item.getProductNum() != null)
                     .collect(Collectors.toMap(
                         RemoteProductShoppingCartVo::getProductId,
                         RemoteProductShoppingCartVo::getProductNum,
                         (existing, replacement) -> existing // 防止重复 key 冲突(理论上不应发生)
                     ));
-            }else {
+            } else {
                 productNumMap = bo.getProductInfo().stream()
                     .filter(item -> item.getProductId() != null && item.getProductNum() != null)
                     .collect(Collectors.toMap(
@@ -358,9 +357,9 @@ public class PcOrderController extends BaseController {
             if (orderId != null && orderId > 0) {
                 //初始化审批流程
                 orderCustomerFlowService.initOrderFlow(orderId);
-                if(bo.getPlaceOrderType() == 1){
+                if (bo.getPlaceOrderType() == 1) {
                     // 成功下单后,删除对应的购物车项
-                    remoteProductShoppingCartService.deleteWithValidByIds(productShoppingCartIds);
+                    remoteProductShoppingCartService.deleteWithValidByIds(bo.getProductShoppingCartId());
                 }
             } else {
                 throw new RuntimeException("订单创建失败");