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 549dbd04..023f24b9 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 @@ -269,7 +269,7 @@ public class CouponRender implements CartRenderStep { //分发优惠券 promotionPriceUtil.recountPrice(tradeDTO, memberCouponDTO.getSkuDetail(), memberCouponDTO.getMemberCoupon().getPrice(), Boolean.TRUE.equals(coupon.getPlatformFlag()) ? - PromotionTypeEnum.PLATFORM_COUPON : PromotionTypeEnum.COUPON); + PromotionTypeEnum.PLATFORM_COUPON : PromotionTypeEnum.COUPON, memberCouponDTO.getMemberCoupon().getCouponId()); //如果是平台券 则需要计算商家承担比例 if (Boolean.TRUE.equals(coupon.getPlatformFlag()) && coupon.getStoreCommission() > 0) { 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 dc473902..b6663995 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 @@ -84,7 +84,7 @@ public class FullDiscountRender implements CartRenderStep { if (isFull(countPrice, cart)) { //如果减现金 if (Boolean.TRUE.equals(fullDiscount.getFullMinusFlag())) { - promotionPriceUtil.recountPrice(tradeDTO, skuPriceDetail, fullDiscount.getFullMinus(), PromotionTypeEnum.FULL_DISCOUNT); + promotionPriceUtil.recountPrice(tradeDTO, skuPriceDetail, fullDiscount.getFullMinus(), PromotionTypeEnum.FULL_DISCOUNT, fullDiscountVO.getId()); } //打折 else if (Boolean.TRUE.equals(fullDiscount.getFullRateFlag())) { diff --git a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java index 280082ed..1eb8efa8 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/SkuPromotionRender.java @@ -15,6 +15,7 @@ import cn.lili.modules.order.cart.entity.enums.RenderStepEnums; 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.entity.dto.DiscountPriceItem; import cn.lili.modules.order.order.entity.dto.PriceDetailDTO; import cn.lili.modules.promotion.entity.dto.search.KanjiaActivitySearchParams; import cn.lili.modules.promotion.entity.enums.KanJiaStatusEnum; @@ -117,6 +118,17 @@ public class SkuPromotionRender implements CartRenderStep { PromotionSkuVO promotionSkuVO = new PromotionSkuVO(PromotionTypeEnum.POINTS_GOODS.name(), cartSkuVO.getPointsId()); cartSkuVO.getPriceDetailDTO().getJoinPromotion().add(promotionSkuVO); totalPayPoints += cartSkuVO.getPoint(); + + //记录优惠由来 + cartSkuVO.getPriceDetailDTO().setDiscountPriceItem( + DiscountPriceItem.builder() + .discountPrice(CurrencyUtil.sub(cartSkuVO.getGoodsSku().getPrice(), cartSkuVO.getPurchasePrice())) + .promotionId(promotionSkuVO.getActivityId()) + .promotionTypeEnum(PromotionTypeEnum.POINTS_GOODS) + .skuId(cartSkuVO.getGoodsSku().getId()) + .goodsId(cartSkuVO.getGoodsSku().getGoodsId()) + .build() + ); } } if (userInfo.getPoint() < totalPayPoints) { @@ -138,9 +150,19 @@ public class SkuPromotionRender implements CartRenderStep { cartSkuVO.setSubTotal(kanjiaActivityVO.getPurchasePrice()); cartSkuVO.getPriceDetailDTO().setGoodsPrice(kanjiaActivityVO.getPurchasePrice()); } - PromotionSkuVO promotionSkuVO = new PromotionSkuVO(PromotionTypeEnum.KANJIA.name(), cartSkuVO.getKanjiaId()); cartSkuVO.getPriceDetailDTO().getJoinPromotion().add(promotionSkuVO); + + //记录优惠由来 + cartSkuVO.getPriceDetailDTO().setDiscountPriceItem( + DiscountPriceItem.builder() + .discountPrice(CurrencyUtil.sub(cartSkuVO.getGoodsSku().getPrice(), cartSkuVO.getPurchasePrice())) + .promotionId(promotionSkuVO.getActivityId()) + .promotionTypeEnum(PromotionTypeEnum.KANJIA) + .skuId(cartSkuVO.getGoodsSku().getId()) + .goodsId(cartSkuVO.getGoodsSku().getGoodsId()) + .build() + ); } } return; @@ -149,6 +171,17 @@ public class SkuPromotionRender implements CartRenderStep { for (CartSkuVO cartSkuVO : cartVO.getCheckedSkuList()) { PromotionSkuVO promotionSkuVO = new PromotionSkuVO(PromotionTypeEnum.PINTUAN.name(), cartSkuVO.getPintuanId()); cartSkuVO.getPriceDetailDTO().getJoinPromotion().add(promotionSkuVO); + + //记录优惠由来 + cartSkuVO.getPriceDetailDTO().setDiscountPriceItem( + DiscountPriceItem.builder() + .discountPrice(CurrencyUtil.sub(cartSkuVO.getGoodsSku().getPrice(), cartSkuVO.getPurchasePrice())) + .promotionId(promotionSkuVO.getActivityId()) + .promotionTypeEnum(PromotionTypeEnum.PINTUAN) + .skuId(cartSkuVO.getGoodsSku().getId()) + .goodsId(cartSkuVO.getGoodsSku().getGoodsId()) + .build() + ); } } return; 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 b6f1a731..ad42aa32 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 @@ -4,8 +4,8 @@ import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.utils.CurrencyUtil; import cn.lili.modules.order.cart.entity.dto.TradeDTO; import cn.lili.modules.order.cart.entity.vo.CartSkuVO; +import cn.lili.modules.order.order.entity.dto.DiscountPriceItem; import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; import java.util.Date; import java.util.List; @@ -17,7 +17,6 @@ import java.util.Map; * @author paulG * @since 2020/8/21 **/ -@Service @Slf4j public class PromotionPriceUtil { @@ -29,7 +28,7 @@ public class PromotionPriceUtil { * @param discountPrice 需要分发的优惠金额 * @param promotionTypeEnum 促销类型 */ - public void recountPrice(TradeDTO tradeDTO, Map skuPromotionDetail, Double discountPrice, PromotionTypeEnum promotionTypeEnum) { + public void recountPrice(TradeDTO tradeDTO, Map skuPromotionDetail, Double discountPrice, PromotionTypeEnum promotionTypeEnum, String activityId) { // sku 促销信息非空判定 if (skuPromotionDetail == null || skuPromotionDetail.size() == 0) { @@ -102,6 +101,17 @@ public class PromotionPriceUtil { cartSkuVO.getPriceDetailDTO().setCouponPrice( CurrencyUtil.add(cartSkuVO.getPriceDetailDTO().getCouponPrice(), skuDiscountPrice)); + + cartSkuVO.getPriceDetailDTO().addDiscountPriceItem( + DiscountPriceItem.builder() + .goodsId(cartSkuVO.getGoodsSku().getGoodsId()) + .skuId(cartSkuVO.getGoodsSku().getId()) + .discountPrice(skuDiscountPrice) + .promotionTypeEnum(PromotionTypeEnum.COUPON) + .promotionId(activityId) + .build() + ); + } else if (promotionTypeEnum == PromotionTypeEnum.PLATFORM_COUPON) { cartSkuVO.getPriceDetailDTO().setSiteCouponPrice( @@ -109,9 +119,32 @@ public class PromotionPriceUtil { cartSkuVO.getPriceDetailDTO().setCouponPrice( CurrencyUtil.add(cartSkuVO.getPriceDetailDTO().getCouponPrice(), cartSkuVO.getPriceDetailDTO().getSiteCouponPrice())); + + + cartSkuVO.getPriceDetailDTO().addDiscountPriceItem( + DiscountPriceItem.builder() + .goodsId(cartSkuVO.getGoodsSku().getGoodsId()) + .skuId(cartSkuVO.getGoodsSku().getId()) + .discountPrice(skuDiscountPrice) + .promotionTypeEnum(PromotionTypeEnum.PLATFORM_COUPON) + .promotionId(activityId) + .build() + ); + } else { cartSkuVO.getPriceDetailDTO().setDiscountPrice( CurrencyUtil.add(cartSkuVO.getPriceDetailDTO().getDiscountPrice(), skuDiscountPrice)); + + //目前剩余的只有满减金额活动。后续如果需要调整,这里建议传递活动类型进来 + cartSkuVO.getPriceDetailDTO().addDiscountPriceItem( + DiscountPriceItem.builder() + .goodsId(cartSkuVO.getGoodsSku().getGoodsId()) + .skuId(cartSkuVO.getGoodsSku().getId()) + .discountPrice(skuDiscountPrice) + .promotionTypeEnum(PromotionTypeEnum.FULL_DISCOUNT) + .promotionId(activityId) + .build() + ); } } } 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 912d7a2c..5ed19646 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,6 +2,7 @@ package cn.lili.modules.order.order.entity.dto; import cn.lili.common.enums.PromotionTypeEnum; import io.swagger.annotations.ApiModelProperty; +import lombok.Builder; import lombok.Data; /** @@ -12,6 +13,7 @@ import lombok.Data; * @Description: * @since 2022/12/23 14:52 */ +@Builder @Data 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 22361ecd..c230af56 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,7 +1,9 @@ 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; @@ -42,6 +44,9 @@ public class PriceDetailDTO implements Serializable { @ApiModelProperty(value = "优惠金额") private Double discountPrice; + /** + * @See List + */ @ApiModelProperty(value = "优惠详情") private String discountPriceDetail; @@ -104,6 +109,29 @@ public class PriceDetailDTO implements Serializable { private List joinPromotion; + /** + * 设置促销详情 + * + * @param discountPriceItem 促销信息 + */ + public void setDiscountPriceItem(DiscountPriceItem discountPriceItem) { + List discountPriceItems = new ArrayList<>(); + this.discountPriceDetail = JSONUtil.toJsonStr(discountPriceItems); + } + + /** + * 设置促销详情 + * + * @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)); + } + + public Double getOriginalPrice() { if (originalPrice == 0D) { return flowPrice;