Browse Source

mall:新增价格计算的接口

YunaiV 2 years ago
parent
commit
5948be86a8

+ 7 - 0
yudao-module-mall/yudao-module-market-api/pom.xml

@@ -21,6 +21,13 @@
             <groupId>cn.iocoder.boot</groupId>
             <artifactId>yudao-common</artifactId>
         </dependency>
+
+        <!-- 参数校验 -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-validation</artifactId>
+            <optional>true</optional>
+        </dependency>
     </dependencies>
 
 </project>

+ 21 - 0
yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/api/price/PriceApi.java

@@ -0,0 +1,21 @@
+package cn.iocoder.yudao.module.market.api.price;
+
+import cn.iocoder.yudao.module.market.api.price.dto.PriceCalculateReqDTO;
+import cn.iocoder.yudao.module.market.api.price.dto.PriceCalculateRespDTO;
+
+/**
+ * 价格 API 接口
+ *
+ * @author 芋道源码
+ */
+public interface PriceApi {
+
+    /**
+     * 计算商品的价格
+     *
+     * @param calculateReqDTO 价格请求
+     * @return 价格相应
+     */
+    PriceCalculateRespDTO calculatePrice(PriceCalculateReqDTO calculateReqDTO);
+
+}

+ 56 - 0
yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/api/price/dto/PriceCalculateReqDTO.java

@@ -0,0 +1,56 @@
+package cn.iocoder.yudao.module.market.api.price.dto;
+
+import lombok.Data;
+
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+/**
+ * 价格计算 Request DTO
+ *
+ * @author 芋道源码
+ */
+@Data
+public class PriceCalculateReqDTO {
+
+    /**
+     * 用户编号
+     *
+     * 对应 MemberUserDO 的 id 编号
+     */
+    private Long userId;
+
+    /**
+     * 优惠劵编号
+     */
+    private Long couponId;
+
+    /**
+     * 商品 SKU 数组
+     */
+    @NotNull(message = "商品数组不能为空")
+    private List<Item> items;
+
+    /**
+     * 商品 SKU
+     */
+    @Data
+    public static class Item {
+
+        /**
+         * SKU 编号
+         */
+        @NotNull(message = "商品 SKU 编号不能为空")
+        private Long skuId;
+
+        /**
+         * SKU 数量
+         */
+        @NotNull(message = "商品 SKU 数量不能为空")
+        @Min(value = 0L, message = "商品 SKU 数量必须大于等于 0") // 可传递 0 数量,用于购物车未选中的情况
+        private Integer count;
+
+    }
+
+}

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

