Browse Source

fix(product-gift): processGifts 下单时复核赠品商品库存

E2E Test Bot 4 weeks ago
parent
commit
b0216ce60f

+ 7 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/ProductOrderService.java

@@ -582,6 +582,13 @@ public class ProductOrderService {
             if (giftItem == null) {
             if (giftItem == null) {
                 return Result.error("赠品项不存在");
                 return Result.error("赠品项不存在");
             }
             }
+            // 赠品商品库存复核(下单时再次校验,防止详情页与下单之间库存耗尽)
+            if ("product".equals(giftItem.getGiftType()) && giftItem.getGiftProductId() != null) {
+                Product gp = productMapper.selectById(giftItem.getGiftProductId());
+                if (gp == null || gp.getStock() == null || gp.getStock() <= 0) {
+                    return Result.error("赠品商品库存不足: " + (giftItem.getGiftProductName() != null ? giftItem.getGiftProductName() : "赠品"));
+                }
+            }
             ProductOrderGift orderGift = new ProductOrderGift();
             ProductOrderGift orderGift = new ProductOrderGift();
             orderGift.setOrderId(order.getId());
             orderGift.setOrderId(order.getId());
             orderGift.setOrderNo(order.getOrderNo());
             orderGift.setOrderNo(order.getOrderNo());