From c4307aa82197f37febf1be03e6f546d1742106d9 Mon Sep 17 00:00:00 2001 From: paulGao Date: Wed, 2 Mar 2022 11:49:41 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A7=92=E6=9D=80?= =?UTF-8?q?=E5=95=86=E5=93=81=E4=B8=8B=E5=8D=95=E6=97=B6=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E4=BC=9A=E6=9B=B4=E6=96=B0=E7=A7=92=E6=9D=80=E5=95=86=E5=93=81?= =?UTF-8?q?=E7=9A=84=E5=87=BA=E5=94=AE=E6=95=B0=E9=87=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lili/event/impl/StockUpdateExecute.java | 2 +- .../order/cart/entity/dto/TradeDTO.java | 1 - .../cart/render/impl/CheckDataRender.java | 2 +- .../order/order/entity/vo/ReceiptVO.java | 6 ++- .../service/PromotionGoodsService.java | 7 +--- .../service/SeckillApplyService.java | 6 +-- .../PromotionGoodsServiceImpl.java | 40 +++++++++---------- .../serviceimpl/SeckillApplyServiceImpl.java | 8 ++-- 8 files changed, 36 insertions(+), 36 deletions(-) diff --git a/consumer/src/main/java/cn/lili/event/impl/StockUpdateExecute.java b/consumer/src/main/java/cn/lili/event/impl/StockUpdateExecute.java index ab9f5d63..77806014 100644 --- a/consumer/src/main/java/cn/lili/event/impl/StockUpdateExecute.java +++ b/consumer/src/main/java/cn/lili/event/impl/StockUpdateExecute.java @@ -332,7 +332,7 @@ public class StockUpdateExecute implements OrderStatusChangeEvent { Integer num = promotionGoods.get(i).getNum(); promotionGoods.get(i).setNum((num != null ? num : 0) + order.getOrder().getGoodsNum()); } - promotionGoodsService.updateBatchById(promotionGoods); + promotionGoodsService.updatePromotionGoodsStock(promotionGoods); } //商品库存,包含sku库存集合,批量更新商品库存相关 goodsSkuService.updateGoodsStuck(goodsSkus); diff --git a/framework/src/main/java/cn/lili/modules/order/cart/entity/dto/TradeDTO.java b/framework/src/main/java/cn/lili/modules/order/cart/entity/dto/TradeDTO.java index 36f84b7f..e05113b1 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/entity/dto/TradeDTO.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/entity/dto/TradeDTO.java @@ -139,7 +139,6 @@ public class TradeDTO implements Serializable { this.cartList = new ArrayList<>(); this.skuPromotionDetail = new HashMap<>(); this.storeCoupons = new HashMap<>(); - this.storeCoupons = new HashMap<>(); this.priceDetailDTO = new PriceDetailDTO(); this.cantUseCoupons = new ArrayList<>(); this.canUseCoupons = new ArrayList<>(); diff --git a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java index 8012158f..58ca809d 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java @@ -193,7 +193,7 @@ public class CheckDataRender implements CartRenderStep { } } //积分商品,判断用户积分是否满足 - } else if (tradeDTO.getCartTypeEnum().equals(CartTypeEnum.POINTS) && tradeDTO.getSkuList().get(0).getPromotionMap() != null && !tradeDTO.getSkuList().get(0).getPromotionMap().isEmpty()) { + } else if (tradeDTO.getCartTypeEnum().equals(CartTypeEnum.POINTS) && tradeDTO.getSkuList().get(0).getPromotionMap() != null && !tradeDTO.getSkuList().get(0).getPromotionMap().isEmpty()) { //获取积分商品VO Optional> pointsPromotions = tradeDTO.getSkuList().get(0).getPromotionMap().entrySet().stream().filter(i -> i.getKey().contains(PromotionTypeEnum.POINTS_GOODS.name())).findFirst(); if (pointsPromotions.isPresent()) { diff --git a/framework/src/main/java/cn/lili/modules/order/order/entity/vo/ReceiptVO.java b/framework/src/main/java/cn/lili/modules/order/order/entity/vo/ReceiptVO.java index ad7b73ce..6047ea88 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/entity/vo/ReceiptVO.java +++ b/framework/src/main/java/cn/lili/modules/order/order/entity/vo/ReceiptVO.java @@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.io.Serializable; + /** * 发票 * @@ -12,8 +14,10 @@ import lombok.Data; */ @Data @ApiModel(value = "发票") -public class ReceiptVO { +public class ReceiptVO implements Serializable { + private static final long serialVersionUID = -8402457457074092957L; + @ApiModelProperty(value = "发票抬头") private String receiptTitle; diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/PromotionGoodsService.java b/framework/src/main/java/cn/lili/modules/promotion/service/PromotionGoodsService.java index f019298b..58a80e00 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/PromotionGoodsService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/PromotionGoodsService.java @@ -121,12 +121,9 @@ public interface PromotionGoodsService extends IService { /** * 更新促销活动商品库存 * - * @param typeEnum 促销商品类型 - * @param promotionId 促销活动id - * @param skuId 商品skuId - * @param quantity 更新后的库存数量 + * @param promotionGoodsList 更新促销活动商品信息 */ - void updatePromotionGoodsStock(PromotionTypeEnum typeEnum, String promotionId, String skuId, Integer quantity); + void updatePromotionGoodsStock(List promotionGoodsList); /** * 更新促销活动商品索引 diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/SeckillApplyService.java b/framework/src/main/java/cn/lili/modules/promotion/service/SeckillApplyService.java index 8d67dd74..f674b489 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/SeckillApplyService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/SeckillApplyService.java @@ -90,13 +90,13 @@ public interface SeckillApplyService extends IService { void removeSeckillApply(String seckillId, String id); /** - * 更新秒杀商品库存 + * 更新秒杀商品出售数量 * * @param seckillId 秒杀活动id * @param skuId 商品skuId - * @param quantity 库存 + * @param saleNum 出售数量 */ - void updateSeckillApplyQuantity(String seckillId, String skuId, Integer quantity); + void updateSeckillApplySaleNum(String seckillId, String skuId, Integer saleNum); /** * 更新秒杀活动时间 diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java index e3846103..21917405 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java @@ -3,8 +3,6 @@ package cn.lili.modules.promotion.serviceimpl; import cn.hutool.core.convert.Convert; import cn.hutool.core.text.CharSequenceUtil; import cn.lili.common.enums.PromotionTypeEnum; -import cn.lili.common.enums.ResultCode; -import cn.lili.common.exception.ServiceException; import cn.lili.common.vo.PageVO; import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.service.GoodsSkuService; @@ -27,6 +25,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Arrays; @@ -209,31 +208,32 @@ public class PromotionGoodsServiceImpl extends ServiceImpl promotionGoodsList) { + for (PromotionGoods promotionGoods : promotionGoodsList) { + String promotionStockKey = PromotionGoodsService.getPromotionGoodsStockCacheKey(PromotionTypeEnum.valueOf(promotionGoods.getPromotionType()), promotionGoods.getPromotionId(), promotionGoods.getSkuId()); + if (promotionGoods.getPromotionType().equals(PromotionTypeEnum.SECKILL.name())) { + SeckillSearchParams searchParams = new SeckillSearchParams(); + searchParams.setSeckillId(promotionGoods.getPromotionId()); + searchParams.setSkuId(promotionGoods.getSkuId()); + SeckillApply seckillApply = this.seckillApplyService.getSeckillApply(searchParams); + if (seckillApply != null) { + seckillApplyService.updateSeckillApplySaleNum(promotionGoods.getPromotionId(), promotionGoods.getSkuId(), promotionGoods.getNum()); + } } - seckillApplyService.updateSeckillApplyQuantity(promotionId, skuId, quantity); - } else { + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); - updateWrapper.eq(PromotionGoods::getPromotionType, typeEnum.name()).eq(PromotionGoods::getPromotionId, promotionId).eq(PromotionGoods::getSkuId, skuId); - updateWrapper.set(PromotionGoods::getQuantity, quantity); + updateWrapper.eq(PromotionGoods::getPromotionType, promotionGoods.getPromotionType()).eq(PromotionGoods::getPromotionId, promotionGoods.getPromotionId()).eq(PromotionGoods::getSkuId, promotionGoods.getSkuId()); + updateWrapper.set(PromotionGoods::getQuantity, promotionGoods.getQuantity()).set(PromotionGoods::getNum, promotionGoods.getNum()); + this.update(updateWrapper); + stringRedisTemplate.opsForValue().set(promotionStockKey, promotionGoods.getQuantity().toString()); } - stringRedisTemplate.opsForValue().set(promotionStockKey, quantity.toString()); + } /** diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java index 66071234..633e453f 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java @@ -231,17 +231,17 @@ public class SeckillApplyServiceImpl extends ServiceImpl updateWrapper = new LambdaUpdateWrapper<>(); updateWrapper.eq(SeckillApply::getSeckillId, seckillId).eq(SeckillApply::getSkuId, skuId); - updateWrapper.set(SeckillApply::getQuantity, quantity); + updateWrapper.set(SeckillApply::getSalesNum, saleNum); this.update(updateWrapper); } From 3506e1c73822b5b31a5057e37d73e73536fdbbf8 Mon Sep 17 00:00:00 2001 From: paulGao Date: Wed, 2 Mar 2022 20:26:50 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E4=BF=83=E9=94=80=E5=95=86=E5=93=81=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/lili/common/enums/ResultCode.java | 1 + .../cart/render/impl/SkuPromotionRender.java | 69 +++++++++++++++++++ .../order/cart/service/CartServiceImpl.java | 1 + .../modules/promotion/entity/dos/Seckill.java | 2 + .../serviceimpl/PromotionServiceImpl.java | 15 ++-- .../serviceimpl/SeckillApplyServiceImpl.java | 6 +- 6 files changed, 82 insertions(+), 12 deletions(-) diff --git a/framework/src/main/java/cn/lili/common/enums/ResultCode.java b/framework/src/main/java/cn/lili/common/enums/ResultCode.java index b335862d..7b61c34f 100644 --- a/framework/src/main/java/cn/lili/common/enums/ResultCode.java +++ b/framework/src/main/java/cn/lili/common/enums/ResultCode.java @@ -246,6 +246,7 @@ public enum ResultCode { * 活动 */ PROMOTION_GOODS_NOT_EXIT(40000, "当前促销商品不存在!"), + PROMOTION_GOODS_QUANTITY_NOT_EXIT(40020, "当前促销商品库存不足!"), PROMOTION_SAME_ACTIVE_EXIST(40001, "活动时间内已存在同类活动,请选择关闭、删除当前时段的活动"), PROMOTION_START_TIME_ERROR(40002, "活动起始时间不能小于当前时间"), PROMOTION_END_TIME_ERROR(40003, "活动结束时间不能小于当前时间"), diff --git a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java index cfcfe37b..3350fda6 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java @@ -2,6 +2,7 @@ package cn.lili.modules.order.cart.render.impl; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; +import cn.lili.cache.Cache; import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; @@ -19,10 +20,14 @@ import cn.lili.modules.promotion.entity.dto.search.KanjiaActivitySearchParams; import cn.lili.modules.promotion.entity.enums.KanJiaStatusEnum; import cn.lili.modules.promotion.entity.vos.PromotionSkuVO; import cn.lili.modules.promotion.entity.vos.kanjia.KanjiaActivityVO; +import cn.lili.modules.promotion.service.KanjiaActivityGoodsService; import cn.lili.modules.promotion.service.KanjiaActivityService; +import cn.lili.modules.promotion.service.PointsGoodsService; +import cn.lili.modules.promotion.service.PromotionGoodsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; import java.util.Map; import java.util.Objects; @@ -39,9 +44,24 @@ public class SkuPromotionRender implements CartRenderStep { @Autowired private KanjiaActivityService kanjiaActivityService; + @Autowired + private KanjiaActivityGoodsService kanjiaActivityGoodsService; + + @Autowired + private PointsGoodsService pointsGoodsService; + + /** + * 促销商品 + */ + @Autowired + private PromotionGoodsService promotionGoodsService; + @Autowired private MemberService memberService; + @Autowired + private Cache cache; + @Override public RenderStepEnums step() { return RenderStepEnums.SKU_PROMOTION; @@ -54,6 +74,10 @@ public class SkuPromotionRender implements CartRenderStep { renderBasePrice(tradeDTO); //渲染单品促销 renderSkuPromotion(tradeDTO); + + checkPromotionQuantity(tradeDTO); + + } /** @@ -155,6 +179,51 @@ public class SkuPromotionRender implements CartRenderStep { } } + /** + * 检查促销库存 + * + * @param tradeDTO 购物车视图 + */ + private void checkPromotionQuantity(TradeDTO tradeDTO) { + for (CartSkuVO cartSkuVO : tradeDTO.getCheckedSkuList()) { + cartSkuVO.getPromotionMap(); + List joinPromotion = cartSkuVO.getPriceDetailDTO().getJoinPromotion(); + if (!joinPromotion.isEmpty()) { + for (PromotionSkuVO promotionSkuVO : joinPromotion) { + + String promotionGoodsStockCacheKey = PromotionGoodsService.getPromotionGoodsStockCacheKey(PromotionTypeEnum.valueOf(promotionSkuVO.getPromotionType()), promotionSkuVO.getActivityId(), cartSkuVO.getGoodsSku().getId()); + Object quantity = cache.get(promotionGoodsStockCacheKey); + + if (quantity == null) { + //如果促销有库存信息 + PromotionTypeEnum promotionTypeEnum = PromotionTypeEnum.valueOf(promotionSkuVO.getPromotionType()); + switch (promotionTypeEnum) { + case KANJIA: + quantity = kanjiaActivityGoodsService.getKanjiaGoodsBySkuId(cartSkuVO.getGoodsSku().getId()).getStock(); + break; + case POINTS_GOODS: + quantity = pointsGoodsService.getPointsGoodsDetailBySkuId(cartSkuVO.getGoodsSku().getId()).getActiveStock(); + break; + case SECKILL: + case PINTUAN: + quantity = promotionGoodsService.getPromotionGoodsStock(PromotionTypeEnum.valueOf(promotionSkuVO.getPromotionType()), promotionSkuVO.getActivityId(), cartSkuVO.getGoodsSku().getId()); + break; + default: + break; + } + } + + + if (cartSkuVO.getNum() > (Integer) quantity) {//设置购物车未选中 + cartSkuVO.setChecked(false); + //设置失效消息 + cartSkuVO.setErrorMessage("促销商品库存不足,现有库存数量[" + quantity + "]"); + } + } + } + } + } + /** * 购物车促销类型 */ diff --git a/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java b/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java index ccf3e7d8..1e8367ce 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java @@ -185,6 +185,7 @@ public class CartServiceImpl implements CartService { //购物车中不存在此商品,则新建立一个 CartSkuVO cartSkuVO = new CartSkuVO(dataSku, promotionMap); + this.checkSetGoodsQuantity(cartSkuVO, skuId, num); cartSkuVO.setCartType(cartTypeEnum); //检测购物车数据 checkCart(cartTypeEnum, cartSkuVO, skuId, num); diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Seckill.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Seckill.java index f80c4b77..e5d22caf 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Seckill.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Seckill.java @@ -11,6 +11,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.ToString; import org.springframework.beans.BeanUtils; import org.springframework.data.elasticsearch.annotations.DateFormat; import org.springframework.data.elasticsearch.annotations.Field; @@ -30,6 +31,7 @@ import java.util.Date; @TableName("li_seckill") @ApiModel(value = "秒杀活动活动") @NoArgsConstructor +@ToString(callSuper = true) public class Seckill extends BasePromotions { private static final long serialVersionUID = -9116425737163730836L; diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionServiceImpl.java index 2d8bda06..cd0df5e8 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionServiceImpl.java @@ -105,7 +105,7 @@ public class PromotionServiceImpl implements PromotionService { /** * 根据商品索引获取当前商品索引的所有促销活动信息 * - * @param storeId 店铺id + * @param storeId 店铺id * @param goodsSkuId 商品skuId * @return 当前促销活动集合 */ @@ -129,7 +129,7 @@ public class PromotionServiceImpl implements PromotionService { promotionMap.put(esPromotionKey, fullDiscount); break; case SECKILL: - this.getGoodsCurrentSeckill(promotionGoods, promotionMap); + this.getGoodsCurrentSeckill(esPromotionKey, promotionGoods, promotionMap); break; case POINTS_GOODS: PointsGoods pointsGoods = pointsGoodsService.getById(promotionGoods.getPromotionId()); @@ -143,7 +143,7 @@ public class PromotionServiceImpl implements PromotionService { } - private void getGoodsCurrentSeckill(PromotionGoods promotionGoods, Map promotionMap) { + private void getGoodsCurrentSeckill(String esPromotionKey, PromotionGoods promotionGoods, Map promotionMap) { Seckill seckill = seckillService.getById(promotionGoods.getPromotionId()); SeckillSearchParams searchParams = new SeckillSearchParams(); searchParams.setSeckillId(promotionGoods.getPromotionId()); @@ -151,19 +151,12 @@ public class PromotionServiceImpl implements PromotionService { List seckillApplyList = seckillApplyService.getSeckillApplyList(searchParams); if (seckillApplyList != null && !seckillApplyList.isEmpty()) { SeckillApply seckillApply = seckillApplyList.get(0); - int nextHour = 23; String[] split = seckill.getHours().split(","); int[] hoursSored = Arrays.stream(split).mapToInt(Integer::parseInt).toArray(); Arrays.sort(hoursSored); - for (int i : hoursSored) { - if (seckillApply.getTimeLine() < i) { - nextHour = i; - } - } - String seckillKey = promotionGoods.getPromotionType() + "-" + nextHour; seckill.setStartTime(promotionGoods.getStartTime()); seckill.setEndTime(promotionGoods.getEndTime()); - promotionMap.put(seckillKey, seckill); + promotionMap.put(esPromotionKey, seckill); } } diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java index 633e453f..32163415 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java @@ -424,7 +424,11 @@ public class SeckillApplyServiceImpl extends ServiceImpl Date: Wed, 2 Mar 2022 20:33:45 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A7=92=E6=9D=80?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/order/cart/render/impl/SkuPromotionRender.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java index 3350fda6..cdb2acfe 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java @@ -209,12 +209,12 @@ public class SkuPromotionRender implements CartRenderStep { quantity = promotionGoodsService.getPromotionGoodsStock(PromotionTypeEnum.valueOf(promotionSkuVO.getPromotionType()), promotionSkuVO.getActivityId(), cartSkuVO.getGoodsSku().getId()); break; default: - break; + return; } } - if (cartSkuVO.getNum() > (Integer) quantity) {//设置购物车未选中 + if (quantity != null && cartSkuVO.getNum() > (Integer) quantity) {//设置购物车未选中 cartSkuVO.setChecked(false); //设置失效消息 cartSkuVO.setErrorMessage("促销商品库存不足,现有库存数量[" + quantity + "]"); From 0d5f871da712ef5ff3007732c26c931ec1921d11 Mon Sep 17 00:00:00 2001 From: paulGao Date: Wed, 2 Mar 2022 20:39:17 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E4=BF=83=E9=94=80=E5=95=86=E5=93=81=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cart/render/impl/SkuPromotionRender.java | 61 ++++++++++--------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java index cdb2acfe..82f3cde9 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java @@ -190,40 +190,43 @@ public class SkuPromotionRender implements CartRenderStep { List joinPromotion = cartSkuVO.getPriceDetailDTO().getJoinPromotion(); if (!joinPromotion.isEmpty()) { for (PromotionSkuVO promotionSkuVO : joinPromotion) { - - String promotionGoodsStockCacheKey = PromotionGoodsService.getPromotionGoodsStockCacheKey(PromotionTypeEnum.valueOf(promotionSkuVO.getPromotionType()), promotionSkuVO.getActivityId(), cartSkuVO.getGoodsSku().getId()); - Object quantity = cache.get(promotionGoodsStockCacheKey); - - if (quantity == null) { - //如果促销有库存信息 - PromotionTypeEnum promotionTypeEnum = PromotionTypeEnum.valueOf(promotionSkuVO.getPromotionType()); - switch (promotionTypeEnum) { - case KANJIA: - quantity = kanjiaActivityGoodsService.getKanjiaGoodsBySkuId(cartSkuVO.getGoodsSku().getId()).getStock(); - break; - case POINTS_GOODS: - quantity = pointsGoodsService.getPointsGoodsDetailBySkuId(cartSkuVO.getGoodsSku().getId()).getActiveStock(); - break; - case SECKILL: - case PINTUAN: - quantity = promotionGoodsService.getPromotionGoodsStock(PromotionTypeEnum.valueOf(promotionSkuVO.getPromotionType()), promotionSkuVO.getActivityId(), cartSkuVO.getGoodsSku().getId()); - break; - default: - return; - } - } - - - if (quantity != null && cartSkuVO.getNum() > (Integer) quantity) {//设置购物车未选中 - cartSkuVO.setChecked(false); - //设置失效消息 - cartSkuVO.setErrorMessage("促销商品库存不足,现有库存数量[" + quantity + "]"); - } + this.checkPromotionGoodsQuantity(cartSkuVO, promotionSkuVO); } } } } + private void checkPromotionGoodsQuantity(CartSkuVO cartSkuVO, PromotionSkuVO promotionSkuVO) { + String promotionGoodsStockCacheKey = PromotionGoodsService.getPromotionGoodsStockCacheKey(PromotionTypeEnum.valueOf(promotionSkuVO.getPromotionType()), promotionSkuVO.getActivityId(), cartSkuVO.getGoodsSku().getId()); + Object quantity = cache.get(promotionGoodsStockCacheKey); + + if (quantity == null) { + //如果促销有库存信息 + PromotionTypeEnum promotionTypeEnum = PromotionTypeEnum.valueOf(promotionSkuVO.getPromotionType()); + switch (promotionTypeEnum) { + case KANJIA: + quantity = kanjiaActivityGoodsService.getKanjiaGoodsBySkuId(cartSkuVO.getGoodsSku().getId()).getStock(); + break; + case POINTS_GOODS: + quantity = pointsGoodsService.getPointsGoodsDetailBySkuId(cartSkuVO.getGoodsSku().getId()).getActiveStock(); + break; + case SECKILL: + case PINTUAN: + quantity = promotionGoodsService.getPromotionGoodsStock(PromotionTypeEnum.valueOf(promotionSkuVO.getPromotionType()), promotionSkuVO.getActivityId(), cartSkuVO.getGoodsSku().getId()); + break; + default: + return; + } + } + + + if (quantity != null && cartSkuVO.getNum() > (Integer) quantity) {//设置购物车未选中 + cartSkuVO.setChecked(false); + //设置失效消息 + cartSkuVO.setErrorMessage("促销商品库存不足,现有库存数量[" + quantity + "]"); + } + } + /** * 购物车促销类型 */