|
|
@@ -32,6 +32,7 @@ import jakarta.validation.constraints.NotNull;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
|
+import java.time.ZoneOffset;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -246,25 +247,38 @@ public class PcOrderController extends BaseController {
|
|
|
|
|
|
// 设置订单商品列表
|
|
|
// mainBo.setOrderProductBos(bo.getOrderProductBos());
|
|
|
+ Map<Long, Long> productNumMap;
|
|
|
// 1. 获取购物车项
|
|
|
- Set<Long> productShoppingCartIds = bo.getProductShoppingCartId();
|
|
|
- if (productShoppingCartIds == null || productShoppingCartIds.isEmpty()) {
|
|
|
- throw new IllegalArgumentException("购物车项ID不能为空");
|
|
|
+ if(bo.getPlaceOrderType() == 1){
|
|
|
+ productNumMap = Map.of();
|
|
|
+ Set<Long> productShoppingCartIds = bo.getProductShoppingCartId();
|
|
|
+ if (productShoppingCartIds == null || productShoppingCartIds.isEmpty()) {
|
|
|
+ throw new IllegalArgumentException("购物车项ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<RemoteProductShoppingCartVo> shoppingCartList = remoteProductShoppingCartService.getShoppingCartList(productShoppingCartIds);
|
|
|
+ if (shoppingCartList.isEmpty()) {
|
|
|
+ throw new IllegalStateException("购物车数据不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 构建 productId -> productNum 映射(防御性:过滤 null key)
|
|
|
+ shoppingCartList.stream()
|
|
|
+ .filter(item -> item.getProductId() != null && item.getProductNum() != null)
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ RemoteProductShoppingCartVo::getProductId,
|
|
|
+ RemoteProductShoppingCartVo::getProductNum,
|
|
|
+ (existing, replacement) -> existing // 防止重复 key 冲突(理论上不应发生)
|
|
|
+ ));
|
|
|
+ }else {
|
|
|
+ productNumMap = bo.getProductInfo().stream()
|
|
|
+ .filter(item -> item.getProductId() != null && item.getProductNum() != null)
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ PcSubmitOrderBo.PcOrderProduct::getProductId,
|
|
|
+ PcSubmitOrderBo.PcOrderProduct::getProductNum,
|
|
|
+ (existing, replacement) -> existing // 防止重复 key 冲突(理论上不应发生)
|
|
|
+ ));
|
|
|
}
|
|
|
|
|
|
- List<RemoteProductShoppingCartVo> shoppingCartList = remoteProductShoppingCartService.getShoppingCartList(productShoppingCartIds);
|
|
|
- if (shoppingCartList.isEmpty()) {
|
|
|
- throw new IllegalStateException("购物车数据不存在");
|
|
|
- }
|
|
|
-
|
|
|
- // 2. 构建 productId -> productNum 映射(防御性:过滤 null key)
|
|
|
- Map<Long, Long> productNumMap = shoppingCartList.stream()
|
|
|
- .filter(item -> item.getProductId() != null && item.getProductNum() != null)
|
|
|
- .collect(Collectors.toMap(
|
|
|
- RemoteProductShoppingCartVo::getProductId,
|
|
|
- RemoteProductShoppingCartVo::getProductNum,
|
|
|
- (existing, replacement) -> existing // 防止重复 key 冲突(理论上不应发生)
|
|
|
- ));
|
|
|
|
|
|
// 3. 提取所有商品 ID(使用 List/Collection,而非拼接字符串!)
|
|
|
List<Long> productIds = new ArrayList<>(productNumMap.keySet());
|
|
|
@@ -308,9 +322,9 @@ public class PcOrderController extends BaseController {
|
|
|
|
|
|
// 5. 保存订单(关键:成功后再删除购物车)
|
|
|
Long orderId = orderMainService.insertByBo(mainBo);
|
|
|
- if (orderId != null && orderId > 0) {
|
|
|
+ if (orderId != null && orderId > 0 && bo.getPlaceOrderType() == 1) {
|
|
|
// 成功下单后,删除对应的购物车项
|
|
|
- remoteProductShoppingCartService.deleteWithValidByIds(productShoppingCartIds);
|
|
|
+ remoteProductShoppingCartService.deleteWithValidByIds(bo.getProductShoppingCartId());
|
|
|
} else {
|
|
|
throw new RuntimeException("订单创建失败");
|
|
|
}
|