From 06325a7ce1e5bef47df4d68045c1bd30424bf8b0 Mon Sep 17 00:00:00 2001 From: Chopper711 Date: Mon, 26 Dec 2022 19:00:13 +0800 Subject: [PATCH] =?UTF-8?q?'=E4=BF=83=E9=94=80=E8=AF=A6=E6=83=85=E5=AE=8C?= =?UTF-8?q?=E5=96=84'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/cart/render/impl/CouponRender.java | 4 +-- .../cart/render/impl/FullDiscountRender.java | 29 ++++++++++++------- .../cart/render/util/PromotionPriceUtil.java | 4 +-- .../order/entity/dto/DiscountPriceItem.java | 4 +++ .../order/entity/dto/PriceDetailDTO.java | 18 +++++------- .../serviceimpl/CouponServiceImpl.java | 2 +- 6 files changed, 34 insertions(+), 27 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CouponRender.java b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CouponRender.java index 023f24b9..36d0423a 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CouponRender.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CouponRender.java @@ -31,8 +31,6 @@ import java.util.stream.Collectors; @Service public class CouponRender implements CartRenderStep { - @Autowired - private PromotionPriceUtil promotionPriceUtil; @Autowired private MemberCouponService memberCouponService; @@ -267,7 +265,7 @@ public class CouponRender implements CartRenderStep { */ private void renderCouponPrice(Map 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()); //如果是平台券 则需要计算商家承担比例 diff --git a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/FullDiscountRender.java b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/FullDiscountRender.java index b6663995..24618c4b 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/FullDiscountRender.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/FullDiscountRender.java @@ -13,6 +13,7 @@ import cn.lili.modules.order.cart.entity.vo.CartVO; 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; @@ -30,9 +31,6 @@ import java.util.stream.Collectors; @Service public class FullDiscountRender implements CartRenderStep { - @Autowired - private PromotionPriceUtil promotionPriceUtil; - @Autowired private GoodsSkuService goodsSkuService; @@ -84,11 +82,11 @@ public class FullDiscountRender implements CartRenderStep { 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); @@ -107,7 +105,7 @@ public class FullDiscountRender implements CartRenderStep { * @param cart * @param skuPriceDetail */ - private void renderFullRate(CartVO cart, Map skuPriceDetail, Double rate) { + private void renderFullRate(CartVO cart, Map skuPriceDetail, Double rate, String activityId) { List cartSkuVOS = cart.getCheckedSkuList().stream().filter(cartSkuVO -> skuPriceDetail.containsKey(cartSkuVO.getGoodsSku().getId())).collect(Collectors.toList()); @@ -115,14 +113,25 @@ public class FullDiscountRender implements CartRenderStep { 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()); }); diff --git a/framework/src/main/java/cn/lili/modules/order/cart/render/util/PromotionPriceUtil.java b/framework/src/main/java/cn/lili/modules/order/cart/render/util/PromotionPriceUtil.java index ad42aa32..dc1c2348 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/render/util/PromotionPriceUtil.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/render/util/PromotionPriceUtil.java @@ -28,7 +28,7 @@ public class PromotionPriceUtil { * @param discountPrice 需要分发的优惠金额 * @param promotionTypeEnum 促销类型 */ - public void recountPrice(TradeDTO tradeDTO, Map skuPromotionDetail, Double discountPrice, PromotionTypeEnum promotionTypeEnum, String activityId) { + public static void recountPrice(TradeDTO tradeDTO, Map skuPromotionDetail, Double discountPrice, PromotionTypeEnum promotionTypeEnum, String activityId) { // sku 促销信息非空判定 if (skuPromotionDetail == null || skuPromotionDetail.size() == 0) { @@ -163,7 +163,7 @@ public class PromotionPriceUtil { * @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); diff --git a/framework/src/main/java/cn/lili/modules/order/order/entity/dto/DiscountPriceItem.java b/framework/src/main/java/cn/lili/modules/order/order/entity/dto/DiscountPriceItem.java index 5ed19646..5391e00f 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/entity/dto/DiscountPriceItem.java +++ b/framework/src/main/java/cn/lili/modules/order/order/entity/dto/DiscountPriceItem.java @@ -2,8 +2,10 @@ package cn.lili.modules.order.order.entity.dto; import cn.lili.common.enums.PromotionTypeEnum; import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; /** * 优惠信息详情 @@ -15,6 +17,8 @@ import lombok.Data; */ @Builder @Data +@NoArgsConstructor +@AllArgsConstructor public class DiscountPriceItem { diff --git a/framework/src/main/java/cn/lili/modules/order/order/entity/dto/PriceDetailDTO.java b/framework/src/main/java/cn/lili/modules/order/order/entity/dto/PriceDetailDTO.java index c230af56..76f6dad6 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/entity/dto/PriceDetailDTO.java +++ b/framework/src/main/java/cn/lili/modules/order/order/entity/dto/PriceDetailDTO.java @@ -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; @@ -44,11 +42,8 @@ public class PriceDetailDTO implements Serializable { @ApiModelProperty(value = "优惠金额") private Double discountPrice; - /** - * @See List - */ @ApiModelProperty(value = "优惠详情") - private String discountPriceDetail; + private List discountPriceDetail; @ApiModelProperty(value = "优惠券金额") private Double couponPrice; @@ -116,7 +111,8 @@ public class PriceDetailDTO implements Serializable { */ public void setDiscountPriceItem(DiscountPriceItem discountPriceItem) { List discountPriceItems = new ArrayList<>(); - this.discountPriceDetail = JSONUtil.toJsonStr(discountPriceItems); + discountPriceItems.add(discountPriceItem); + this.discountPriceDetail = discountPriceItems; } /** @@ -125,10 +121,7 @@ public class PriceDetailDTO implements Serializable { * @param discountPriceItem 促销信息 */ public void addDiscountPriceItem(DiscountPriceItem discountPriceItem) { - List discountPriceItems = StringUtils.isEmpty(this.discountPriceDetail) ? - new ArrayList<>() : JSONUtil.toList(this.discountPriceDetail, DiscountPriceItem.class); - - this.discountPriceDetail = JSONUtil.toJsonStr(discountPriceItems.add(discountPriceItem)); + discountPriceDetail.add(discountPriceItem); } @@ -165,6 +158,7 @@ public class PriceDetailDTO implements Serializable { billPrice = 0d; settlementPrice = 0d; + discountPriceDetail = new ArrayList<>(); joinPromotion = new ArrayList<>(); } @@ -235,6 +229,8 @@ public class PriceDetailDTO implements Serializable { billPrice = CurrencyUtil.add(billPrice, priceDetailDTO.getBillPrice()); settlementPrice = CurrencyUtil.add(settlementPrice, priceDetailDTO.getSettlementPrice()); + discountPriceDetail.addAll(priceDetailDTO.getDiscountPriceDetail()); + } /** diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java index 3f29131a..cf6dd6bc 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java @@ -196,7 +196,7 @@ public class CouponServiceImpl extends AbstractPromotionsServiceImpl