diff --git a/framework/src/main/java/cn/lili/modules/order/cart/entity/vo/CartSkuVO.java b/framework/src/main/java/cn/lili/modules/order/cart/entity/vo/CartSkuVO.java index 59f2e7ea..30608258 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/entity/vo/CartSkuVO.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/entity/vo/CartSkuVO.java @@ -117,4 +117,8 @@ public class CartSkuVO extends CartBase implements Serializable { public Map getPromotionMap() { return PromotionTools.filterInvalidPromotionsMap(this.promotionMap); } + + public Map getNotFilterPromotionMap() { + return this.promotionMap; + } } 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 1430263b..8cb02a48 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 @@ -31,6 +31,7 @@ import cn.lili.modules.promotion.entity.dos.Coupon; import cn.lili.modules.promotion.entity.dos.Pintuan; import cn.lili.modules.promotion.entity.dos.PointsGoods; import cn.lili.modules.promotion.entity.vos.CouponVO; +import cn.lili.modules.promotion.service.PromotionGoodsService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -63,6 +64,11 @@ public class CheckDataRender implements CartRenderStep { @Autowired private WholesaleService wholesaleService; + /** + * 商品索引 + */ + @Autowired + private PromotionGoodsService promotionGoodsService; @Override public RenderStepEnums step() { @@ -127,6 +133,17 @@ public class CheckDataRender implements CartRenderStep { //设置失效消息 cartSkuVO.setErrorMessage("商品库存不足,现有库存数量[" + dataSku.getQuantity() + "]"); } + //如果存在商品促销活动,则判定商品促销状态 + if (CollUtil.isNotEmpty(cartSkuVO.getNotFilterPromotionMap()) || Boolean.TRUE.equals(cartSkuVO.getGoodsSku().getPromotionFlag())) { + //获取当前最新的促销信息 + cartSkuVO.setPromotionMap(this.promotionGoodsService.getCurrentGoodsPromotion(cartSkuVO.getGoodsSku(), tradeDTO.getCartTypeEnum().name())); + //设定商品价格 + Double goodsPrice = cartSkuVO.getGoodsSku().getPromotionFlag() != null && cartSkuVO.getGoodsSku().getPromotionFlag() ? cartSkuVO.getGoodsSku().getPromotionPrice() : cartSkuVO.getGoodsSku().getPrice(); + cartSkuVO.setPurchasePrice(goodsPrice); + cartSkuVO.setUtilPrice(goodsPrice); + cartSkuVO.setSubTotal(CurrencyUtil.mul(cartSkuVO.getPurchasePrice(), cartSkuVO.getNum())); + } + } } 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 f23459df..0712ddca 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 @@ -16,7 +16,6 @@ import cn.lili.modules.goods.entity.dos.Wholesale; import cn.lili.modules.goods.entity.enums.GoodsAuthEnum; import cn.lili.modules.goods.entity.enums.GoodsSalesModeEnum; import cn.lili.modules.goods.entity.enums.GoodsStatusEnum; -import cn.lili.modules.goods.entity.vos.GoodsVO; import cn.lili.modules.goods.service.GoodsService; import cn.lili.modules.goods.service.GoodsSkuService; import cn.lili.modules.goods.service.WholesaleService; @@ -36,10 +35,8 @@ import cn.lili.modules.order.order.entity.dos.Trade; import cn.lili.modules.order.order.entity.vo.ReceiptVO; import cn.lili.modules.promotion.entity.dos.KanjiaActivity; import cn.lili.modules.promotion.entity.dos.MemberCoupon; -import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.dto.search.KanjiaActivitySearchParams; import cn.lili.modules.promotion.entity.dto.search.MemberCouponSearchParams; -import cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams; import cn.lili.modules.promotion.entity.enums.KanJiaStatusEnum; import cn.lili.modules.promotion.entity.enums.MemberCouponStatusEnum; import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; @@ -139,7 +136,7 @@ public class CartServiceImpl implements CartService { } CartTypeEnum cartTypeEnum = getCartType(cartType); GoodsSku dataSku = checkGoods(skuId); - Map promotionMap = this.getCurrentGoodsPromotion(dataSku, cartType); + Map promotionMap = promotionGoodsService.getCurrentGoodsPromotion(dataSku, cartType); try { //购物车方式购买需要保存之前的选择,其他方式购买,则直接抹除掉之前的记录 @@ -554,39 +551,6 @@ public class CartServiceImpl implements CartService { return trade; } - private Map getCurrentGoodsPromotion(GoodsSku dataSku, String cartType) { - Map promotionMap; - EsGoodsIndex goodsIndex = goodsIndexService.findById(dataSku.getId()); - if (goodsIndex == null) { - GoodsVO goodsVO = this.goodsService.getGoodsVO(dataSku.getGoodsId()); - goodsIndex = goodsIndexService.getResetEsGoodsIndex(dataSku, goodsVO.getGoodsParamsDTOList()); - } - if (goodsIndex.getPromotionMap() != null && !goodsIndex.getPromotionMap().isEmpty()) { - if (goodsIndex.getPromotionMap().keySet().stream().anyMatch(i -> i.contains(PromotionTypeEnum.SECKILL.name())) || (goodsIndex.getPromotionMap().keySet().stream().anyMatch(i -> i.contains(PromotionTypeEnum.PINTUAN.name())) && CartTypeEnum.PINTUAN.name().equals(cartType))) { - - Optional> containsPromotion = goodsIndex.getPromotionMap().entrySet().stream().filter(i -> i.getKey().contains(PromotionTypeEnum.SECKILL.name()) || i.getKey().contains(PromotionTypeEnum.PINTUAN.name())).findFirst(); - if (containsPromotion.isPresent()) { - JSONObject promotionsObj = JSONUtil.parseObj(containsPromotion.get().getValue()); - PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); - searchParams.setSkuId(dataSku.getId()); - searchParams.setPromotionId(promotionsObj.get("id").toString()); - PromotionGoods promotionsGoods = promotionGoodsService.getPromotionsGoods(searchParams); - if (promotionsGoods != null && promotionsGoods.getPrice() != null) { - dataSku.setPromotionFlag(true); - dataSku.setPromotionPrice(promotionsGoods.getPrice()); - } else { - dataSku.setPromotionFlag(false); - dataSku.setPromotionPrice(null); - } - } - } - promotionMap = goodsIndex.getPromotionMap(); - } else { - promotionMap = null; - } - return promotionMap; - } - /** * 获取购物车类型 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 58a80e00..4aac7c38 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 @@ -3,6 +3,7 @@ package cn.lili.modules.promotion.service; import cn.lili.cache.CachePrefix; import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.vo.PageVO; +import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -10,6 +11,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import java.util.Date; import java.util.List; +import java.util.Map; /** * 促销商品业务层 @@ -35,7 +37,7 @@ public interface PromotionGoodsService extends IService { /** * 获取某sku所有有效活动 * - * @param skuId 商品skuId + * @param skuId 商品skuId * @param storeIds 店铺id * @return 促销商品集合 */ @@ -70,7 +72,7 @@ public interface PromotionGoodsService extends IService { /** * 获取当前有效时间特定促销类型的促销商品信息 * - * @param skuId skuId + * @param skuId skuId * @param promotionTypes 特定促销类型 * @return 促销商品信息 */ @@ -79,7 +81,7 @@ public interface PromotionGoodsService extends IService { /** * 获取当前有效时间特定促销类型的促销商品价格 * - * @param skuId skuId + * @param skuId skuId * @param promotionTypes 特定促销类型 * @return 促销商品价格 */ @@ -154,4 +156,13 @@ public interface PromotionGoodsService extends IService { */ void deletePromotionGoods(PromotionGoodsSearchParams searchParams); + /** + * 获取当前商品促销信息 + * + * @param dataSku 商品sku信息 + * @param cartType 购物车类型 + * @return 当前商品促销信息 + */ + Map getCurrentGoodsPromotion(GoodsSku dataSku, String cartType); + } \ No newline at end of file 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 cc2a993f..98852a25 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 @@ -2,10 +2,15 @@ package cn.lili.modules.promotion.serviceimpl; import cn.hutool.core.convert.Convert; import cn.hutool.core.text.CharSequenceUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.vo.PageVO; import cn.lili.modules.goods.entity.dos.GoodsSku; +import cn.lili.modules.goods.entity.vos.GoodsVO; +import cn.lili.modules.goods.service.GoodsService; import cn.lili.modules.goods.service.GoodsSkuService; +import cn.lili.modules.order.cart.entity.enums.CartTypeEnum; import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.dos.SeckillApply; import cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams; @@ -16,6 +21,8 @@ import cn.lili.modules.promotion.mapper.PromotionGoodsMapper; import cn.lili.modules.promotion.service.PromotionGoodsService; import cn.lili.modules.promotion.service.SeckillApplyService; import cn.lili.modules.promotion.tools.PromotionTools; +import cn.lili.modules.search.entity.dos.EsGoodsIndex; +import cn.lili.modules.search.service.EsGoodsIndexService; import cn.lili.mybatis.util.PageUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -27,10 +34,7 @@ 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; -import java.util.Date; -import java.util.List; +import java.util.*; /** * 促销商品业务层实现 @@ -59,6 +63,12 @@ public class PromotionGoodsServiceImpl extends ServiceImpl findSkuValidPromotion(String skuId, String storeIds) { @@ -267,8 +277,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl promotionIds) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() - .in(PromotionGoods::getPromotionId, promotionIds); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper().in(PromotionGoods::getPromotionId, promotionIds); this.remove(queryWrapper); } @@ -282,4 +291,41 @@ public class PromotionGoodsServiceImpl extends ServiceImpl getCurrentGoodsPromotion(GoodsSku dataSku, String cartType) { + Map promotionMap; + EsGoodsIndex goodsIndex = goodsIndexService.findById(dataSku.getId()); + if (goodsIndex == null) { + GoodsVO goodsVO = this.goodsService.getGoodsVO(dataSku.getGoodsId()); + goodsIndex = goodsIndexService.getResetEsGoodsIndex(dataSku, goodsVO.getGoodsParamsDTOList()); + } + if (goodsIndex.getPromotionMap() != null && !goodsIndex.getPromotionMap().isEmpty()) { + if (goodsIndex.getPromotionMap().keySet().stream().anyMatch(i -> i.contains(PromotionTypeEnum.SECKILL.name())) || (goodsIndex.getPromotionMap().keySet().stream().anyMatch(i -> i.contains(PromotionTypeEnum.PINTUAN.name())) && CartTypeEnum.PINTUAN.name().equals(cartType))) { + Optional> containsPromotion = goodsIndex.getPromotionMap().entrySet().stream().filter(i -> i.getKey().contains(PromotionTypeEnum.SECKILL.name()) || i.getKey().contains(PromotionTypeEnum.PINTUAN.name())).findFirst(); + containsPromotion.ifPresent(stringObjectEntry -> this.setGoodsPromotionInfo(dataSku, stringObjectEntry)); + } + promotionMap = goodsIndex.getPromotionMap(); + } else { + promotionMap = null; + dataSku.setPromotionFlag(false); + dataSku.setPromotionPrice(null); + } + return promotionMap; + } + + private void setGoodsPromotionInfo(GoodsSku dataSku, Map.Entry promotionInfo) { + JSONObject promotionsObj = JSONUtil.parseObj(promotionInfo); + PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); + searchParams.setSkuId(dataSku.getId()); + searchParams.setPromotionId(promotionsObj.get("id").toString()); + PromotionGoods promotionsGoods = this.getPromotionsGoods(searchParams); + if (promotionsGoods != null && promotionsGoods.getPrice() != null) { + dataSku.setPromotionFlag(true); + dataSku.setPromotionPrice(promotionsGoods.getPrice()); + } else { + dataSku.setPromotionFlag(false); + dataSku.setPromotionPrice(null); + } + } + } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionCacheKeys.java b/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionCacheKeys.java deleted file mode 100644 index 6281f779..00000000 --- a/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionCacheKeys.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.lili.modules.promotion.tools; - -import cn.lili.cache.CachePrefix; - -/** - * 满额活动缓存Key - * @author paulG - * @since 2020/10/12 - **/ -public class PromotionCacheKeys { - - /** - * 读取满优惠redis key - * @param activityId 活动ID - * @return 满优惠redis key - */ - public static String getFullDiscountKey(String activityId){ - return CachePrefix.STORE_ID_FULL_DISCOUNT + "::" + activityId; - } - - /** - * 读取满优惠redis key - * @param id id - * @return 满优惠redis key - */ - public static String getPromotionGoodsKey(String id){ - return CachePrefix.PROMOTION_GOODS + "::" + id; - } - - /** - * 读取秒杀活动redis key - * @param timeStr 时间字符串(格式为 yyyyMMdd) - * @return 满优惠redis key - */ - public static String getSeckillTimelineKey(String timeStr){ - return CachePrefix.STORE_ID_SECKILL + "::" + timeStr; - } - -}