满优惠notice调整,满优惠信息写入购物车时机调整。

This commit is contained in:
Chopper 2021-08-26 11:05:05 +08:00
parent fbb750927f
commit 3d158125f9
6 changed files with 88 additions and 72 deletions

View File

@ -130,7 +130,7 @@ public class FullDiscountExecute implements TradeEvent, OrderStatusChangeEvent {
try {
//赠品潘迪ing
if (cartVO.getGiftList() != null && cartVO.getGiftList().size() > 0) {
generatorGiftOrder(cartVO.getGiftList(), cartVO, order);
generatorGiftOrder(cartVO.getGiftList(), order);
}
} catch (Exception e) {
log.error("订单赠送赠品异常", e);
@ -141,10 +141,9 @@ public class FullDiscountExecute implements TradeEvent, OrderStatusChangeEvent {
* 生成赠品订单
*
* @param skuIds 赠品sku信息
* @param cartVO 购物车信息
* @param originOrder 赠品原订单信息
*/
private void generatorGiftOrder(List<String> skuIds, CartVO cartVO, Order originOrder) {
private void generatorGiftOrder(List<String> skuIds, Order originOrder) {
List<OrderItem> orderItems = new ArrayList<>();
List<OrderLog> orderLogs = new ArrayList<>();
Order order = new Order();

View File

@ -1,5 +1,6 @@
package cn.lili.modules.order.cart.entity.vo;
import cn.lili.modules.goods.entity.dos.GoodsSku;
import cn.lili.modules.promotion.entity.dos.FullDiscount;
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
import lombok.Data;
@ -20,6 +21,10 @@ public class FullDiscountVO extends FullDiscount {
* 促销关联的商品
*/
private List<PromotionGoods> promotionGoodsList;
/**
* 赠品信息
*/
private GoodsSku giftSku;
/**
* 参与商品-1则代表所有商品参加
@ -28,15 +33,24 @@ public class FullDiscountVO extends FullDiscount {
public String notice() {
StringBuilder stringBuffer = new StringBuilder();
if (Boolean.TRUE.equals(this.getIsFreeFreight())) {
stringBuffer.append("免运费 ");
}
if (Boolean.TRUE.equals(this.getIsFullMinus())) {
stringBuffer.append("").append(this.getFullMinus()).append("");
stringBuffer.append("").append(this.getFullMinus()).append("");
}
if (Boolean.TRUE.equals(this.getIsFullRate())) {
stringBuffer.append("").append(this.getFullRate()).append("");
stringBuffer.append(" ").append(this.getFullRate()).append("");
}
if (Boolean.TRUE.equals(this.getIsFreeFreight())) {
stringBuffer.append(" 免运费 ");
}
if (Boolean.TRUE.equals(this.getIsPoint())) {
stringBuffer.append("").append(this.getPoint()).append("积分 ");
}
if (Boolean.TRUE.equals(this.getIsGift() && giftSku != null)) {
stringBuffer.append(" 赠品[").append(giftSku.getGoodsName()).append("]");
}
return stringBuffer.toString();
}

View File

@ -2,6 +2,8 @@ package cn.lili.modules.order.cart.render.impl;
import cn.lili.common.enums.PromotionTypeEnum;
import cn.lili.common.utils.CurrencyUtil;
import cn.lili.modules.goods.entity.dos.GoodsSku;
import cn.lili.modules.goods.service.GoodsSkuService;
import cn.lili.modules.order.cart.entity.dto.TradeDTO;
import cn.lili.modules.order.cart.entity.enums.RenderStepEnums;
import cn.lili.modules.order.cart.entity.vo.CartSkuVO;
@ -33,6 +35,9 @@ public class FullDiscountRender implements CartRenderStep {
@Autowired
private PromotionPriceUtil promotionPriceUtil;
@Autowired
private GoodsSkuService goodsSkuService;
@Override
public RenderStepEnums step() {
return RenderStepEnums.FULL_DISCOUNT;
@ -64,6 +69,13 @@ public class FullDiscountRender implements CartRenderStep {
for (CartVO cart : cartList) {
//如果购物车中的店铺id与活动店铺id相等则进行促销计算
if (fullDiscount.getStoreId().equals(cart.getStoreId())) {
//如果有赠品则将赠品信息写入
if (fullDiscount.getIsGift()) {
GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(fullDiscount.getGiftId());
fullDiscount.setGiftSku(goodsSku);
}
//写入满减活动
cart.setFullDiscount(fullDiscount);
Map<String, Double> skuPriceDetail;
@ -189,7 +201,7 @@ public class FullDiscountRender implements CartRenderStep {
*/
private boolean isFull(Double price, CartVO cart) {
if (cart.getFullDiscount().getFullMoney() <= price) {
cart.setPromotionNotice("正在参与满优惠活动" + cart.getFullDiscount().getPromotionName() + "" + cart.getFullDiscount().notice());
cart.setPromotionNotice("正在参与满优惠活动[" + cart.getFullDiscount().getPromotionName() + "]" + cart.getFullDiscount().notice());
return true;
} else {
cart.setPromotionNotice("还差" + CurrencyUtil.sub(cart.getFullDiscount().getFullMoney(), price) + " 即可参与活动(" + cart.getFullDiscount().getPromotionName() + "" + cart.getFullDiscount().notice());

View File

@ -34,15 +34,6 @@ public interface PromotionGoodsService extends IService<PromotionGoods> {
return "{" + CachePrefix.PROMOTION_GOODS_STOCK.name() + "_" + typeEnum.name() + "}_" + promotionId + "_" + skuId;
}
/**
* 根据活动获取商品
*
* @param promotionId 促销活动id
* @param skuId 商品id
* @return 促销商品信息
*/
PromotionGoods findByPromotion(String promotionId, String skuId);
/**
* 删除指定促销类型的促销商品
*
@ -76,10 +67,10 @@ public interface PromotionGoodsService extends IService<PromotionGoods> {
/**
* 分页获取促销商品信息
*
* @param goodsId 商品skuId
* @param skuId 商品skuId
* @return 某商品的促销信息
*/
List<PromotionGoods> getPromotionGoods(String goodsId);
List<PromotionGoods> getPromotionGoods(String skuId);
/**
* 分页获取促销商品信息

View File

@ -273,13 +273,13 @@ public class FullDiscountServiceImpl extends ServiceImpl<FullDiscountMapper, Ful
if (noGiftSelected) {
throw new ServiceException(ResultCode.FULL_DISCOUNT_GIFT_ERROR);
}
}else{
} else {
fullDiscountVO.setGiftId(null);
}
//如果优惠方式是赠优惠券
if (Boolean.TRUE.equals(fullDiscountVO.getIsCoupon())) {
this.checkCoupon(fullDiscountVO.getCouponId(), fullDiscountVO.getEndTime().getTime());
}else{
this.checkCoupon(fullDiscountVO.getCouponId());
} else {
fullDiscountVO.setCouponId(null);
}
//如果优惠方式是折扣
@ -311,15 +311,17 @@ public class FullDiscountServiceImpl extends ServiceImpl<FullDiscountMapper, Ful
* 检查优惠券信息
*
* @param couponId 优惠券编号
* @param endTime 活动结束时间
*/
private void checkCoupon(String couponId, long endTime) {
private void checkCoupon(String couponId) {
//是否没有选择优惠券
boolean noCouponSelected = couponId == null;
if (noCouponSelected) {
throw new ServiceException(ResultCode.COUPON_NOT_EXIST);
}
Coupon coupon = this.couponService.getById(couponId);
if (coupon == null) {
throw new ServiceException(ResultCode.COUPON_NOT_EXIST);
}
}
/**

View File

@ -25,7 +25,6 @@ import cn.lili.modules.promotion.entity.vos.CouponVO;
import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams;
import cn.lili.modules.promotion.entity.vos.SeckillVO;
import cn.lili.modules.promotion.mapper.PromotionGoodsMapper;
import cn.lili.modules.promotion.service.PointsGoodsService;
import cn.lili.modules.promotion.service.PromotionGoodsService;
import cn.lili.modules.promotion.service.SeckillApplyService;
import cn.lili.mybatis.util.PageUtil;
@ -77,18 +76,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
*/
@Autowired
private GoodsSkuService goodsSkuService;
/**
* 积分商品
*/
@Autowired
private PointsGoodsService pointsGoodsService;
@Override
public PromotionGoods findByPromotion(String promotionId, String skuId) {
LambdaQueryWrapper<PromotionGoods> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PromotionGoods::getPromotionId, promotionId).eq(PromotionGoods::getSkuId, skuId);
return new PromotionGoods();
}
@Override
public void removePromotionGoods(List<PromotionGoods> promotionGoodsList, PromotionTypeEnum promotionType) {
@ -100,9 +88,52 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
@Override
public List<PromotionGoods> findNowSkuPromotion(String skuId) {
return this.list(new LambdaQueryWrapper<PromotionGoods>()
GoodsSku sku = goodsSkuService.getGoodsSkuByIdFromCache(skuId);
if (sku == null) {
return null;
}
List<PromotionGoods> promotionGoods = new ArrayList<>();
promotionGoods.addAll(this.list(new LambdaQueryWrapper<PromotionGoods>()
.eq(PromotionGoods::getSkuId, skuId)
.eq(PromotionGoods::getPromotionStatus, PromotionStatusEnum.START.name()));
.eq(PromotionGoods::getPromotionStatus, PromotionStatusEnum.START.name())));
//单独检查添加适用于全品类的满优惠活动
Query query = new Query();
query.addCriteria(Criteria.where("promotionStatus").is(PromotionStatusEnum.START.name()));
query.addCriteria(Criteria.where("startTime").lte(new Date().getTime()));
List<FullDiscountVO> fullDiscountVOS = mongoTemplate.find(query, FullDiscountVO.class);
for (FullDiscountVO fullDiscountVO : fullDiscountVOS) {
if (fullDiscountVO.getPromotionGoodsList() == null &&
sku.getStoreId().equals(fullDiscountVO.getStoreId())) {
PromotionGoods p = new PromotionGoods(sku);
p.setPromotionId(fullDiscountVO.getId());
p.setPromotionStatus(fullDiscountVO.getPromotionStatus());
p.setPromotionType(PromotionTypeEnum.FULL_DISCOUNT.name());
p.setStartTime(fullDiscountVO.getStartTime());
p.setEndTime(fullDiscountVO.getEndTime());
promotionGoods.add(p);
}
}
//单独检查添加适用于全品类的全平台或属于当前店铺的优惠券活动
List<CouponVO> couponVOS = mongoTemplate.find(query, CouponVO.class);
for (CouponVO couponVO : couponVOS) {
boolean aLLScopeType = (couponVO.getPromotionGoodsList() == null
&& couponVO.getScopeType().equals(CouponScopeTypeEnum.ALL.name())
&& (("0").equals(couponVO.getStoreId()) || sku.getStoreId().equals(couponVO.getStoreId())));
if (aLLScopeType) {
PromotionGoods p = new PromotionGoods(sku);
p.setPromotionId(couponVO.getId());
p.setPromotionStatus(couponVO.getPromotionStatus());
p.setPromotionType(PromotionTypeEnum.COUPON.name());
p.setStartTime(couponVO.getStartTime());
p.setEndTime(couponVO.getEndTime());
promotionGoods.add(p);
}
}
return promotionGoods;
}
@Override
@ -141,39 +172,6 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
Integer goodsStock = this.getPromotionGoodsStock(PromotionTypeEnum.valueOf(promotionGood.getPromotionType()), promotionGood.getPromotionId(), promotionGood.getSkuId());
promotionGood.setQuantity(goodsStock);
}
//单独检查添加适用于全品类的满优惠活动
Query query = new Query();
query.addCriteria(Criteria.where("promotionStatus").is(PromotionStatusEnum.START.name()));
query.addCriteria(Criteria.where("startTime").lte(date));
List<FullDiscountVO> fullDiscountVOS = mongoTemplate.find(query, FullDiscountVO.class);
for (FullDiscountVO fullDiscountVO : fullDiscountVOS) {
if (fullDiscountVO.getPromotionGoodsList() == null &&
cartSkuVO.getStoreId().equals(fullDiscountVO.getStoreId())) {
PromotionGoods p = new PromotionGoods(cartSkuVO.getGoodsSku());
p.setPromotionId(fullDiscountVO.getId());
p.setPromotionStatus(fullDiscountVO.getPromotionStatus());
p.setPromotionType(PromotionTypeEnum.FULL_DISCOUNT.name());
p.setStartTime(fullDiscountVO.getStartTime());
p.setEndTime(fullDiscountVO.getEndTime());
promotionGoods.add(p);
}
}
//单独检查添加适用于全品类的全平台或属于当前店铺的优惠券活动
List<CouponVO> couponVOS = mongoTemplate.find(query, CouponVO.class);
for (CouponVO couponVO : couponVOS) {
boolean aLLScopeType = (couponVO.getPromotionGoodsList() == null
&& couponVO.getScopeType().equals(CouponScopeTypeEnum.ALL.name())
&& (("0").equals(couponVO.getStoreId()) || cartSkuVO.getStoreId().equals(couponVO.getStoreId())));
if (aLLScopeType) {
PromotionGoods p = new PromotionGoods(cartSkuVO.getGoodsSku());
p.setPromotionId(couponVO.getId());
p.setPromotionStatus(couponVO.getPromotionStatus());
p.setPromotionType(PromotionTypeEnum.COUPON.name());
p.setStartTime(couponVO.getStartTime());
p.setEndTime(couponVO.getEndTime());
promotionGoods.add(p);
}
}
cartSkuVO.setPromotions(promotionGoods);
//下一次更新时间
cartSkuVO.setUpdatePromotionTime(date);