@@ -0,0 +1,191 @@
+package cn.iocoder.yudao.module.market.api.price.dto;
+
+import cn.iocoder.yudao.module.market.enums.common.PromotionLevelEnum;
+import cn.iocoder.yudao.module.market.enums.common.PromotionTypeEnum;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 价格计算 Response DTO
+ *
+ * @author 芋道源码
+ */
+@Data
+public class PriceCalculateRespDTO {
+
+    /**
+     * 订单
+     */
+    private Order order;
+
+    /**
+     * 商品 SKU 数组
+     */
+    private List<Item> items;
+
+    /**
+     * 营销活动数组
+     *
+     * 只对应 {@link #items} 商品匹配的活动
+     */
+    private List<Promotion> promotions;
+
+    /**
+     * 订单
+     */
+    @Data
+    public static class Order {
+
+        /**
+         * 商品原价(总),单位:分
+         *
+         * 基于 {@link Item#getTotalOriginalPrice()} 求和
+         */
+        private Integer skuOriginalPrice;
+        /**
+         * 商品优惠(总),单位:分
+         *
+         * 基于 {@link Item#getTotalPromotionPrice()} 求和
+         */
+        private Integer skuPromotionPrice;
+        /**
+         * 订单优惠(总),单位:分
+         *
+         * 例如说:满减折扣;不包括优惠劵、商品优惠
+         */
+        private Integer orderPromotionPrice;
+        /**
+         * 运费金额,单位:分
+         */
+        private Integer deliveryPrice;
+        /**
+         * 应付金额(总),单位:分
+         *
+         * = {@link #skuOriginalPrice}
+         * + {@link #deliveryPrice}
+         * - {@link #skuPromotionPrice}
+         * - {@link #orderPromotionPrice}
+         * - {@link #couponPrice} // TODO 芋艿:需要再考虑一下它
+         */
+        private Integer payPrice;
+
+        // ========== 营销基本信息 ==========
+        /**
+         * 优惠劵编号
+         */
+        private Long couponId;
+        /**
+         * 优惠劵减免金额,单位:分
+         */
+        private Integer couponPrice;
+
+    }
+
+    /**
+     * 商品 SKU
+     */
+    @Data
+    public static class Item extends PriceCalculateReqDTO.Item {
+
+        /**
+         * 商品原价(单),单位:分
+         *
+         * 对应 ProductSkuDO 的 price 字段
+         */
+        private Integer originalPrice;
+        /**
+         * 商品原价(总),单位:分
+         *
+         * = {@link #originalPrice} * {@link #getCount()}
+         */
+        private Integer totalOriginalPrice;
+        /**
+         * 商品级优惠(总),单位:分
+         *
+         * 例如说“限时折扣”:商品原价的 8 折;商品原价的减 50 元
+         */
+        private Integer totalPromotionPrice;
+        /**
+         * 最终购买金额(总),单位:分。
+         *
+         * = {@link #totalOriginalPrice}
+         * - {@link #totalPromotionPrice}
+         */
+        private Integer totalPresentPrice;
+        /**
+         * 最终购买金额(单),单位:分。
+         *
+         * = {@link #totalPresentPrice} / {@link #getCount()}
+         */
+        private Integer presentPrice;
+        /**
+         * 应付金额(总),单位:分
+         */
+        private Integer totalPayPrice;
+
+    }
+
+    /**
+     * 营销活动
+     */
+    @Data
+    public static class Promotion {
+
+        /**
+         * 营销编号
+         *
+         * 例如说:营销活动的编号、优惠劵的编号
+         */
+        private Long id;
+        /**
+         * 营销类型
+         *
+         * 枚举 {@link PromotionTypeEnum}
+         */
+        private Integer type;
+        /**
+         * 营销级别
+         *
+         * 枚举 {@link PromotionLevelEnum}
+         */
+        private Integer level;
+        /**
+         * 匹配的商品 SKU 数组
+         */
+        private List<Item> items;
+        /**
+         * 计算时的原价(总),单位:分
+         */
+        private Integer totalOriginalPrice;
+        /**
+         * 计算时的优惠(总),单位:分
+         */
+        private Integer totalPromotionPrice;
+        // TODO 芋艿:是否匹配,match ;不匹配的原因
+        // TODO 芋艿:描述
+
+        /**
+         * 匹配的商品 SKU
+         */
+        @Data
+        public static class Item {
+
+            /**
+             * 商品 SKU 编号
+             */
+            private Long skuId;
+            /**
+             * 计算时的原价(总),单位:分
+             */
+            private Integer totalOriginalPrice;
+            /**
+             * 计算时的优惠(总),单位:分
+             */
+            private Integer totalPromotionPrice;
+
+        }
+
+    }
+
+}

+ 0 - 44
yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/activity/MarketActivityTypeEnum.java

@@ -1,44 +0,0 @@
-package cn.iocoder.yudao.module.market.enums.activity;
-
-import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
-
-import java.util.Arrays;
-
-/**
- * 促销活动类型枚举
- */
-public enum MarketActivityTypeEnum implements IntArrayValuable {
-
-    TIME_LIMITED_DISCOUNT(1, "限时折扣"),
-    FULL_PRIVILEGE(2, "满减送"),
-    ;
-
-    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(MarketActivityTypeEnum::getValue).toArray();
-
-    /**
-     * 类型值
-     */
-    private final Integer value;
-    /**
-     * 类型名
-     */
-    private final String name;
-
-    MarketActivityTypeEnum(Integer value, String name) {
-        this.value = value;
-        this.name = name;
-    }
-
-    public Integer getValue() {
-        return value;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    @Override
-    public int[] array() {
-        return ARRAYS;
-    }
-}

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

@@ -0,0 +1,37 @@
+package cn.iocoder.yudao.module.market.enums.common;
+
+import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.util.Arrays;
+
+/**
+ * 营销的级别枚举
+ *
+ * @author 芋道源码
+ */
+@Getter
+@AllArgsConstructor
+public enum PromotionLevelEnum implements IntArrayValuable {
+
+    ORDER(1, "订单级"),
+    SKU(2, "商品级"),
+    ;
+
+    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionLevelEnum::getLevel).toArray();
+
+    /**
+     * 级别值
+     */
+    private final Integer level;
+    /**
+     * 类型名
+     */
+    private final String name;
+
+    @Override
+    public int[] array() {
+        return ARRAYS;
+    }
+}

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

