Skip to content

Commit

Permalink
'促销详情完善'
Browse files Browse the repository at this point in the history
  • Loading branch information
chopper711 committed Dec 26, 2022
1 parent 903b779 commit 06325a7
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
@Service
public class CouponRender implements CartRenderStep {

@Autowired
private PromotionPriceUtil promotionPriceUtil;
@Autowired
private MemberCouponService memberCouponService;

Expand Down Expand Up @@ -267,7 +265,7 @@ private void renderSku(TradeDTO tradeDTO, MemberCouponDTO memberCouponDTO) {
*/
private void renderCouponPrice(Map<String, Double> couponMap, TradeDTO tradeDTO, MemberCoupon coupon, MemberCouponDTO memberCouponDTO) {
//分发优惠券
promotionPriceUtil.recountPrice(tradeDTO, memberCouponDTO.getSkuDetail(), memberCouponDTO.getMemberCoupon().getPrice(),
PromotionPriceUtil.recountPrice(tradeDTO, memberCouponDTO.getSkuDetail(), memberCouponDTO.getMemberCoupon().getPrice(),
Boolean.TRUE.equals(coupon.getPlatformFlag()) ?
PromotionTypeEnum.PLATFORM_COUPON : PromotionTypeEnum.COUPON, memberCouponDTO.getMemberCoupon().getCouponId());
//如果是平台券 则需要计算商家承担比例
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import cn.lili.modules.order.cart.entity.vo.FullDiscountVO;
import cn.lili.modules.order.cart.render.CartRenderStep;
import cn.lili.modules.order.cart.render.util.PromotionPriceUtil;
import cn.lili.modules.order.order.entity.dto.DiscountPriceItem;
import cn.lili.modules.order.order.entity.dto.PriceDetailDTO;
import cn.lili.modules.promotion.entity.dos.FullDiscount;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -30,9 +31,6 @@
@Service
public class FullDiscountRender implements CartRenderStep {

@Autowired
private PromotionPriceUtil promotionPriceUtil;

@Autowired
private GoodsSkuService goodsSkuService;

Expand Down Expand Up @@ -84,11 +82,11 @@ public void render(TradeDTO tradeDTO) {
if (isFull(countPrice, cart)) {
//如果减现金
if (Boolean.TRUE.equals(fullDiscount.getFullMinusFlag())) {
promotionPriceUtil.recountPrice(tradeDTO, skuPriceDetail, fullDiscount.getFullMinus(), PromotionTypeEnum.FULL_DISCOUNT, fullDiscountVO.getId());
PromotionPriceUtil.recountPrice(tradeDTO, skuPriceDetail, fullDiscount.getFullMinus(), PromotionTypeEnum.FULL_DISCOUNT, fullDiscountVO.getId());
}
//打折
else if (Boolean.TRUE.equals(fullDiscount.getFullRateFlag())) {
this.renderFullRate(cart, skuPriceDetail, CurrencyUtil.div(fullDiscount.getFullRate(), 10));
this.renderFullRate(cart, skuPriceDetail, CurrencyUtil.div(fullDiscount.getFullRate(), 10), fullDiscountVO.getId());
}
//渲染满优惠
renderFullMinus(cart);
Expand All @@ -107,22 +105,33 @@ else if (Boolean.TRUE.equals(fullDiscount.getFullRateFlag())) {
* @param cart
* @param skuPriceDetail
*/
private void renderFullRate(CartVO cart, Map<String, Double> skuPriceDetail, Double rate) {
private void renderFullRate(CartVO cart, Map<String, Double> skuPriceDetail, Double rate, String activityId) {

List<CartSkuVO> cartSkuVOS = cart.getCheckedSkuList().stream().filter(cartSkuVO -> skuPriceDetail.containsKey(cartSkuVO.getGoodsSku().getId())).collect(Collectors.toList());

// 循环计算扣减金额
cartSkuVOS.forEach(cartSkuVO -> {
PriceDetailDTO priceDetailDTO = cartSkuVO.getPriceDetailDTO();


Double discountPrice = CurrencyUtil.mul(priceDetailDTO.getGoodsPrice(),
CurrencyUtil.sub(1, rate)
);
//优惠金额=旧的优惠金额+商品金额*商品折扣比例
priceDetailDTO.setDiscountPrice(
CurrencyUtil.add(priceDetailDTO.getDiscountPrice(),
CurrencyUtil.mul(priceDetailDTO.getGoodsPrice(),
CurrencyUtil.sub(1, rate)
)
CurrencyUtil.add(priceDetailDTO.getDiscountPrice(), discountPrice
)
);
//优惠金额=旧的优惠金额+商品金额*商品折扣比例
priceDetailDTO.addDiscountPriceItem(DiscountPriceItem
.builder()
.discountPrice(discountPrice)
.promotionTypeEnum(PromotionTypeEnum.FULL_DISCOUNT)
.promotionId(activityId)
.skuId(cartSkuVO.getGoodsSku().getId())
.goodsId(cartSkuVO.getGoodsSku().getGoodsId())

.build());

});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class PromotionPriceUtil {
* @param discountPrice 需要分发的优惠金额
* @param promotionTypeEnum 促销类型
*/
public void recountPrice(TradeDTO tradeDTO, Map<String, Double> skuPromotionDetail, Double discountPrice, PromotionTypeEnum promotionTypeEnum, String activityId) {
public static void recountPrice(TradeDTO tradeDTO, Map<String, Double> skuPromotionDetail, Double discountPrice, PromotionTypeEnum promotionTypeEnum, String activityId) {

// sku 促销信息非空判定
if (skuPromotionDetail == null || skuPromotionDetail.size() == 0) {
Expand Down Expand Up @@ -163,7 +163,7 @@ public void recountPrice(TradeDTO tradeDTO, Map<String, Double> skuPromotionDeta
* @param promotionId 活动ID
* @return 是否有效
*/
private boolean checkPromotionValidTime(Date startTime, Date endTime, String promotionType, String promotionId) {
private static boolean checkPromotionValidTime(Date startTime, Date endTime, String promotionType, String promotionId) {
long now = System.currentTimeMillis();
if (startTime.getTime() > now) {
log.error("商品ID为{}的{}活动开始时间小于当时时间,活动未开始!", promotionId, promotionType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import cn.lili.common.enums.PromotionTypeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* 优惠信息详情
Expand All @@ -15,6 +17,8 @@
*/
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DiscountPriceItem {


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package cn.lili.modules.order.order.entity.dto;


import cn.hutool.json.JSONUtil;
import cn.lili.common.utils.CurrencyUtil;
import cn.lili.common.utils.StringUtils;
import cn.lili.modules.promotion.entity.vos.PromotionSkuVO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
Expand Down Expand Up @@ -44,11 +42,8 @@ public class PriceDetailDTO implements Serializable {
@ApiModelProperty(value = "优惠金额")
private Double discountPrice;

/**
* @See List<DiscountPriceItem>
*/
@ApiModelProperty(value = "优惠详情")
private String discountPriceDetail;
private List<DiscountPriceItem> discountPriceDetail;

@ApiModelProperty(value = "优惠券金额")
private Double couponPrice;
Expand Down Expand Up @@ -116,7 +111,8 @@ public class PriceDetailDTO implements Serializable {
*/
public void setDiscountPriceItem(DiscountPriceItem discountPriceItem) {
List<DiscountPriceItem> discountPriceItems = new ArrayList<>();
this.discountPriceDetail = JSONUtil.toJsonStr(discountPriceItems);
discountPriceItems.add(discountPriceItem);
this.discountPriceDetail = discountPriceItems;
}

/**
Expand All @@ -125,10 +121,7 @@ public void setDiscountPriceItem(DiscountPriceItem discountPriceItem) {
* @param discountPriceItem 促销信息
*/
public void addDiscountPriceItem(DiscountPriceItem discountPriceItem) {
List<DiscountPriceItem> discountPriceItems = StringUtils.isEmpty(this.discountPriceDetail) ?
new ArrayList<>() : JSONUtil.toList(this.discountPriceDetail, DiscountPriceItem.class);

this.discountPriceDetail = JSONUtil.toJsonStr(discountPriceItems.add(discountPriceItem));
discountPriceDetail.add(discountPriceItem);
}


Expand Down Expand Up @@ -165,6 +158,7 @@ public PriceDetailDTO() {
billPrice = 0d;
settlementPrice = 0d;

discountPriceDetail = new ArrayList<>();

joinPromotion = new ArrayList<>();
}
Expand Down Expand Up @@ -235,6 +229,8 @@ public void increase(PriceDetailDTO priceDetailDTO) {
billPrice = CurrencyUtil.add(billPrice, priceDetailDTO.getBillPrice());
settlementPrice = CurrencyUtil.add(settlementPrice, priceDetailDTO.getSettlementPrice());

discountPriceDetail.addAll(priceDetailDTO.getDiscountPriceDetail());

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void checkPromotions(Coupon coupon) {
}

//如果优惠券使用时间类型不合法,抛出异常,抛出异常
if (CouponRangeDayEnum.exist(coupon.getRangeDayType())) {
if (!CouponRangeDayEnum.exist(coupon.getRangeDayType())) {
throw new ServiceException(ResultCode.COUPON_RANGE_ERROR);
}

Expand Down

0 comments on commit 06325a7

Please sign in to comment.