砍价、积分商品订单价格计算

This commit is contained in:
lifenlong 2021-07-18 18:30:37 +08:00
parent 451d683c4f
commit dd213e7e33
9 changed files with 259 additions and 136 deletions

View File

@ -66,8 +66,7 @@ public class CartSkuVO extends CartBase implements Serializable {
@ApiModelProperty(value = "是否可配送")
private Boolean isShip;
@ApiModelProperty(value =
"拼团id 如果是拼团购买 此值为拼团活动id" +
@ApiModelProperty(value = "拼团id 如果是拼团购买 此值为拼团活动id" +
"当pintuanId为空则表示普通购买或者拼团商品单独购买")
private String pintuanId;

View File

@ -16,6 +16,10 @@ import cn.lili.modules.order.cart.entity.vo.CartSkuVO;
import cn.lili.modules.order.cart.entity.vo.CartVO;
import cn.lili.modules.order.cart.render.CartRenderStep;
import cn.lili.modules.order.order.service.OrderService;
import cn.lili.modules.promotion.entity.dos.Pintuan;
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
import cn.lili.modules.promotion.entity.enums.PromotionTypeEnum;
import cn.lili.modules.promotion.service.PintuanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;
@ -23,6 +27,7 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
/**
@ -41,6 +46,9 @@ public class CheckDataRender implements CartRenderStep {
@Autowired
private OrderService orderService;
@Autowired
private PintuanService pintuanService;
@Override
public void render(TradeDTO tradeDTO) {
//预校验
@ -140,6 +148,18 @@ public class CheckDataRender implements CartRenderStep {
throw new ServiceException(ResultCode.PINTUAN_JOIN_ERROR);
}
}
//判断拼团商品的限购数量
Optional<String> pintuanId = tradeDTO.getSkuList().get(0).getPromotions().stream().filter(i -> i.getPromotionType().equals(PromotionTypeEnum.PINTUAN.name())).map(PromotionGoods::getPromotionId).findFirst();
if (pintuanId.isPresent()) {
Pintuan pintuan = pintuanService.getPintuanById(pintuanId.get());
Integer limitNum = pintuan.getLimitNum();
for (CartSkuVO cartSkuVO : tradeDTO.getSkuList()) {
if (limitNum != 0 && cartSkuVO.getNum() > limitNum) {
throw new ServiceException(ResultCode.PINTUAN_LIMIT_NUM_ERROR);
}
}
}
}else if(tradeDTO.getCartTypeEnum().equals(CartTypeEnum.KANJIA)){
}

View File

@ -1,8 +1,6 @@
package cn.lili.modules.order.cart.render.impl;
import cn.hutool.core.date.DateUtil;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.utils.CurrencyUtil;
import cn.lili.modules.order.cart.entity.dto.MemberCouponDTO;
import cn.lili.modules.order.cart.entity.dto.TradeDTO;
@ -14,14 +12,10 @@ import cn.lili.modules.order.cart.entity.vo.PriceDetailVO;
import cn.lili.modules.order.cart.render.CartRenderStep;
import cn.lili.modules.order.order.entity.dto.PriceDetailDTO;
import cn.lili.modules.promotion.entity.dos.MemberCoupon;
import cn.lili.modules.promotion.entity.dos.Pintuan;
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
import cn.lili.modules.promotion.entity.dto.GoodsSkuPromotionPriceDTO;
import cn.lili.modules.promotion.entity.dto.PromotionPriceDTO;
import cn.lili.modules.promotion.entity.dto.PromotionPriceParamDTO;
import cn.lili.modules.promotion.entity.dto.StorePromotionPriceDTO;
import cn.lili.modules.promotion.entity.enums.PromotionTypeEnum;
import cn.lili.modules.promotion.service.PintuanService;
import cn.lili.modules.promotion.service.PromotionGoodsService;
import cn.lili.modules.promotion.service.PromotionPriceService;
import org.springframework.beans.factory.annotation.Autowired;
@ -53,19 +47,15 @@ public class SkuPromotionRender implements CartRenderStep {
*/
@Autowired
private PromotionGoodsService promotionGoodsService;
/**
* 拼团
*/
@Autowired
private PintuanService pintuanService;
@Override
public void render(TradeDTO tradeDTO) {
//主要渲染各个优惠的价格
this.renderSkuPromotion(tradeDTO);
//渲染促销价格
this.renderPromotionPrice(tradeDTO);
this.checkPromotionLimit(tradeDTO);
//获取商品促销
renderSkuPromotion(tradeDTO);
}
@ -76,23 +66,12 @@ public class SkuPromotionRender implements CartRenderStep {
*/
private void renderSkuPromotion(TradeDTO tradeDTO) {
//渲染促销价格
this.renderPromotionPrice(tradeDTO);
//拼团和积分购买需要特殊处理这里优先特殊处理
if (tradeDTO.getCartTypeEnum().equals(CartTypeEnum.POINTS)) {
List<CartSkuVO> cartSkuVOList = tradeDTO.getSkuList();
for (CartSkuVO cartSku : cartSkuVOList) {
PriceDetailDTO priceDetailDTO = cartSku.getPriceDetailDTO();
//需要支付的积分
priceDetailDTO.setPayPoint(
CurrencyUtil.mul(
cartSku.getPoint(), cartSku.getNum()).intValue());
}
} else {
//这里普通购物车也只渲染满优惠其他优惠都是商品级别的都写在商品属性里
//非积分商品拼团砍价商品可渲染满优惠活动
//这里普通购物车也只渲染满优惠其他优惠都是商品级别的都写在商品属性里
if (!tradeDTO.getCartTypeEnum().equals(CartTypeEnum.POINTS)
&& !tradeDTO.getCartTypeEnum().equals(CartTypeEnum.PINTUAN)
&& !tradeDTO.getCartTypeEnum().equals(CartTypeEnum.KANJIA)) {
List<CartVO> cartVOS = tradeDTO.getCartList();
for (CartVO cartVO : cartVOS) {
if (isFull(cartVO)) {
this.renderFullMinus(cartVO);
@ -101,16 +80,61 @@ public class SkuPromotionRender implements CartRenderStep {
promotionGoodsService.getCartSkuPromotion(cartSkuVO);
}
}
}
}
/**
* 渲染购物车视图的促销价格
* 1.获取购物车商品列表
* 2.获取用户的优惠券
* 3.调用价格计算模块返回价格计算结果
* 4.分配计算后的促销
*
* @param tradeDTO 购物车视图
*/
private void renderPromotionPrice(TradeDTO tradeDTO) {
//获取购物车商品列表
List<PromotionPriceParamDTO> promotionPriceParamList = this.getPromotionPriceParamList(tradeDTO);
//店铺优惠券集合
List<MemberCoupon> memberCoupons = this.getMemberCoupons(tradeDTO);
//调用价格计算模块返回价格计算结果
PromotionPriceDTO promotionPrice = promotionPriceService.calculationPromotionPrice(promotionPriceParamList, memberCoupons,tradeDTO.getCartTypeEnum());
// 分配计算后的促销
this.distributionPromotionPrice(tradeDTO, promotionPrice);
}
/**
* 获取用户优惠券列表
*
* @param tradeDTO 交易DTO
* @return 用户优惠券列表
*/
private List<MemberCoupon> getMemberCoupons(TradeDTO tradeDTO) {
//店铺优惠券集合
List<MemberCoupon> memberCoupons = new ArrayList<>();
if (tradeDTO.getStoreCoupons() != null) {
memberCoupons.addAll(tradeDTO.getStoreCoupons().values().parallelStream().map(MemberCouponDTO::getMemberCoupon).collect(Collectors.toList()));
}
//平台优惠券
if (tradeDTO.getPlatformCoupon() != null && tradeDTO.getPlatformCoupon().getMemberCoupon() != null) {
memberCoupons.add(tradeDTO.getPlatformCoupon().getMemberCoupon());
}
//清除过期优惠券
long now = DateUtil.date().getTime();
memberCoupons.removeIf(memberCoupon -> memberCoupon.getEndTime().getTime() < now);
return memberCoupons;
}
/**
* 获取促销价格DTO列表
*
* @param tradeDTO 交易DTO
* @return 促销价格DTO列表
*/
private List<PromotionPriceParamDTO> getPromotionPriceParamList(TradeDTO tradeDTO) {
List<PromotionPriceParamDTO> promotionPriceParamList = new ArrayList<>();
List<CartVO> cartList = tradeDTO.getCartList();
for (CartVO cartVO : cartList) {
@ -130,30 +154,7 @@ public class SkuPromotionRender implements CartRenderStep {
}
}
}
//如果包含促销规则
if (!promotionPriceParamList.isEmpty()) {
//店铺优惠券集合
List<MemberCoupon> memberCoupons = new ArrayList<>();
if (tradeDTO.getStoreCoupons() != null) {
memberCoupons.addAll(tradeDTO.getStoreCoupons().values().parallelStream().map(MemberCouponDTO::getMemberCoupon).collect(Collectors.toList()));
}
//平台优惠券
if (tradeDTO.getPlatformCoupon() != null && tradeDTO.getPlatformCoupon().getMemberCoupon() != null) {
memberCoupons.add(tradeDTO.getPlatformCoupon().getMemberCoupon());
}
//检查优惠券集合中是否存在过期优惠券
this.checkMemberCoupons(memberCoupons);
//调用价格计算模块返回价格计算结果
PromotionPriceDTO promotionPrice = promotionPriceService.calculationPromotionPrice(promotionPriceParamList, memberCoupons);
// 分配计算后的促销
this.distributionPromotionPrice(tradeDTO, promotionPrice);
}
}
private void checkMemberCoupons(List<MemberCoupon> memberCoupons) {
long now = DateUtil.date().getTime();
memberCoupons.removeIf(memberCoupon -> memberCoupon.getEndTime().getTime() < now);
return promotionPriceParamList;
}
/**
@ -284,19 +285,4 @@ public class SkuPromotionRender implements CartRenderStep {
return false;
}
private void checkPromotionLimit(TradeDTO tradeDTO) {
if (tradeDTO.getCartTypeEnum().equals(CartTypeEnum.PINTUAN)) {
//如果为拼团订单则获取拼团活动ID
Optional<String> pintuanId = tradeDTO.getSkuList().get(0).getPromotions().stream().filter(i -> i.getPromotionType().equals(PromotionTypeEnum.PINTUAN.name())).map(PromotionGoods::getPromotionId).findFirst();
if (pintuanId.isPresent()) {
Pintuan pintuan = pintuanService.getPintuanById(pintuanId.get());
Integer limitNum = pintuan.getLimitNum();
for (CartSkuVO cartSkuVO : tradeDTO.getSkuList()) {
if (limitNum != 0 && cartSkuVO.getNum() > limitNum) {
throw new ServiceException(ResultCode.PINTUAN_LIMIT_NUM_ERROR);
}
}
}
}
}
}

View File

@ -52,8 +52,8 @@ public class GoodsSkuPromotionPriceDTO implements Serializable {
@ApiModelProperty(value = "单个商品积分购买数量")
private Double points;
@ApiModelProperty(value = "商品购买总数量 = 单个商品积分购买数量 * 数量")
private Double totalPoints;
@ApiModelProperty(value = "商品购买积分总数量 = 单个商品积分购买数量 * 数量")
private Long totalPoints;
@ApiModelProperty(value = "单个优惠的所占总优惠金额比例")
private Double discountPriceRate;
@ -101,8 +101,9 @@ public class GoodsSkuPromotionPriceDTO implements Serializable {
this.setOriginalPrice(sku.getPrice());
this.setCouponPrice(0D);
this.setPoints(0d);
this.setTotalPoints(0d);
this.setTotalPoints(0L);
this.setFinalePrice(sku.getPrice());
this.setJoinPromotion(new ArrayList<>());
}
}

View File

@ -59,12 +59,12 @@ public interface PointsGoodsService extends IService<PointsGoods> {
PointsGoodsVO getPointsGoodsDetail(String id);
/**
* 根据SkuID获取积分商品信息
* 根据ID获取积分详情
*
* @param skuId 商品skuId
* @param skuId 商品SkuId
* @return 积分详情
*/
PointsGoods getPointsGoodsDetailBySkuId(String skuId);
PointsGoodsVO getPointsGoodsVOByMongo(String skuId);
/**
* 根据条件查询积分商品

View File

@ -1,5 +1,6 @@
package cn.lili.modules.promotion.service;
import cn.lili.modules.order.cart.entity.enums.CartTypeEnum;
import cn.lili.modules.promotion.entity.dos.MemberCoupon;
import cn.lili.modules.promotion.entity.dto.PromotionPriceDTO;
import cn.lili.modules.promotion.entity.dto.PromotionPriceParamDTO;
@ -19,8 +20,9 @@ public interface PromotionPriceService {
*
* @param tradeSkuList 促销计算参数
* @param memberCouponList 使用的优惠券
* @param cartTypeEnum 购物车类型
* @return 促销计算结果
*/
PromotionPriceDTO calculationPromotionPrice(List<PromotionPriceParamDTO> tradeSkuList, List<MemberCoupon> memberCouponList);
PromotionPriceDTO calculationPromotionPrice(List<PromotionPriceParamDTO> tradeSkuList, List<MemberCoupon> memberCouponList, CartTypeEnum cartTypeEnum);
}

View File

@ -315,17 +315,11 @@ public class KanjiaActivityGoodsServiceImpl extends ServiceImpl<KanJiaActivityGo
@Override
public KanjiaActivityGoodsDTO getKanJiaGoodsBySku(String skuId) {
//构建查询条件
KanjiaActivityGoodsParams kanJiaActivityGoodsParams = new KanjiaActivityGoodsParams();
kanJiaActivityGoodsParams.setSkuId(skuId);
kanJiaActivityGoodsParams.setPromotionStatus(PromotionStatusEnum.START.name());
//查询相关数据
Query query = kanJiaActivityGoodsParams.mongoQuery();
List<KanjiaActivityGoodsDTO> kanJiaActivityGoodsDTOS = this.mongoTemplate.find(query, KanjiaActivityGoodsDTO.class);
// 为了担心会查到多条数据 所以查询集合 正常情况下只会查询到一条
if (kanJiaActivityGoodsDTOS.size() > 0) {
return kanJiaActivityGoodsDTOS.get(0);
}
return null;
//mongo查询条件
Query query = new Query();
query.addCriteria(Criteria.where("skuId").ne(skuId))
.addCriteria(Criteria.where("promotionStatus").ne(PromotionStatusEnum.START.name()));
List<KanjiaActivityGoodsDTO> kanjiaActivityGoodsDTOList=this.mongoTemplate.find(query, KanjiaActivityGoodsDTO.class);
return kanjiaActivityGoodsDTOList.get(0);
}
}

View File

@ -203,20 +203,14 @@ public class PointsGoodsServiceImpl extends ServiceImpl<PointsGoodsMapper, Point
return this.checkExist(id);
}
/**
* 根据SkuID获取积分详情
*
* @param skuId@return 积分详情
*/
@Override
public PointsGoods getPointsGoodsDetailBySkuId(String skuId) {
LambdaQueryWrapper<PointsGoods> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PointsGoods::getSkuId, skuId).eq(PointsGoods::getPromotionStatus, PromotionStatusEnum.START.name());
List<PointsGoods> list = this.list(queryWrapper);
if (list.size() == 1) {
return list.get(0);
}
return null;
public PointsGoodsVO getPointsGoodsVOByMongo(String skuId) {
//mongo查询条件
Query query = new Query();
query.addCriteria(Criteria.where("skuId").ne(skuId))
.addCriteria(Criteria.where("promotionStatus").ne(PromotionStatusEnum.START.name()));
List<PointsGoodsVO> pointsGoodsVO=this.mongoTemplate.find(query, PointsGoodsVO.class);
return pointsGoodsVO.get(0);
}
/**

View File

@ -1,15 +1,16 @@
package cn.lili.modules.promotion.serviceimpl;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.text.CharSequenceUtil;
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.enums.CartTypeEnum;
import cn.lili.modules.promotion.entity.dos.*;
import cn.lili.modules.promotion.entity.dto.*;
import cn.lili.modules.promotion.entity.enums.*;
import cn.lili.modules.promotion.service.PromotionGoodsService;
import cn.lili.modules.promotion.service.PromotionPriceService;
import cn.lili.modules.promotion.service.SeckillApplyService;
import cn.lili.modules.promotion.entity.vos.PointsGoodsVO;
import cn.lili.modules.promotion.service.*;
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
import cn.lili.modules.search.service.EsGoodsSearchService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -50,27 +51,114 @@ public class PromotionPriceServiceImpl implements PromotionPriceService {
*/
@Autowired
private GoodsSkuService goodsSkuService;
/**
* 积分商品
*/
@Autowired
private PointsGoodsService pointsGoodsService;
/**
* 积分商品
*/
@Autowired
private KanjiaActivityGoodsService kanjiaActivityGoodsService;
@Override
public PromotionPriceDTO calculationPromotionPrice(List<PromotionPriceParamDTO> tradeSkuList, List<MemberCoupon> memberCouponList) {
public PromotionPriceDTO calculationPromotionPrice(List<PromotionPriceParamDTO> tradeSkuList, List<MemberCoupon> memberCouponList, CartTypeEnum cartTypeEnum) {
List<GoodsSkuPromotionPriceDTO> priceDTOList=new ArrayList<>();
PromotionPriceDTO promotionPrice = new PromotionPriceDTO();
//拆分出SkuId列表
List<String> skuIds = tradeSkuList.parallelStream().map(PromotionPriceParamDTO::getSkuId).collect(Collectors.toList());
//参与计算的ES商品SKU及其促销信息列表
List<EsGoodsIndex> esGoodsSkus = goodsSearchService.getEsGoodsBySkuIds(skuIds);
//参与计算的缓存中的商品SKU列表
List<GoodsSku> goodsSkus = goodsSkuService.getGoodsSkuByIdFromCache(skuIds);
//单品商品SKU促销计算结果列表
List<GoodsSkuPromotionPriceDTO> priceDTOList = this.packageGoodsSkuPromotionPrice(tradeSkuList, esGoodsSkus, goodsSkus);
//判断交易类型进行不同的处理
if (cartTypeEnum.equals(CartTypeEnum.POINTS)) {
this.pointGoodsPromotion(tradeSkuList);
} else if (cartTypeEnum.equals(CartTypeEnum.KANJIA)) {
this.kanjiaPromotion(tradeSkuList);
} else {
//参与计算的缓存中的商品SKU列表
List<GoodsSku> goodsSkus = goodsSkuService.getGoodsSkuByIdFromCache(skuIds);
//单品商品SKU促销计算结果列表
priceDTOList = this.packageGoodsSkuPromotionPrice(tradeSkuList, esGoodsSkus, goodsSkus);
}
//获取商品促销价格DTO列表
List<StorePromotionPriceDTO> storePromotionPriceList = new ArrayList<>();
//计算优惠券金额
Double couponTotalPrice = 0.0;
//将使用的优惠券根据店铺分类
Map<String, List<MemberCoupon>> couponCollect = memberCouponList.parallelStream().collect(Collectors.groupingBy(MemberCoupon::getStoreId));
//获取店铺优惠券金额
this.getStorePromotionPrice(storePromotionPriceList, priceDTOList, esGoodsSkus, couponCollect, couponTotalPrice);
//获取平台优惠金额
this.getPlatformPromotionPrice(couponCollect, storePromotionPriceList, priceDTOList, couponTotalPrice);
double couponTotalPrice = 0;
//计算最终结算金额返回数据
return this.getPromotionPriceDTO(storePromotionPriceList, couponTotalPrice);
}
/**
* 获取促销金额DTO
*
* @param storePromotionPriceList 店铺促销列表
* @param couponTotalPrice 优惠券优惠金额
* @return 促销金额DTO
*/
private PromotionPriceDTO getPromotionPriceDTO(List<StorePromotionPriceDTO> storePromotionPriceList, Double couponTotalPrice) {
PromotionPriceDTO promotionPrice = new PromotionPriceDTO();
promotionPrice.setStorePromotionPriceList(storePromotionPriceList);
promotionPrice.setTotalCouponPrice(couponTotalPrice);
promotionPrice.setTotalOriginPrice(storePromotionPriceList.parallelStream().mapToDouble(StorePromotionPriceDTO::getTotalOriginPrice).sum());
promotionPrice.setTotalPoints(storePromotionPriceList.parallelStream().mapToDouble(StorePromotionPriceDTO::getTotalPoints).sum());
promotionPrice.setTotalDiscountPrice(storePromotionPriceList.parallelStream().mapToDouble(StorePromotionPriceDTO::getTotalDiscountPrice).sum());
//最终结算金额 = 商品原价格合计 - 总优惠价格合计 - 优惠券合计
double totalFinalePrice = CurrencyUtil.sub(CurrencyUtil.sub(promotionPrice.getTotalOriginPrice(), promotionPrice.getTotalDiscountPrice()), promotionPrice.getTotalCouponPrice());
promotionPrice.setTotalFinalePrice(totalFinalePrice);
return promotionPrice;
}
/**
* 获取平台优惠券促销金额
*
* @param couponCollect 优惠券列表
* @param storePromotionPriceList 店铺促销列表
* @param priceDTOList 商品促销DTO列表
* @param couponTotalPrice 优惠券金额合计
*/
private void getPlatformPromotionPrice(Map<String, List<MemberCoupon>> couponCollect, List<StorePromotionPriceDTO> storePromotionPriceList, List<GoodsSkuPromotionPriceDTO> priceDTOList, Double couponTotalPrice) {
//获取平台优惠券
List<MemberCoupon> platformCoupons = couponCollect.get("platform");
if (platformCoupons != null && !platformCoupons.isEmpty()) {
//计算平台优惠券活动
couponTotalPrice = CurrencyUtil.add(couponTotalPrice, this.calculationCoupon(platformCoupons, priceDTOList));
for (StorePromotionPriceDTO storePromotionPriceDTO : storePromotionPriceList) {
Double couponPrice = storePromotionPriceDTO.getGoodsSkuPromotionPriceList().parallelStream().mapToDouble(GoodsSkuPromotionPriceDTO::getCouponPrice).sum();
storePromotionPriceDTO.setTotalCouponPrice(couponPrice);
}
}
}
/**
* 获取店铺优惠券促销金额
*
* @param storePromotionPriceList 店铺促销金额列表
* @param priceDTOList 商品促销金额DTO列表
* @param esGoodsSkus 商品索引SKU
* @param couponCollect 会员优惠券列表
* @param couponTotalPrice 优惠券金额合计
*/
private void getStorePromotionPrice(List<StorePromotionPriceDTO> storePromotionPriceList, List<GoodsSkuPromotionPriceDTO> priceDTOList,
List<EsGoodsIndex> esGoodsSkus, Map<String, List<MemberCoupon>> couponCollect, Double couponTotalPrice) {
//根据卖家分组商品信息
Map<String, List<GoodsSkuPromotionPriceDTO>> storeCollect = priceDTOList.parallelStream().collect(Collectors.groupingBy(GoodsSkuPromotionPriceDTO::getStoreId));
List<StorePromotionPriceDTO> storePromotionPriceList = new ArrayList<>();
for (Map.Entry<String, List<GoodsSkuPromotionPriceDTO>> entry : storeCollect.entrySet()) {
StorePromotionPriceDTO storePromotionPrice = new StorePromotionPriceDTO();
storePromotionPrice.setStoreId(entry.getKey());
@ -110,25 +198,6 @@ public class PromotionPriceServiceImpl implements PromotionPriceService {
storePromotionPriceList.add(storePromotionPrice);
}
//获取平台优惠券
List<MemberCoupon> platformCoupons = couponCollect.get("platform");
if (platformCoupons != null && !platformCoupons.isEmpty()) {
//计算平台优惠券活动
couponTotalPrice = CurrencyUtil.add(couponTotalPrice, this.calculationCoupon(platformCoupons, priceDTOList));
for (StorePromotionPriceDTO storePromotionPriceDTO : storePromotionPriceList) {
Double couponPrice = storePromotionPriceDTO.getGoodsSkuPromotionPriceList().parallelStream().mapToDouble(GoodsSkuPromotionPriceDTO::getCouponPrice).sum();
storePromotionPriceDTO.setTotalCouponPrice(couponPrice);
}
}
promotionPrice.setStorePromotionPriceList(storePromotionPriceList);
promotionPrice.setTotalCouponPrice(couponTotalPrice);
promotionPrice.setTotalOriginPrice(storePromotionPriceList.parallelStream().mapToDouble(StorePromotionPriceDTO::getTotalOriginPrice).sum());
promotionPrice.setTotalPoints(storePromotionPriceList.parallelStream().mapToDouble(StorePromotionPriceDTO::getTotalPoints).sum());
promotionPrice.setTotalDiscountPrice(storePromotionPriceList.parallelStream().mapToDouble(StorePromotionPriceDTO::getTotalDiscountPrice).sum());
//最终结算金额 = 商品原价格合计 - 总优惠价格合计 - 优惠券合计
double totalFinalePrice = CurrencyUtil.sub(CurrencyUtil.sub(promotionPrice.getTotalOriginPrice(), promotionPrice.getTotalDiscountPrice()), promotionPrice.getTotalCouponPrice());
promotionPrice.setTotalFinalePrice(totalFinalePrice);
return promotionPrice;
}
/**
@ -156,7 +225,6 @@ public class PromotionPriceServiceImpl implements PromotionPriceService {
this.calculationPromotionMap(promotionMap, goodsSkuPromotionPrice, esGoodsIndex, promotionPriceParamDTO);
goodsSkuPromotionPrice.setTotalOriginalPrice(CurrencyUtil.mul(goodsSkuPromotionPrice.getOriginalPrice(), goodsSkuPromotionPrice.getNumber()));
goodsSkuPromotionPrice.setTotalPoints(CurrencyUtil.mul(goodsSkuPromotionPrice.getPoints(), goodsSkuPromotionPrice.getNumber()));
goodsSkuPromotionPrice.setTotalDiscountPrice(CurrencyUtil.mul(goodsSkuPromotionPrice.getDiscountPrice(), goodsSkuPromotionPrice.getNumber()));
goodsSkuPromotionPrice.setTotalFinalePrice(CurrencyUtil.mul(goodsSkuPromotionPrice.getFinalePrice(), goodsSkuPromotionPrice.getNumber()));
priceDTOList.add(goodsSkuPromotionPrice);
@ -165,13 +233,72 @@ public class PromotionPriceServiceImpl implements PromotionPriceService {
return priceDTOList;
}
/**
* 计算积分商品
* 积分商品的购买金额是0
* 1.根据SkuId去查询积分商品Mongo
* 2.计算积分商品的优惠信息
*
* @param tradeSkuList 交易商品促销金额列表
* @return 计算结果
*/
private List<GoodsSkuPromotionPriceDTO> pointGoodsPromotion(List<PromotionPriceParamDTO> tradeSkuList) {
List<GoodsSkuPromotionPriceDTO> priceDTOList = new ArrayList<>();
//获取积分商品SkuId
String skuId = tradeSkuList.get(0).getSkuId();
//获取积分商品VO
PointsGoodsVO pointsGoodsVO = pointsGoodsService.getPointsGoodsVOByMongo(skuId);
//参与计算的缓存中的商品SKU列表
GoodsSku goodsSku = pointsGoodsVO.getGoodsSku();
//获取商品促销金额
GoodsSkuPromotionPriceDTO goodsSkuPromotionPrice = new GoodsSkuPromotionPriceDTO(goodsSku, tradeSkuList.get(0).getNum());
//计算商品原价=原价*数量
goodsSkuPromotionPrice.setTotalOriginalPrice(CurrencyUtil.mul(goodsSkuPromotionPrice.getOriginalPrice(), goodsSkuPromotionPrice.getNumber()));
//计算商品积分数量=兑换积分*数量
goodsSkuPromotionPrice.setTotalPoints(pointsGoodsVO.getPoints() * Convert.toLong(goodsSkuPromotionPrice.getNumber()));
//优惠金额=商品原价*数量
goodsSkuPromotionPrice.setTotalDiscountPrice(CurrencyUtil.mul(goodsSkuPromotionPrice.getOriginalPrice(), goodsSkuPromotionPrice.getNumber()));
//购买价格=积分商品价格为 0
goodsSkuPromotionPrice.setTotalFinalePrice(0.0);
priceDTOList.add(goodsSkuPromotionPrice);
return priceDTOList;
}
/**
* 计算砍价商品
* 砍价商品只能购买一件
* 1.根据SkuId去查询积分商品Mongo
* 2.计算积分商品的优惠信息
*
* @param tradeSkuList 交易商品促销金额列表
* @return 计算结果
*/
private List<GoodsSkuPromotionPriceDTO> kanjiaPromotion(List<PromotionPriceParamDTO> tradeSkuList) {
List<GoodsSkuPromotionPriceDTO> priceDTOList = new ArrayList<>();
//获取积分商品SkuId
String skuId = tradeSkuList.get(0).getSkuId();
//获取积分商品VO
KanjiaActivityGoodsDTO kanjiaActivityGoodsDTO = kanjiaActivityGoodsService.getKanJiaGoodsBySku(skuId);
//参与计算的缓存中的商品SKU列表
GoodsSku goodsSku = kanjiaActivityGoodsDTO.getGoodsSku();
GoodsSkuPromotionPriceDTO goodsSkuPromotionPrice = new GoodsSkuPromotionPriceDTO(goodsSku, tradeSkuList.get(0).getNum());
//优惠金额=商品原价-购买价格
goodsSkuPromotionPrice.setTotalDiscountPrice(CurrencyUtil.sub(goodsSkuPromotionPrice.getOriginalPrice(), kanjiaActivityGoodsDTO.getPurchasePrice()));
//购买价格=砍价成交金额
goodsSkuPromotionPrice.setTotalFinalePrice(kanjiaActivityGoodsDTO.getPurchasePrice());
priceDTOList.add(goodsSkuPromotionPrice);
return priceDTOList;
}
/**
* 促销计算(秒杀活动拼团满优惠活动砍价)
*
* @param promotionMap 当前商品所有参加的促销活动
* @param goodsSkuPromotionPrice 商品SKU促销计算信息
* @param esGoodsIndex ES商品信息
* @param promotionPriceParamDTO 拼团id标示是否计算拼团活动
* @param promotionPriceParamDTO 拼团id标示是否计算拼团活动
*/
private void calculationPromotionMap(Map<String, Object> promotionMap, GoodsSkuPromotionPriceDTO goodsSkuPromotionPrice, EsGoodsIndex esGoodsIndex, PromotionPriceParamDTO promotionPriceParamDTO) {
//未参加促销则直接返回