Commit 5948be86a820ad729ac227fee5870c490012bdd7

Authored by YunaiV
1 parent 515c0de7

mall:新增价格计算的接口

yudao-module-mall/yudao-module-market-api/pom.xml
... ... @@ -21,6 +21,13 @@
21 21 <groupId>cn.iocoder.boot</groupId>
22 22 <artifactId>yudao-common</artifactId>
23 23 </dependency>
  24 +
  25 + <!-- 参数校验 -->
  26 + <dependency>
  27 + <groupId>org.springframework.boot</groupId>
  28 + <artifactId>spring-boot-starter-validation</artifactId>
  29 + <optional>true</optional>
  30 + </dependency>
24 31 </dependencies>
25 32  
26 33 </project>
... ...
yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/api/price/PriceApi.java 0 → 100644
  1 +package cn.iocoder.yudao.module.market.api.price;
  2 +
  3 +import cn.iocoder.yudao.module.market.api.price.dto.PriceCalculateReqDTO;
  4 +import cn.iocoder.yudao.module.market.api.price.dto.PriceCalculateRespDTO;
  5 +
  6 +/**
  7 + * 价格 API 接口
  8 + *
  9 + * @author 芋道源码
  10 + */
  11 +public interface PriceApi {
  12 +
  13 + /**
  14 + * 计算商品的价格
  15 + *
  16 + * @param calculateReqDTO 价格请求
  17 + * @return 价格相应
  18 + */
  19 + PriceCalculateRespDTO calculatePrice(PriceCalculateReqDTO calculateReqDTO);
  20 +
  21 +}
... ...
yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/api/price/dto/PriceCalculateReqDTO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.market.api.price.dto;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import javax.validation.constraints.Min;
  6 +import javax.validation.constraints.NotNull;
  7 +import java.util.List;
  8 +
  9 +/**
  10 + * 价格计算 Request DTO
  11 + *
  12 + * @author 芋道源码
  13 + */
  14 +@Data
  15 +public class PriceCalculateReqDTO {
  16 +
  17 + /**
  18 + * 用户编号
  19 + *
  20 + * 对应 MemberUserDO 的 id 编号
  21 + */
  22 + private Long userId;
  23 +
  24 + /**
  25 + * 优惠劵编号
  26 + */
  27 + private Long couponId;
  28 +
  29 + /**
  30 + * 商品 SKU 数组
  31 + */
  32 + @NotNull(message = "商品数组不能为空")
  33 + private List<Item> items;
  34 +
  35 + /**
  36 + * 商品 SKU
  37 + */
  38 + @Data
  39 + public static class Item {
  40 +
  41 + /**
  42 + * SKU 编号
  43 + */
  44 + @NotNull(message = "商品 SKU 编号不能为空")
  45 + private Long skuId;
  46 +
  47 + /**
  48 + * SKU 数量
  49 + */
  50 + @NotNull(message = "商品 SKU 数量不能为空")
  51 + @Min(value = 0L, message = "商品 SKU 数量必须大于等于 0") // 可传递 0 数量,用于购物车未选中的情况
  52 + private Integer count;
  53 +
  54 + }
  55 +
  56 +}