@@ -0,0 +1,37 @@
+package cn.iocoder.yudao.module.market.enums.common;
+
+import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.util.Arrays;
+
+/**
+ * 营销类型枚举
+ *
+ * @author 芋道源码
+ */
+@Getter
+@AllArgsConstructor
+public enum PromotionTypeEnum implements IntArrayValuable {
+
+    TIME_LIMITED_DISCOUNT(1, "限时折扣"),
+    FULL_PRIVILEGE(2, "满减送"),
+    ;
+
+    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionTypeEnum::getType).toArray();
+
+    /**
+     * 类型值
+     */
+    private final Integer type;
+    /**
+     * 类型名
+     */
+    private final String name;
+
+    @Override
+    public int[] array() {
+        return ARRAYS;
+    }
+}

+ 2 - 2
yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityBaseVO.java

@@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.market.controller.admin.activity.vo;
 
 import cn.iocoder.yudao.framework.common.validation.InEnum;
 import cn.iocoder.yudao.module.market.enums.activity.MarketActivityStatusEnum;
-import cn.iocoder.yudao.module.market.enums.activity.MarketActivityTypeEnum;
+import cn.iocoder.yudao.module.market.enums.common.PromotionTypeEnum;
 import lombok.*;
 import java.util.*;
 import io.swagger.annotations.*;
