浏览代码

暂存调整 Price 接口

YunaiV 2 年之前
父节点
当前提交
5c4b61f5ff

+ 51 - 35
yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/api/price/dto/PriceCalculateRespDTO.java

@@ -35,34 +35,43 @@ public class PriceCalculateRespDTO {
         /**
          * 商品原价(总),单位:分
          *
-         * 基于 {@link OrderItem#getTotalOriginalPrice()} 求和
+         * 基于 {@link OrderItem#getOriginalPrice()} 求和
          */
-        private Integer skuOriginalPrice;
+        private Integer originalPrice;
+        /**
+         * 活动减免优惠(总),单位:分
+         *
+         * 基于 {@link OrderItem#getActivityPrice()} 求和
+         */
+        private Integer activityPrice;
+        /**
+         * 优惠劵减免金额(总),单位:分
+         *
+         * 基于 {@link OrderItem#getCouponPrice()} 求和
+         */
+        private Integer couponPrice;
         /**
-         * 商品优惠(总),单位:分
+         * 积分减免金额(总),单位:分
          *
-         * 基于 {@link OrderItem#getTotalPromotionPrice()} 求和
+         * 基于 {@link OrderItem#getPointPrice()} 求和
          */
-        private Integer skuPromotionPrice;
+        private Integer pointPrice;
         /**
-         * 订单优惠(总),单位:分
+         * 会员减免金额(总),单位:分
          *
-         * 例如说:满减折扣;不包括优惠劵、商品优惠
+         * 基于 {@link OrderItem#getMemberPrice()} 求和
          */
-        private Integer orderPromotionPrice;
+        private Integer memberPrice;
         /**
          * 运费金额,单位:分
          */
         private Integer deliveryPrice;
         /**
-         * 应付金额(总),单位:分
+         * 最终购买金额(总),单位:分
          *
-         * = {@link #skuOriginalPrice}
+         * = {@link OrderItem#getPayPrice()} 求和
          * + {@link #deliveryPrice}
-         * - {@link #skuPromotionPrice}
-         * - {@link #orderPromotionPrice}
          */
-        //         * - {@link #couponPrice}  // TODO 芋艿:靠营销表记录
         private Integer payPrice;
         /**
          * 商品 SKU 数组
@@ -74,12 +83,6 @@ public class PriceCalculateRespDTO {
          * 优惠劵编号
          */
         private Long couponId;
-//        /**
-//         * 优惠劵减免金额,单位:分
-//         *
-//         *   // TODO 芋艿:靠营销表记录
-//         */
-//        private Integer couponPrice;
 
     }
 
@@ -94,41 +97,54 @@ public class PriceCalculateRespDTO {
          */
         private Integer count;
 
+        /**
+         * 商品原价(总),单位:分
+         *
+         * = {@link #originalUnitPrice} * {@link #getCount()}
+         */
+        private Integer originalPrice;
         /**
          * 商品原价(单),单位:分
          *
          * 对应 ProductSkuDO 的 price 字段
          */
-        private Integer originalPrice;
+        private Integer originalUnitPrice;
         /**
-         * 商品原价(总),单位:分
+         * 活动减免优惠(总),单位:分
          *
-         * = {@link #originalPrice} * {@link #getCount()}
+         * 例如说,限时折扣、满减送等营销活动
          */
-        private Integer totalOriginalPrice;
+        private Integer activityPrice;
         /**
-         * 商品级优惠(总),单位:分
+         * 优惠劵减免金额(总),单位:分
          *
-         * 例如说“限时折扣”:商品原价的 8 折;商品原价的减 50 元
+         * 一个优惠劵会作用到的多个 SKU 商品,按照计算时的 {@link #payPrice} 的比例分摊
          */
-        private Integer totalPromotionPrice;
+        private Integer couponPrice;
+        /**
+         * 积分减免金额(总),单位:分
+         */
+        private Integer pointPrice;
+        /**
+         * 会员减免金额(总),单位:分
+         */
+        private Integer memberPrice;
         /**
          * 最终购买金额(总),单位:分。
          *
-         * = {@link #totalOriginalPrice}
-         * - {@link #totalPromotionPrice}
+         * = {@link #originalPrice}
+         * - {@link #activityPrice}
+         * - {@link #couponPrice}
+         * - {@link #pointPrice}
+         * - {@link #memberPrice}
          */
-        private Integer totalPresentPrice;
+        private Integer payPrice;
         /**
          * 最终购买金额(单),单位:分。
          *
-         * = {@link #totalPresentPrice} / {@link #getCount()}
-         */
-        private Integer presentPrice;
-        /**
-         * 应付金额(总),单位:分
+         * = {@link #payPrice} / {@link #getCount()}
          */
-        private Integer totalPayPrice;
+        private Integer payUnitPrice;
 
     }
 