... ...
yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/api/price/dto/PriceCalculateRespDTO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.market.api.price.dto;
  2 +
  3 +import cn.iocoder.yudao.module.market.enums.common.PromotionLevelEnum;
  4 +import cn.iocoder.yudao.module.market.enums.common.PromotionTypeEnum;
  5 +import lombok.Data;
  6 +
  7 +import java.util.List;
  8 +
  9 +/**
  10 + * 价格计算 Response DTO
  11 + *
  12 + * @author 芋道源码
  13 + */
  14 +@Data
  15 +public class PriceCalculateRespDTO {
  16 +
  17 + /**
  18 + * 订单
  19 + */
  20 + private Order order;
  21 +
  22 + /**
  23 + * 商品 SKU 数组
  24 + */
  25 + private List<Item> items;
  26 +
  27 + /**
  28 + * 营销活动数组
  29 + *
  30 + * 只对应 {@link #items} 商品匹配的活动
  31 + */
  32 + private List<Promotion> promotions;
  33 +
  34 + /**
  35 + * 订单
  36 + */
  37 + @Data
  38 + public static class Order {
  39 +
  40 + /**
  41 + * 商品原价(总),单位:分
  42 + *
  43 + * 基于 {@link Item#getTotalOriginalPrice()} 求和
  44 + */
  45 + private Integer skuOriginalPrice;
  46 + /**
  47 + * 商品优惠(总),单位:分
  48 + *
  49 + * 基于 {@link Item#getTotalPromotionPrice()} 求和
  50 + */
  51 + private Integer skuPromotionPrice;
  52 + /**
  53 + * 订单优惠(总),单位:分
  54 + *
  55 + * 例如说:满减折扣;不包括优惠劵、商品优惠
  56 + */
  57 + private Integer orderPromotionPrice;
  58 + /**
  59 + * 运费金额,单位:分
  60 + */
  61 + private Integer deliveryPrice;
  62 + /**
  63 + * 应付金额(总),单位:分
  64 + *
  65 + * = {@link #skuOriginalPrice}
  66 + * + {@link #deliveryPrice}
  67 + * - {@link #skuPromotionPrice}
  68 + * - {@link #orderPromotionPrice}
  69 + * - {@link #couponPrice} // TODO 芋艿:需要再考虑一下它
  70 + */
  71 + private Integer payPrice;
  72 +
  73 + // ========== 营销基本信息 ==========
  74 + /**
  75 + * 优惠劵编号
  76 + */
  77 + private Long couponId;
  78 + /**
  79 + * 优惠劵减免金额,单位:分
  80 + */
  81 + private Integer couponPrice;
  82 +
  83 + }
  84 +
  85 + /**
  86 + * 商品 SKU
  87 + */
  88 + @Data
  89 + public static class Item extends PriceCalculateReqDTO.Item {
  90 +
  91 + /**
  92 + * 商品原价(单),单位:分
  93 + *
  94 + * 对应 ProductSkuDO 的 price 字段
  95 + */
  96 + private Integer originalPrice;
  97 + /**
  98 + * 商品原价(总),单位:分
  99 + *
  100 + * = {@link #originalPrice} * {@link #getCount()}
  101 + */
  102 + private Integer totalOriginalPrice;
  103 + /**
  104 + * 商品级优惠(总),单位:分
  105 + *
  106 + * 例如说“限时折扣”:商品原价的 8 折;商品原价的减 50 元
  107 + */
  108 + private Integer totalPromotionPrice;
  109 + /**
  110 + * 最终购买金额(总),单位:分。
  111 + *
  112 + * = {@link #totalOriginalPrice}
  113 + * - {@link #totalPromotionPrice}
  114 + */
  115 + private Integer totalPresentPrice;
  116 + /**
  117 + * 最终购买金额(单),单位:分。
  118 + *
  119 + * = {@link #totalPresentPrice} / {@link #getCount()}
  120 + */
  121 + private Integer presentPrice;
  122 + /**
  123 + * 应付金额(总),单位:分
  124 + */
  125 + private Integer totalPayPrice;
  126 +
  127 + }
  128 +
  129 + /**
  130 + * 营销活动
  131 + */
  132 + @Data
  133 + public static class Promotion {
  134 +
  135 + /**
  136 + * 营销编号
  137 + *
  138 + * 例如说:营销活动的编号、优惠劵的编号
  139 + */
  140 + private Long id;
  141 + /**
  142 + * 营销类型
  143 + *
  144 + * 枚举 {@link PromotionTypeEnum}
  145 + */
  146 + private Integer type;
  147 + /**
  148 + * 营销级别
  149 + *
  150 + * 枚举 {@link PromotionLevelEnum}
  151 + */
  152 + private Integer level;
  153 + /**
  154 + * 匹配的商品 SKU 数组
  155 + */
  156 + private List<Item> items;
  157 + /**
  158 + * 计算时的原价(总),单位:分
  159 + */
  160 + private Integer totalOriginalPrice;
  161 + /**
  162 + * 计算时的优惠(总),单位:分
  163 + */
  164 + private Integer totalPromotionPrice;
  165 + // TODO 芋艿:是否匹配,match ;不匹配的原因
  166 + // TODO 芋艿:描述
  167 +
  168 + /**
  169 + * 匹配的商品 SKU
  170 + */
  171 + @Data
  172 + public static class Item {
  173 +
  174 + /**
  175 + * 商品 SKU 编号
  176 + */
  177 + private Long skuId;
  178 + /**
  179 + * 计算时的原价(总),单位:分
  180 + */
  181 + private Integer totalOriginalPrice;
  182 + /**
  183 + * 计算时的优惠(总),单位:分
  184 + */
  185 + private Integer totalPromotionPrice;
  186 +
  187 + }
  188 +
  189 + }
  190 +
  191 +}