@@ -24,7 +24,7 @@ public class ActivityBaseVO {
 
     @ApiModelProperty(value = "活动类型", required = true)
     @NotNull(message = "活动类型不能为空")
-    @InEnum(MarketActivityTypeEnum.class)
+    @InEnum(PromotionTypeEnum.class)
     private Integer activityType;
 
     @ApiModelProperty(value = "活动状态", required = true)

+ 2 - 2
yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/controller/admin/activity/vo/ActivityPageReqVO.java

@@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.market.controller.admin.activity.vo;
 
 import cn.iocoder.yudao.framework.common.validation.InEnum;
 import cn.iocoder.yudao.module.market.enums.activity.MarketActivityStatusEnum;
-import cn.iocoder.yudao.module.market.enums.activity.MarketActivityTypeEnum;
+import cn.iocoder.yudao.module.market.enums.common.PromotionTypeEnum;
 import lombok.*;
 import java.util.*;
 import io.swagger.annotations.*;
@@ -21,7 +21,7 @@ public class ActivityPageReqVO extends PageParam {
     private String title;
 
     @ApiModelProperty(value = "活动类型")
-    @InEnum(MarketActivityTypeEnum.class)
+    @InEnum(PromotionTypeEnum.class)
     private Integer activityType;
 
     @ApiModelProperty(value = "活动状态")

+ 12 - 5
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java

@@ -110,6 +110,8 @@ public class TradeOrderDO extends BaseDO {
 
     // ========== 价格 + 支付基本信息 ==========
     // 价格文档 - 淘宝:https://open.taobao.com/docV3.htm?docId=108471&docType=1
+    // 价格文档 - 京东到家:https://openo2o.jddj.com/api/getApiDetail/182/4d1494c5e7ac4679bfdaaed950c5bc7f.htm
+    // 价格文档 - 有赞:https://doc.youzanyun.com/detail/API/0/906
 
 //  TODO  promotion_details(订单优惠信息明细,商品和订单级优惠一般都在里面)
 
@@ -118,7 +120,8 @@ public class TradeOrderDO extends BaseDO {
      *
      * 基于 {@link TradeOrderItemDO#getTotalOriginalPrice()} 求和
      */
-    private Integer skuOriginalPrice; // niu - goods_money;
+    // niu - goods_money;
+    private Integer skuOriginalPrice;
     /**
      * 商品优惠(总),单位:分
      *
@@ -130,11 +133,13 @@ public class TradeOrderDO extends BaseDO {
      *
      * 例如说:满减折扣;不包括优惠劵、商品优惠
      */
-    private Integer orderPromotionPrice; // niu - promotion_money;taobao - discount_fee(主订单优惠)
+    // niu - promotion_money;taobao - discount_fee(主订单优惠)
+    private Integer orderPromotionPrice;
     /**
      * 运费金额,单位:分
      */
-    private Integer deliveryPrice; // niu - delivery_money;taobao - post_fee(订单邮费)
+    // niu - delivery_money;taobao - post_fee(订单邮费)
+    private Integer deliveryPrice;
     // TODO 芋艿:taobao 的:trade.adjust_fee/order.adjust_fee(调整金额,如:卖家手动修改订单价格,官方数据修复等等)
     /**
      * 应付金额(总),单位:分
@@ -145,7 +150,8 @@ public class TradeOrderDO extends BaseDO {
      * - {@link #orderPromotionPrice}
      * - {@link #couponPrice}
      */
-    private Integer payPrice; // niu - pay_money;taobao - payment(主订单实付金额) | trade.total_fee(主订单应付金额,参考使用);
+    // niu - pay_money;taobao - payment(主订单实付金额) | trade.total_fee(主订单应付金额,参考使用);
+    private Integer payPrice;
     /**
      * 支付订单编号
      *
@@ -244,7 +250,8 @@ public class TradeOrderDO extends BaseDO {
     /**
      * 优惠劵减免金额,单位:分
      */
-    private Integer couponPrice; // niu - coupon_money;
+    // niu - coupon_money;
+    private Integer couponPrice;
 //    /**
 //     * 积分抵扣的金额,单位:分
 //     */

+ 10 - 5
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java

@@ -84,19 +84,22 @@ public class TradeOrderItemDO extends BaseDO {
      *
      * 对应 ProductSkuDO 的 price 字段
      */
-    private Integer originalPrice; // like - original_price;niu - costPrice
+    // like - original_price;niu - costPrice
+    private Integer originalPrice;
     /**
      * 商品原价(总),单位:分
      *
      * = {@link #originalPrice} * {@link #count}
      */
-    private Integer totalOriginalPrice; // like - total_price;niu - 暂无
+    // like - total_price;niu - 暂无
+    private Integer totalOriginalPrice;
     /**
      * 商品级优惠(总),单位:分
      *
      * 例如说“限时折扣”:商品原价的 8 折;商品原价的减 50 元
      */
-    private Integer totalPromotionPrice; // taobao - order.discount_fee(子订单商品优惠)
+    // taobao - order.discount_fee(子订单商品优惠)
+    private Integer totalPromotionPrice;
     /**
      * 最终购买金额(单),单位:分。
      *
@@ -109,12 +112,14 @@ public class TradeOrderItemDO extends BaseDO {
      * = {@link #totalOriginalPrice}
      * - {@link #totalPromotionPrice}
      */
-    private Integer totalPresentPrice; // like -  total_pay_price;niu - goods_money; taobao - order.payment(子订单实付金额,不算主订单分摊金额) | order.total_fee(子订单应付金额,参考使用)
+    // like -  total_pay_price;niu - goods_money; taobao - order.payment(子订单实付金额,不算主订单分摊金额) | order.total_fee(子订单应付金额,参考使用)
+    private Integer totalPresentPrice;
     // TODO 芋艿:part_mjz_discount(子订单分摊金额);本质上,totalOriginalPrice - totalPayPrice
     /**
      * 应付金额(总),单位:分
      */
-    private Integer totalPayPrice; // taobao - divide_order_fee (分摊后子订单实付金额);
+    // taobao - divide_order_fee (分摊后子订单实付金额);
+    private Integer totalPayPrice;
 
     // ========== 营销基本信息 ==========
 //    /**