!177 增加结算时当前商品促销最新状态的查询
Merge pull request !177 from OceansDeep/feature/pg
This commit is contained in:
commit
27ad9b0599
@ -117,4 +117,8 @@ public class CartSkuVO extends CartBase implements Serializable {
|
||||
public Map<String, Object> getPromotionMap() {
|
||||
return PromotionTools.filterInvalidPromotionsMap(this.promotionMap);
|
||||
}
|
||||
|
||||
public Map<String, Object> getNotFilterPromotionMap() {
|
||||
return this.promotionMap;
|
||||
}
|
||||
}
|
||||
|
@ -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()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<String, Object> promotionMap = this.getCurrentGoodsPromotion(dataSku, cartType);
|
||||
Map<String, Object> promotionMap = promotionGoodsService.getCurrentGoodsPromotion(dataSku, cartType);
|
||||
|
||||
try {
|
||||
//购物车方式购买需要保存之前的选择,其他方式购买,则直接抹除掉之前的记录
|
||||
@ -554,39 +551,6 @@ public class CartServiceImpl implements CartService {
|
||||
return trade;
|
||||
}
|
||||
|
||||
private Map<String, Object> getCurrentGoodsPromotion(GoodsSku dataSku, String cartType) {
|
||||
Map<String, Object> 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<Map.Entry<String, Object>> 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取购物车类型
|
||||
|
@ -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<PromotionGoods> {
|
||||
/**
|
||||
* 获取某sku所有有效活动
|
||||
*
|
||||
* @param skuId 商品skuId
|
||||
* @param skuId 商品skuId
|
||||
* @param storeIds 店铺id
|
||||
* @return 促销商品集合
|
||||
*/
|
||||
@ -70,7 +72,7 @@ public interface PromotionGoodsService extends IService<PromotionGoods> {
|
||||
/**
|
||||
* 获取当前有效时间特定促销类型的促销商品信息
|
||||
*
|
||||
* @param skuId skuId
|
||||
* @param skuId skuId
|
||||
* @param promotionTypes 特定促销类型
|
||||
* @return 促销商品信息
|
||||
*/
|
||||
@ -79,7 +81,7 @@ public interface PromotionGoodsService extends IService<PromotionGoods> {
|
||||
/**
|
||||
* 获取当前有效时间特定促销类型的促销商品价格
|
||||
*
|
||||
* @param skuId skuId
|
||||
* @param skuId skuId
|
||||
* @param promotionTypes 特定促销类型
|
||||
* @return 促销商品价格
|
||||
*/
|
||||
@ -154,4 +156,13 @@ public interface PromotionGoodsService extends IService<PromotionGoods> {
|
||||
*/
|
||||
void deletePromotionGoods(PromotionGoodsSearchParams searchParams);
|
||||
|
||||
/**
|
||||
* 获取当前商品促销信息
|
||||
*
|
||||
* @param dataSku 商品sku信息
|
||||
* @param cartType 购物车类型
|
||||
* @return 当前商品促销信息
|
||||
*/
|
||||
Map<String, Object> getCurrentGoodsPromotion(GoodsSku dataSku, String cartType);
|
||||
|
||||
}
|
@ -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<PromotionGoodsMapper,
|
||||
@Autowired
|
||||
private GoodsSkuService goodsSkuService;
|
||||
|
||||
@Autowired
|
||||
private GoodsService goodsService;
|
||||
|
||||
@Autowired
|
||||
private EsGoodsIndexService goodsIndexService;
|
||||
|
||||
@Override
|
||||
public List<PromotionGoods> findSkuValidPromotion(String skuId, String storeIds) {
|
||||
|
||||
@ -267,8 +277,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
||||
*/
|
||||
@Override
|
||||
public void deletePromotionGoods(List<String> promotionIds) {
|
||||
LambdaQueryWrapper<PromotionGoods> queryWrapper = new LambdaQueryWrapper<PromotionGoods>()
|
||||
.in(PromotionGoods::getPromotionId, promotionIds);
|
||||
LambdaQueryWrapper<PromotionGoods> queryWrapper = new LambdaQueryWrapper<PromotionGoods>().in(PromotionGoods::getPromotionId, promotionIds);
|
||||
this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
@ -282,4 +291,41 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
|
||||
this.remove(searchParams.queryWrapper());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getCurrentGoodsPromotion(GoodsSku dataSku, String cartType) {
|
||||
Map<String, Object> 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<Map.Entry<String, Object>> 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<String, Object> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user