... ...
yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionLevelEnum.java 0 → 100644
  1 +package cn.iocoder.yudao.module.market.enums.common;
  2 +
  3 +import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Getter;
  6 +
  7 +import java.util.Arrays;
  8 +
  9 +/**
  10 + * 营销的级别枚举
  11 + *
  12 + * @author 芋道源码
  13 + */
  14 +@Getter
  15 +@AllArgsConstructor
  16 +public enum PromotionLevelEnum implements IntArrayValuable {
  17 +
  18 + ORDER(1, "订单级"),
  19 + SKU(2, "商品级"),
  20 + ;
  21 +
  22 + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionLevelEnum::getLevel).toArray();
  23 +
  24 + /**
  25 + * 级别值
  26 + */
  27 + private final Integer level;
  28 + /**
  29 + * 类型名
  30 + */
  31 + private final String name;
  32 +
  33 + @Override
  34 + public int[] array() {
  35 + return ARRAYS;
  36 + }
  37 +}
... ...
yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/activity/MarketActivityTypeEnum.java renamed to yudao-module-mall/yudao-module-market-api/src/main/java/cn/iocoder/yudao/module/market/enums/common/PromotionTypeEnum.java
1   -package cn.iocoder.yudao.module.market.enums.activity;
  1 +package cn.iocoder.yudao.module.market.enums.common;
