Commit 054569a3d392e51c41f0323c6bcd57710f3fa8be

Authored by YunaiV
1 parent a778c250

promotion:去除已经不使用的代码

Showing 18 changed files with 4 additions and 755 deletions
yudao-module-mall/yudao-module-promotion-api/pom.xml
... ... @@ -13,7 +13,7 @@
13 13  
14 14 <name>${project.artifactId}</name>
15 15 <description>
16   - market 模块 API,暴露给其它模块调用
  16 + promotion 模块 API,暴露给其它模块调用
17 17 </description>
18 18  
19 19 <dependencies>
... ...
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationActivityApi.java deleted
1   -package cn.iocoder.yudao.module.promotion.api.combination;
2   -
3   -/**
4   - * 拼团活动 Api 接口
5   - *
6   - * @author HUIHUI
7   - */
8   -public interface CombinationActivityApi {
9   -
10   -}
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java
... ... @@ -42,14 +42,6 @@ public interface CombinationRecordApi {
42 42 boolean isCombinationRecordSuccess(Long userId, Long orderId);
43 43  
44 44 /**
45   - * 更新拼团状态为【失败】
46   - *
47   - * @param userId 用户编号
48   - * @param orderId 订单编号
49   - */
50   - void updateRecordStatusToFailed(Long userId, Long orderId);
51   -
52   - /**
53 45 * 【下单前】校验是否满足拼团活动条件
54 46 *
55 47 * 如果校验失败,则抛出业务异常
... ...
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/price/PriceApi.java deleted
1   -package cn.iocoder.yudao.module.promotion.api.price;
2   -
3   -import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO;
4   -import cn.iocoder.yudao.module.promotion.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-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/price/dto/CouponMeetRespDTO.java deleted
1   -package cn.iocoder.yudao.module.promotion.api.price.dto;
2   -
3   -import lombok.Data;
4   -
5   -/**
6   - * 优惠劵的匹配信息 Response DTO
7   - *
8   - * why 放在 price 包下?主要获取的时候,需要涉及到较多的价格计算逻辑,放在 price 可以更好的复用逻辑
9   - *
10   - * @author 芋道源码
11   - */
12   -@Data
13   -public class CouponMeetRespDTO {
14   -
15   - /**
16   - * 优惠劵编号
17   - */
18   - private Long id;
19   -
20   - // ========== 非优惠劵的基本信息字段 ==========
21   - /**
22   - * 是否匹配
23   - */
24   - private Boolean meet;
25   - /**
26   - * 不匹配的提示,即 {@link #meet} = true 才有值
27   - *
28   - * 例如说:
29   - * 1. 所结算商品没有符合条件的商品
30   - * 2. 差 XXX 元可用优惠劵
31   - * 3. 优惠劵未到使用时间
32   - */
33   - private String meetTip;
34   -
35   -}
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/price/dto/PriceCalculateReqDTO.java deleted
1   -package cn.iocoder.yudao.module.promotion.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   -@Deprecated
16   -public class PriceCalculateReqDTO {
17   -
18   - /**
19   - * 用户编号
20   - *
21   - * 对应 MemberUserDO 的 id 编号
22   - */
23   - private Long userId;
24   -
25   - /**
26   - * 优惠劵编号
27   - */
28   - private Long couponId;
29   -
30   - /**
31   - * 收货地址编号
32   - */
33   - private Long addressId;
34   -
35   - /**
36   - * 商品 SKU 数组
37   - */
38   - @NotNull(message = "商品数组不能为空")
39   - private List<Item> items;
40   -
41   - /**
42   - * 商品 SKU
43   - */
44   - @Data
45   - public static class Item {
46   -
47   - /**
48   - * SKU 编号
49   - */
50   - @NotNull(message = "商品 SKU 编号不能为空")
51   - private Long skuId;
52   -
53   - /**
54   - * SKU 数量
55   - */
56   - @NotNull(message = "商品 SKU 数量不能为空")
57   - @Min(value = 0L, message = "商品 SKU 数量必须大于等于 0") // 可传递 0 数量,用于购物车未选中的情况
58   - private Integer count;
59   -
60   - }
61   -
62   -}
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/price/dto/PriceCalculateRespDTO.java deleted
1   -package cn.iocoder.yudao.module.promotion.api.price.dto;
2   -
3   -import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
4   -import lombok.Data;
5   -
6   -import java.util.List;
7   -
8   -/**
9   - * 价格计算 Response DTO
10   - *
11   - * 整体设计,参考 taobao 的技术文档:
12   - * 1. <a href="https://developer.alibaba.com/docs/doc.htm?treeId=1&articleId=1029&docType=1">订单管理</a>
13   - * 2. <a href="https://open.taobao.com/docV3.htm?docId=108471&docType=1">常用订单金额说明</a>
14   - *
15   - * 举个例子:<a href="https://img.alicdn.com/top/i1/LB1mALAi4HI8KJjy1zbXXaxdpXa">订单图</a>
16   - * 输入:
17   - * 1. 订单实付: trade.payment = 198.00;订单邮费:5 元;
18   - * 2. 商品级优惠 圣诞价: 省 29.00 元 和 圣诞价:省 150.00 元; 订单级优惠,圣诞 2:省 5.00 元;
19   - * 分摊:
20   - * 1. 商品 1:原价 108 元,优惠 29 元,子订单实付 79 元,分摊主订单优惠 1.99 元;
21   - * 2. 商品 2:原价 269 元,优惠 150 元,子订单实付 119 元,分摊主订单优惠 3.01 元;
22   - *
23   - * @author 芋道源码
24   - */
25   -@Data
26   -@Deprecated
27   -public class PriceCalculateRespDTO {
28   -
29   - /**
30   - * 订单
31   - */
32   - private Order order;
33   -
34   - /**
35   - * 营销活动数组
36   - *
37   - * 只对应 {@link Order#items} 商品匹配的活动
38   - */
39   - private List<Promotion> promotions;
40   -
41   - // TODO @芋艿:需要改造下,主要是价格字段
42   - /**
43   - * 订单
44   - */
45   - @Data
46   - public static class Order {
47   -
48   - /**
49   - * 商品原价(总),单位:分
50   - *
51   - * 基于 {@link OrderItem#getOriginalPrice()} 求和
52   - *
53   - * 对应 taobao 的 trade.total_fee 字段
54   - */
55   - private Integer totalPrice;
56   - /**
57   - * 订单优惠(总),单位:分
58   - *
59   - * 订单级优惠:对主订单的优惠,常见如:订单满 200 元减 10 元;订单满 80 包邮。
60   - *
61   - * 对应 taobao 的 order.discount_fee 字段
62   - */
63   - private Integer discountPrice;
64   - /**
65   - * 优惠劵减免金额(总),单位:分
66   - *
67   - * 对应 taobao 的 trade.coupon_fee 字段
68   - */
69   - private Integer couponPrice;
70   - /**
71   - * 积分减免金额(总),单位:分
72   - *
73   - * 对应 taobao 的 trade.point_fee 字段
74   - */
75   - private Integer pointPrice;
76   - /**
77   - * 运费金额,单位:分
78   - */
79   - private Integer deliveryPrice;
80   - /**
81   - * 最终购买金额(总),单位:分
82   - *
83   - * = {@link OrderItem#getPayPrice()} 求和
84   - * - {@link #couponPrice}
85   - * - {@link #pointPrice}
86   - * + {@link #deliveryPrice}
87   - * - {@link #discountPrice}
88   - */
89   - private Integer payPrice;
90   - /**
91   - * 商品 SKU 数组
92   - */
93   - private List<OrderItem> items;
94   -
95   - // ========== 营销基本信息 ==========
96   - /**
97   - * 优惠劵编号
98   - */
99   - private Long couponId;
100   -
101   - }
102   -
103   - /**
104   - * 订单商品 SKU
105   - */
106   - @Data
107   - public static class OrderItem {
108   -
109   - /**
110   - * SPU 编号
111   - */
112   - private Long spuId;
113   - /**
114   - * SKU 编号
115   - */
116   - private Long skuId;
117   - /**
118   - * 购买数量
119   - */
120   - private Integer count;
121   -
122   - /**
123   - * 商品原价(总),单位:分
124   - *
125   - * = {@link #originalUnitPrice} * {@link #getCount()}
126   - */
127   - private Integer originalPrice;
128   - /**
129   - * 商品原价(单),单位:分
130   - *
131   - * 对应 ProductSkuDO 的 price 字段
132   - * 对应 taobao 的 order.price 字段
133   - */
134   - private Integer originalUnitPrice;
135   - /**
136   - * 商品优惠(总),单位:分
137   - *
138   - * 商品级优惠:对单个商品的,常见如:商品原价的 8 折;商品原价的减 50 元
139   - *
140   - * 对应 taobao 的 order.discount_fee 字段
141   - */
142   - private Integer discountPrice;
143   - /**
144   - * 子订单实付金额,不算主订单分摊金额,单位:分
145   - *
146   - * = {@link #originalPrice}
147   - * - {@link #discountPrice}
148   - *
149   - * 对应 taobao 的 order.payment 字段
150   - */
151   - private Integer payPrice;
152   -
153   - /**
154   - * 子订单分摊金额(总),单位:分
155   - * 需要分摊 {@link Order#discountPrice}、{@link Order#couponPrice}、{@link Order#pointPrice}
156   - *
157   - * 对应 taobao 的 order.part_mjz_discount 字段
158   - * 淘宝说明:子订单分摊优惠基础逻辑:一般正常优惠券和满减优惠按照子订单的金额进行分摊,特殊情况如果优惠券是指定商品使用的,只会分摊到对应商品子订单上不分摊。
159   - */
160   - private Integer orderPartPrice;
161   - /**
162   - * 分摊后子订单实付金额(总),单位:分
163   - *
164   - * = {@link #payPrice}
165   - * - {@link #orderPartPrice}
166   - *
167   - * 对应 taobao 的 divide_order_fee 字段
168   - */
169   - private Integer orderDividePrice;
170   -
171   - }
172   -
173   - /**
174   - * 营销明细
175   - */
176   - @Data
177   - @Deprecated
178   - public static class Promotion {
179   -
180   - /**
181   - * 营销编号
182   - *
183   - * 例如说:营销活动的编号、优惠劵的编号
184   - */
185   - private Long id;
186   - /**
187   - * 营销名字
188   - */
189   - private String name;
190   - /**
191   - * 营销类型
192   - *
193   - * 枚举 {@link PromotionTypeEnum}
194   - */
195   - private Integer type;
196   - /**
197   - * 营销级别
198   - *
199   - * 枚举 @link PromotionLevelEnum} TODO PromotionLevelEnum 没有这个枚举类
200   - */
201   - private Integer level;
202   - /**
203   - * 计算时的原价(总),单位:分
204   - */
205   - private Integer totalPrice;
206   - /**
207   - * 计算时的优惠(总),单位:分
208   - */
209   - private Integer discountPrice;
210   - /**
211   - * 匹配的商品 SKU 数组
212   - */
213   - private List<PromotionItem> items;
214   -
215   - // ========== 匹配情况 ==========
216   -
217   - /**
218   - * 是否满足优惠条件
219   - */
220   - private Boolean match;
221   - /**
222   - * 满足条件的提示
223   - *
224   - * 如果 {@link #match} = true 满足,则提示“圣诞价:省 150.00 元”
225   - * 如果 {@link #match} = false 不满足,则提示“购满 85 元,可减 40 元”
226   - */
227   - private String description;
228   -
229   - }
230   -
231   - /**
232   - * 营销匹配的商品 SKU
233   - */
234   - @Data
235   - public static class PromotionItem {
236   -
237   - /**
238   - * 商品 SKU 编号
239   - */
240   - private Long skuId;
241   - /**
242   - * 计算时的原价(总),单位:分
243   - */
244   - private Integer originalPrice;
245   - /**
246   - * 计算时的优惠(总),单位:分
247   - */
248   - private Integer discountPrice;
249   -
250   - }
251   -
252   -}
yudao-module-mall/yudao-module-promotion-biz/pom.xml
... ... @@ -14,8 +14,8 @@
14 14 <name>${project.artifactId}</name>
15 15  
16 16 <description>
17   - market模块,主要实现营销相关功能
18   - 例如:营销活动、banner广告、优惠券、优惠码等功能。
  17 + promotion 模块,主要实现营销相关功能
  18 + 例如:营销活动、banner 广告、优惠券、优惠码等功能。
19 19 </description>
20 20  
21 21 <dependencies>
... ... @@ -49,10 +49,6 @@
49 49 <groupId>cn.iocoder.boot</groupId>
50 50 <artifactId>yudao-spring-boot-starter-biz-tenant</artifactId>
51 51 </dependency>
52   - <dependency>
53   - <groupId>cn.iocoder.boot</groupId>
54   - <artifactId>yudao-spring-boot-starter-biz-weixin</artifactId>
55   - </dependency>
56 52  
57 53 <!-- Web 相关 -->
58 54 <dependency>
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationActivityApiImpl.java deleted
1   -package cn.iocoder.yudao.module.promotion.api.combination;
2   -
3   -import org.springframework.stereotype.Service;
4   -
5   -/**
6   - * 拼团活动 Api 接口实现类
7   - *
8   - * @author HUIHUI
9   - */
10   -@Service
11   -public class CombinationActivityApiImpl implements CombinationActivityApi {
12   -
13   -}
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java
... ... @@ -45,11 +45,6 @@ public class CombinationRecordApiImpl implements CombinationRecordApi {
45 45 }
46 46  
47 47 @Override
48   - public void updateRecordStatusToFailed(Long userId, Long orderId) {
49   - recordService.updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordStatusEnum.FAILED.getStatus(), userId, orderId);
50   - }
51   -
52   - @Override
53 48 public CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count) {
54 49 return recordService.validateJoinCombination(userId, activityId, headId, skuId, count);
55 50 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/price/PriceApiImpl.java deleted
1   -package cn.iocoder.yudao.module.promotion.api.price;
2   -
3   -import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO;
4   -import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateRespDTO;
5   -import cn.iocoder.yudao.module.promotion.service.price.PriceService;
6   -import org.springframework.stereotype.Service;
7   -
8   -import javax.annotation.Resource;
9   -
10   -/**
11   - * 价格 API 实现类
12   - *
13   - * @author 芋道源码
14   - */
15   -@Service
16   -public class PriceApiImpl implements PriceApi {
17   -
18   - @Resource
19   - private PriceService priceService;
20   -
21   - @Override
22   - public PriceCalculateRespDTO calculatePrice(PriceCalculateReqDTO calculateReqDTO) {
23   - //return priceService.calculatePrice(calculateReqDTO); TODO 没有 calculatePrice 这个方法
24   -
25   - return null;
26   - }
27   -
28   -}
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/price/PriceConvert.java deleted
1   -package cn.iocoder.yudao.module.promotion.convert.price;
2   -
3   -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
4   -import cn.iocoder.yudao.module.promotion.api.price.dto.CouponMeetRespDTO;
5   -import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO;
6   -import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateRespDTO;
7   -import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
8   -import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO;
9   -import org.mapstruct.Mapper;
10   -import org.mapstruct.factory.Mappers;
11   -
12   -import java.util.ArrayList;
13   -import java.util.List;
14   -import java.util.Map;
15   -
16   -@Mapper
17   -public interface PriceConvert {
18   -
19   - PriceConvert INSTANCE = Mappers.getMapper(PriceConvert.class);
20   -
21   - default PriceCalculateRespDTO convert(PriceCalculateReqDTO calculateReqDTO, List<ProductSkuRespDTO> skuList) {
22   - // 创建 PriceCalculateRespDTO 对象
23   - PriceCalculateRespDTO priceCalculate = new PriceCalculateRespDTO();
24   - // 创建它的 Order 属性
25   - PriceCalculateRespDTO.Order order = new PriceCalculateRespDTO.Order().setTotalPrice(0).setDiscountPrice(0)
26   - .setCouponPrice(0).setPointPrice(0).setDeliveryPrice(0).setPayPrice(0)
27   - .setItems(new ArrayList<>()).setCouponId(calculateReqDTO.getCouponId());
28   - priceCalculate.setOrder(order).setPromotions(new ArrayList<>());
29   - // 创建它的 OrderItem 属性
30   - Map<Long, Integer> skuIdCountMap = CollectionUtils.convertMap(calculateReqDTO.getItems(),
31   - PriceCalculateReqDTO.Item::getSkuId, PriceCalculateReqDTO.Item::getCount);
32   - skuList.forEach(sku -> {
33   - Integer count = skuIdCountMap.get(sku.getId());
34   - PriceCalculateRespDTO.OrderItem orderItem = new PriceCalculateRespDTO.OrderItem()
35   - .setSpuId(sku.getSpuId()).setSkuId(sku.getId()).setCount(count)
36   - .setOriginalUnitPrice(sku.getPrice()).setOriginalPrice(sku.getPrice() * count)
37   - .setDiscountPrice(0).setOrderPartPrice(0);
38   - orderItem.setPayPrice(orderItem.getOriginalPrice()).setOrderDividePrice(orderItem.getOriginalPrice());
39   - priceCalculate.getOrder().getItems().add(orderItem);
40   - // 补充价格信息到 Order 中
41   - order.setTotalPrice(order.getTotalPrice() + orderItem.getOriginalPrice())
42   - .setPayPrice(order.getTotalPrice());
43   - });
44   - return priceCalculate;
45   - }
46   -
47   - CouponMeetRespDTO convert(CouponDO coupon);
48   -
49   -}
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java
... ... @@ -22,15 +22,6 @@ import java.util.Map;
22 22 public interface CombinationRecordService {
23 23  
24 24 /**
25   - * 更新拼团状态
26   - *
27   - * @param status 状态
28   - * @param userId 用户编号
29   - * @param orderId 订单编号
30   - */
31   - void updateCombinationRecordStatusByUserIdAndOrderId(Integer status, Long userId, Long orderId);
32   -
33   - /**
34 25 * 【下单前】校验是否满足拼团活动条件
35 26 *
36 27 * 如果校验失败,则抛出业务异常
... ... @@ -63,15 +54,6 @@ public interface CombinationRecordService {
63 54 CombinationRecordDO getCombinationRecord(Long userId, Long orderId);
64 55  
65 56 /**
66   - * 获取拼团记录
67   - *
68   - * @param userId 用户 id
69   - * @param activityId 活动 id
70   - * @return 拼团记录列表
71   - */
72   - List<CombinationRecordDO> getCombinationRecordListByUserIdAndActivityId(Long userId, Long activityId);
73   -
74   - /**
75 57 * 【下单前】校验是否满足拼团活动条件
76 58 *
77 59 * 如果校验失败,则抛出业务异常
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
... ... @@ -66,25 +66,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
66 66 @Resource
67 67 private TradeOrderApi tradeOrderApi;
68 68  
69   - @Override
70   - @Transactional(rollbackFor = Exception.class)
71   - public void updateCombinationRecordStatusByUserIdAndOrderId(Integer status, Long userId, Long orderId) {
72   - // 校验拼团是否存在
73   - CombinationRecordDO record = validateCombinationRecord(userId, orderId);
74   -
75   - // 更新状态
76   - combinationRecordMapper.updateById(new CombinationRecordDO().setId(record.getId()).setStatus(status));
77   - }
78   -
79   - private CombinationRecordDO validateCombinationRecord(Long userId, Long orderId) {
80   - // 校验拼团是否存在
81   - CombinationRecordDO recordDO = combinationRecordMapper.selectByUserIdAndOrderId(userId, orderId);
82   - if (recordDO == null) {
83   - throw exception(COMBINATION_RECORD_NOT_EXISTS);
84   - }
85   - return recordDO;
86   - }
87   -
88 69 // TODO @芋艿:在详细预览下;
89 70 @Override
90 71 public KeyValue<CombinationActivityDO, CombinationProductDO> validateCombinationRecord(
... ... @@ -230,11 +211,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
230 211 }
231 212  
232 213 @Override
233   - public List<CombinationRecordDO> getCombinationRecordListByUserIdAndActivityId(Long userId, Long activityId) {
234   - return combinationRecordMapper.selectListByUserIdAndActivityId(userId, activityId);
235   - }
236   -
237   - @Override
238 214 public CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId,
239 215 Long skuId, Integer count) {
240 216 KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord(userId, activityId,
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/price/PriceService.java deleted
1   -package cn.iocoder.yudao.module.promotion.service.price;
2   -
3   -import cn.iocoder.yudao.module.promotion.api.price.dto.CouponMeetRespDTO;
4   -import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO;
5   -
6   -import java.util.List;
7   -
8   -/**
9   - * 价格计算 Service 接口
10   - *
11   - * @author 芋道源码
12   - */
13   -public interface PriceService {
14   -
15   - /**
16   - * 获得优惠劵的匹配信息列表
17   - *
18   - * @param calculateReqDTO 价格请求
19   - * @return 价格响应
20   - */
21   - List<CouponMeetRespDTO> getMeetCouponList(PriceCalculateReqDTO calculateReqDTO);
22   -
23   -}
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/price/PriceServiceImpl.java deleted
1   -package cn.iocoder.yudao.module.promotion.service.price;
2   -
3   -import cn.hutool.core.collection.CollUtil;
4   -import cn.iocoder.yudao.framework.common.exception.ServiceException;
5   -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
6   -import cn.iocoder.yudao.module.promotion.api.price.dto.CouponMeetRespDTO;
7   -import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO;
8   -import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateRespDTO;
9   -import cn.iocoder.yudao.module.promotion.convert.price.PriceConvert;
10   -import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO;
11   -import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum;
12   -import cn.iocoder.yudao.module.promotion.service.coupon.CouponService;
13   -import lombok.extern.slf4j.Slf4j;
14   -import org.springframework.stereotype.Service;
15   -import org.springframework.validation.annotation.Validated;
16   -
17   -import javax.annotation.Resource;
18   -import java.util.Collections;
19   -import java.util.List;
20   -
21   -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue;
22   -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COUPON_VALID_TIME_NOT_NOW;
23   -
24   -/**
25   - * 价格计算 Service 实现类
26   - *
27   - * 优惠计算顺序:min(限时折扣, 会员折扣) > 满减送 > 优惠券。
28   - * 参考文档:
29   - * 1. <a href="https://help.youzan.com/displaylist/detail_4_4-1-60384">有赞文档:限时折扣、满减送、优惠券哪个优先计算?</a>
30   - *
31   - * TODO 芋艿:进一步完善
32   - * 1. 限时折扣:指定金额、减免金额、折扣
33   - * 2. 满减送:循环、折扣
34   - * 3. 优惠劵:待定
35   - *
36   - * @author 芋道源码
37   - */
38   -@Service
39   -@Validated
40   -@Slf4j
41   -public class PriceServiceImpl implements PriceService {
42   -
43   - @Resource
44   - private CouponService couponService;
45   -
46   - @Override
47   - public List<CouponMeetRespDTO> getMeetCouponList(PriceCalculateReqDTO calculateReqDTO) {
48   - // 先计算一轮价格
49   -// PriceCalculateRespDTO priceCalculate = calculatePrice(calculateReqDTO);
50   - PriceCalculateRespDTO priceCalculate = null;
51   -
52   - // 获得用户的待使用优惠劵
53   - List<CouponDO> couponList = couponService.getCouponList(calculateReqDTO.getUserId(), CouponStatusEnum.UNUSED.getStatus());
54   - if (CollUtil.isEmpty(couponList)) {
55   - return Collections.emptyList();
56   - }
57   -
58   - // 获得优惠劵的匹配信息
59   - return CollectionUtils.convertList(couponList, coupon -> {
60   - CouponMeetRespDTO couponMeetRespDTO = PriceConvert.INSTANCE.convert(coupon);
61   - try {
62   - // 校验优惠劵
63   - couponService.validCoupon(coupon);
64   -
65   - // 获得匹配的商品 SKU 数组
66   - // TODO 芋艿:后续处理
67   -// List<PriceCalculateRespDTO.OrderItem> orderItems = getMatchCouponOrderItems(priceCalculate, coupon);
68   - List<PriceCalculateRespDTO.OrderItem> orderItems = null;
69   - if (CollUtil.isEmpty(orderItems)) {
70   - return couponMeetRespDTO.setMeet(false).setMeetTip("所结算商品没有符合条件的商品");
71   - }
72   -
73   - // 计算是否满足优惠劵的使用金额
74   - Integer originPrice = getSumValue(orderItems, PriceCalculateRespDTO.OrderItem::getOrderDividePrice, Integer::sum);
75   - assert originPrice != null;
76   - if (originPrice < coupon.getUsePrice()) {
77   - return couponMeetRespDTO.setMeet(false)
78   -// .setMeetTip(String.format("差 %s 元可用优惠劵", formatPrice(coupon.getUsePrice() - originPrice)));
79   - .setMeetTip("所结算的商品中未满足使用的金额");
80   - }
81   - } catch (ServiceException serviceException) {
82   - couponMeetRespDTO.setMeet(false);
83   - if (serviceException.getCode().equals(COUPON_VALID_TIME_NOT_NOW.getCode())) {
84   - couponMeetRespDTO.setMeetTip("优惠劵未到使用时间");
85   - } else {
86   - log.error("[getMeetCouponList][calculateReqDTO({}) 获得优惠劵匹配信息异常]", calculateReqDTO, serviceException);
87   - couponMeetRespDTO.setMeetTip("优惠劵不满足使用条件");
88   - }
89   - return couponMeetRespDTO;
90   - }
91   - // 满足
92   - return couponMeetRespDTO.setMeet(true);
93   - });
94   - }
95   -
96   -}
yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/price/PriceServiceTest.java deleted
1   -package cn.iocoder.yudao.module.promotion.service.price;
2   -
3   -import cn.iocoder.yudao.framework.common.exception.ServiceException;
4   -import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest;
5   -import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi;
6   -import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
7   -import cn.iocoder.yudao.module.promotion.api.price.dto.CouponMeetRespDTO;
8   -import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO;
9   -import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO;
10   -import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum;
11   -import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum;
12   -import cn.iocoder.yudao.module.promotion.service.coupon.CouponService;
13   -import cn.iocoder.yudao.module.promotion.service.reward.RewardActivityService;
14   -import org.junit.jupiter.api.Test;
15   -import org.mockito.InjectMocks;
16   -import org.mockito.Mock;
17   -
18   -import java.util.List;
19   -
20   -import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet;
21   -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
22   -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
23   -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COUPON_VALID_TIME_NOT_NOW;
24   -import static java.util.Arrays.asList;
25   -import static java.util.Collections.singletonList;
26   -import static org.junit.jupiter.api.Assertions.*;
27   -import static org.mockito.ArgumentMatchers.eq;
28   -import static org.mockito.Mockito.doThrow;
29   -import static org.mockito.Mockito.when;
30   -
31   -/**
32   - * {@link PriceServiceImpl} 的单元测试
33   - *
34   - * @author 芋道源码
35   - */
36   -public class PriceServiceTest extends BaseMockitoUnitTest {
37   -
38   - @InjectMocks
39   - private PriceServiceImpl priceService;
40   -
41   - @Mock
42   - private RewardActivityService rewardActivityService;
43   - @Mock
44   - private CouponService couponService;
45   - @Mock
46   - private ProductSkuApi productSkuApi;
47   -
48   - /**
49   - * 测试满减送活动,不匹配的情况
50   - */
51   - @Test
52   - public void testCalculatePrice_rewardActivityNotMeet() {
53   -
54   - }
55   -
56   - @Test
57   - public void testGetMeetCouponList() {
58   - // 准备参数
59   - PriceCalculateReqDTO calculateReqDTO = new PriceCalculateReqDTO().setUserId(1024L)
60   - .setItems(singletonList(new PriceCalculateReqDTO.Item().setSkuId(10L).setCount(2)));
61   - // mock 方法(商品 SKU 信息)
62   - ProductSkuRespDTO productSku = randomPojo(ProductSkuRespDTO.class, o -> o.setId(10L).setPrice(100));
63   - when(productSkuApi.getSkuList(eq(asSet(10L)))).thenReturn(singletonList(productSku));
64   - // mock 方法(情况一:优惠劵未到使用时间)
65   - CouponDO coupon01 = randomPojo(CouponDO.class);
66   - doThrow(new ServiceException(COUPON_VALID_TIME_NOT_NOW)).when(couponService).validCoupon(coupon01);
67   - // mock 方法(情况二:所结算商品没有符合条件的商品)
68   - CouponDO coupon02 = randomPojo(CouponDO.class);
69   - // mock 方法(情况三:使用金额不足)
70   - CouponDO coupon03 = randomPojo(CouponDO.class, o -> o.setProductScope(PromotionProductScopeEnum.ALL.getScope())
71   - .setUsePrice(300));
72   - // mock 方法(情况五:满足条件)
73   - CouponDO coupon04 = randomPojo(CouponDO.class, o -> o.setProductScope(PromotionProductScopeEnum.ALL.getScope())
74   - .setUsePrice(190));
75   - // mock 方法(获得用户的待使用优惠劵)
76   - when(couponService.getCouponList(eq(1024L), eq(CouponStatusEnum.UNUSED.getStatus())))
77   - .thenReturn(asList(coupon01, coupon02, coupon03, coupon04));
78   - // 调用
79   - List<CouponMeetRespDTO> list = priceService.getMeetCouponList(calculateReqDTO);
80   - // 断言
81   - assertEquals(list.size(), 4);
82   - // 断言情况一:优惠劵未到使用时间
83   - CouponMeetRespDTO couponMeetRespDTO01 = list.get(0);
84   - assertPojoEquals(couponMeetRespDTO01, coupon01);
85   - assertFalse(couponMeetRespDTO01.getMeet());
86   - assertEquals(couponMeetRespDTO01.getMeetTip(), "优惠劵未到使用时间");
87   - // 断言情况二:所结算商品没有符合条件的商品
88   - CouponMeetRespDTO couponMeetRespDTO02 = list.get(1);
89   - assertPojoEquals(couponMeetRespDTO02, coupon02);
90   - assertFalse(couponMeetRespDTO02.getMeet());
91   - assertEquals(couponMeetRespDTO02.getMeetTip(), "所结算商品没有符合条件的商品");
92   - // 断言情况三:差 %s 元可用优惠劵
93   - CouponMeetRespDTO couponMeetRespDTO03 = list.get(2);
94   - assertPojoEquals(couponMeetRespDTO03, coupon03);
95   - assertFalse(couponMeetRespDTO03.getMeet());
96   - assertEquals(couponMeetRespDTO03.getMeetTip(), "所结算的商品中未满足使用的金额");
97   - // 断言情况四:满足条件
98   - CouponMeetRespDTO couponMeetRespDTO04 = list.get(3);
99   - assertPojoEquals(couponMeetRespDTO04, coupon04);
100   - assertTrue(couponMeetRespDTO04.getMeet());
101   - assertNull(couponMeetRespDTO04.getMeetTip());
102   - }
103   -
104   -}
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java
... ... @@ -421,6 +421,7 @@ public class PayOrderServiceImpl implements PayOrderService {
421 421 return;
422 422 }
423 423  
  424 + // TODO 芋艿:应该 new 出来更新
424 425 order.setPrice(payPrice);
425 426 orderMapper.updateById(order);
426 427 }
... ...