+ 2 - 2
yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionLevelEnum.java

@@ -15,8 +15,8 @@ import java.util.Arrays;
 @AllArgsConstructor
 public enum PromotionLevelEnum implements IntArrayValuable {
 
-    ORDER(1, "订单级"),
-    SKU(2, "商品级"),
+    ORDER(1, "订单级"), // 多个商品,进行组合后优惠
+    SKU(2, "商品级"), // 单个商品,直接优惠
     ;
 
     public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionLevelEnum::getLevel).toArray();

+ 2 - 2
yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionTypeEnum.java

@@ -15,8 +15,8 @@ import java.util.Arrays;
 @AllArgsConstructor
 public enum PromotionTypeEnum implements IntArrayValuable {
 
-    DISCOUNT(1, "限时折扣"),
-    REWARD(2, "满减送"),
+    DISCOUNT_ACTIVITY(1, "限时折扣"),
+    REWARD_ACTIVITY(2, "满减送"),
     ;
 
     public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionTypeEnum::getType).toArray();

+ 5 - 5
yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/convert/price/PriceConvert.java

@@ -19,8 +19,8 @@ public interface PriceConvert {
     default PriceCalculateRespDTO convert(PriceCalculateReqDTO calculateReqDTO, List<ProductSkuRespDTO> skuList) {
         // 创建 PriceCalculateRespDTO 对象
         PriceCalculateRespDTO priceCalculate = new PriceCalculateRespDTO();
-        priceCalculate.setOrder(new PriceCalculateRespDTO.Order().setSkuOriginalPrice(0).setSkuPromotionPrice(0)
-                .setOrderPromotionPrice(0).setDeliveryPrice(0).setPayPrice(0).setItems(new ArrayList<>())
+        priceCalculate.setOrder(new PriceCalculateRespDTO.Order().setOriginalPrice(0).setActivityPrice(0)
+                .setDeliveryPrice(0).setPayPrice(0).setItems(new ArrayList<>())
                 .setCouponId(calculateReqDTO.getCouponId()));
         priceCalculate.setPromotions(new ArrayList<>());
         // 创建它的 OrderItem 属性
@@ -29,9 +29,9 @@ public interface PriceConvert {
         skuList.forEach(sku -> {
             Integer count = skuIdCountMap.get(sku.getId());
             PriceCalculateRespDTO.OrderItem orderItem = new PriceCalculateRespDTO.OrderItem().setCount(count)
-                    .setOriginalPrice(sku.getPrice()).setTotalOriginalPrice(sku.getPrice() * count).setTotalPromotionPrice(0);
-            orderItem.setTotalPresentPrice(orderItem.getTotalPresentPrice()).setPresentPrice(orderItem.getOriginalPrice())
-                    .setTotalPayPrice(orderItem.getTotalPayPrice());
+                    .setOriginalUnitPrice(sku.getPrice()).setOriginalPrice(sku.getPrice() * count).setActivityPrice(0);
+            orderItem.setPayPrice(orderItem.getPayPrice()).setPayUnitPrice(orderItem.getOriginalUnitPrice())
+                    .setPayPrice(orderItem.getPayPrice());
             priceCalculate.getOrder().getItems().add(orderItem);
         });
         return priceCalculate;

+ 1 - 4
yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/price/PriceServiceImpl.java

@@ -15,7 +15,6 @@ import java.util.Map;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS;
-import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_STOCK_NOT_ENOUGH;
 
 /**
  * 价格计算 Service 实现类
@@ -54,9 +53,7 @@ public class PriceServiceImpl implements PriceService {
             if (count == null) {
                 throw exception(SKU_NOT_EXISTS);
             }
-            if (count > sku.getStock()) {
-                throw exception(SKU_STOCK_NOT_ENOUGH);
-            }
+            // 不校验库存不足,避免购物车场景,商品无货的情况
         });
         return skus;
     }