2 2  
3 3 import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Getter;
4 6  
5 7 import java.util.Arrays;
6 8  
7 9 /**
8   - * 促销活动类型枚举
  10 + * 营销类型枚举
  11 + *
  12 + * @author 芋道源码
9 13 */
10   -public enum MarketActivityTypeEnum implements IntArrayValuable {
  14 +@Getter
  15 +@AllArgsConstructor
  16 +public enum PromotionTypeEnum implements IntArrayValuable {
11 17  
12 18 TIME_LIMITED_DISCOUNT(1, "限时折扣"),
13 19 FULL_PRIVILEGE(2, "满减送"),
14 20 ;
15 21  
16   - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(MarketActivityTypeEnum::getValue).toArray();
  22 + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionTypeEnum::getType).toArray();
17 23  
18 24 /**
19 25 * 类型值
20 26 */
21   - private final Integer value;
  27 + private final Integer type;
22 28 /**
23 29 * 类型名
24 30 */
25 31 private final String name;
26 32  
27   - MarketActivityTypeEnum(Integer value, String name) {
28   - this.value = value;
29   - this.name = name;
30   - }
31   -
32   - public Integer getValue() {
33   - return value;
34   - }
35   -
36   - public String getName() {
37   - return name;
38   - }
39   -
40 33 @Override
41 34 public int[] array() {
42 35 return ARRAYS;
... ...
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;
2 2  
3 3 import cn.iocoder.yudao.framework.common.validation.InEnum;
4 4 import cn.iocoder.yudao.module.market.enums.activity.MarketActivityStatusEnum;
5   -import cn.iocoder.yudao.module.market.enums.activity.MarketActivityTypeEnum;
  5 +import cn.iocoder.yudao.module.market.enums.common.PromotionTypeEnum;
6 6 import lombok.*;
7 7 import java.util.*;
8 8 import io.swagger.annotations.*;
... ... @@ -24,7 +24,7 @@ public class ActivityBaseVO {
24 24  
25 25 @ApiModelProperty(value = "活动类型", required = true)
26 26 @NotNull(message = "活动类型不能为空")
27   - @InEnum(MarketActivityTypeEnum.class)
  27 + @InEnum(PromotionTypeEnum.class)
28 28 private Integer activityType;
29 29  
30 30 @ApiModelProperty(value = "活动状态", required = true)
... ...
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;
2 2  
3 3 import cn.iocoder.yudao.framework.common.validation.InEnum;
4 4 import cn.iocoder.yudao.module.market.enums.activity.MarketActivityStatusEnum;
5   -import cn.iocoder.yudao.module.market.enums.activity.MarketActivityTypeEnum;
  5 +import cn.iocoder.yudao.module.market.enums.common.PromotionTypeEnum;
6 6 import lombok.*;
7 7 import java.util.*;
8 8 import io.swagger.annotations.*;
... ... @@ -21,7 +21,7 @@ public class ActivityPageReqVO extends PageParam {
21 21 private String title;
22 22  
23 23 @ApiModelProperty(value = "活动类型")
24   - @InEnum(MarketActivityTypeEnum.class)
  24 + @InEnum(PromotionTypeEnum.class)
25 25 private Integer activityType;
26 26  
27 27 @ApiModelProperty(value = "活动状态")
... ...
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 {
110 110  
111 111 // ========== 价格 + 支付基本信息 ==========
112 112 // 价格文档 - 淘宝:https://open.taobao.com/docV3.htm?docId=108471&docType=1
  113 + // 价格文档 - 京东到家:https://openo2o.jddj.com/api/getApiDetail/182/4d1494c5e7ac4679bfdaaed950c5bc7f.htm
  114 + // 价格文档 - 有赞:https://doc.youzanyun.com/detail/API/0/906
113 115  
114 116 // TODO promotion_details(订单优惠信息明细,商品和订单级优惠一般都在里面)
115 117  
... ... @@ -118,7 +120,8 @@ public class TradeOrderDO extends BaseDO {
118 120 *
119 121 * 基于 {@link TradeOrderItemDO#getTotalOriginalPrice()} 求和
120 122 */
121   - private Integer skuOriginalPrice; // niu - goods_money;
  123 + // niu - goods_money;
  124 + private Integer skuOriginalPrice;
122 125 /**
123 126 * 商品优惠(总),单位:分
124 127 *
... ... @@ -130,11 +133,13 @@ public class TradeOrderDO extends BaseDO {
130 133 *
131 134 * 例如说:满减折扣;不包括优惠劵、商品优惠
132 135 */
133   - private Integer orderPromotionPrice; // niu - promotion_money;taobao - discount_fee(主订单优惠)
  136 + // niu - promotion_money;taobao - discount_fee(主订单优惠)
  137 + private Integer orderPromotionPrice;
134 138 /**
135 139 * 运费金额,单位:分
136 140 */
137   - private Integer deliveryPrice; // niu - delivery_money;taobao - post_fee(订单邮费)
  141 + // niu - delivery_money;taobao - post_fee(订单邮费)
  142 + private Integer deliveryPrice;
138 143 // TODO 芋艿:taobao 的:trade.adjust_fee/order.adjust_fee(调整金额,如:卖家手动修改订单价格,官方数据修复等等)
139 144 /**
140 145 * 应付金额(总),单位:分
... ... @@ -145,7 +150,8 @@ public class TradeOrderDO extends BaseDO {
145 150 * - {@link #orderPromotionPrice}
146 151 * - {@link #couponPrice}
147 152 */
148   - private Integer payPrice; // niu - pay_money;taobao - payment(主订单实付金额) | trade.total_fee(主订单应付金额,参考使用);
  153 + // niu - pay_money;taobao - payment(主订单实付金额) | trade.total_fee(主订单应付金额,参考使用);
  154 + private Integer payPrice;
149 155 /**
150 156 * 支付订单编号
151 157 *
... ... @@ -244,7 +250,8 @@ public class TradeOrderDO extends BaseDO {
244 250 /**
245 251 * 优惠劵减免金额,单位:分
246 252 */
247   - private Integer couponPrice; // niu - coupon_money;
  253 + // niu - coupon_money;
  254 + private Integer couponPrice;
248 255 // /**
249 256 // * 积分抵扣的金额,单位:分
250 257 // */
... ...
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 {
84 84 *
85 85 * 对应 ProductSkuDO 的 price 字段
86 86 */
87   - private Integer originalPrice; // like - original_price;niu - costPrice
  87 + // like - original_price;niu - costPrice
  88 + private Integer originalPrice;
88 89 /**
89 90 * 商品原价(总),单位:分
90 91 *
91 92 * = {@link #originalPrice} * {@link #count}
92 93 */
93   - private Integer totalOriginalPrice; // like - total_price;niu - 暂无
  94 + // like - total_price;niu - 暂无
  95 + private Integer totalOriginalPrice;
94 96 /**
95 97 * 商品级优惠(总),单位:分
96 98 *
97 99 * 例如说“限时折扣”:商品原价的 8 折;商品原价的减 50 元
98 100 */
99   - private Integer totalPromotionPrice; // taobao - order.discount_fee(子订单商品优惠)
  101 + // taobao - order.discount_fee(子订单商品优惠)
  102 + private Integer totalPromotionPrice;
100 103 /**
101 104 * 最终购买金额(单),单位:分。
102 105 *
... ... @@ -109,12 +112,14 @@ public class TradeOrderItemDO extends BaseDO {
109 112 * = {@link #totalOriginalPrice}
110 113 * - {@link #totalPromotionPrice}
111 114 */
112   - private Integer totalPresentPrice; // like - total_pay_price;niu - goods_money; taobao - order.payment(子订单实付金额,不算主订单分摊金额) | order.total_fee(子订单应付金额,参考使用)
  115 + // like - total_pay_price;niu - goods_money; taobao - order.payment(子订单实付金额,不算主订单分摊金额) | order.total_fee(子订单应付金额,参考使用)
  116 + private Integer totalPresentPrice;
113 117 // TODO 芋艿:part_mjz_discount(子订单分摊金额);本质上,totalOriginalPrice - totalPayPrice
114 118 /**
115 119 * 应付金额(总),单位:分
116 120 */
117   - private Integer totalPayPrice; // taobao - divide_order_fee (分摊后子订单实付金额);
  121 + // taobao - divide_order_fee (分摊后子订单实付金额);
  122 + private Integer totalPayPrice;
118 123  
119 124 // ========== 营销基本信息 ==========
120 125 // /**
... ...