Commit ad535e674f16e7fa96b5421fe52d434755fc79d6
1 parent
a8c78f30
trade:积分相关的价格计算
Showing
11 changed files
with
39 additions
and
19 deletions
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java
| @@ -111,17 +111,19 @@ public class ProductSpuRespDTO { | @@ -111,17 +111,19 @@ public class ProductSpuRespDTO { | ||
| 111 | // ========== 物流相关字段 ========= | 111 | // ========== 物流相关字段 ========= |
| 112 | 112 | ||
| 113 | /** | 113 | /** |
| 114 | - * 赠送积分 | ||
| 115 | - */ | ||
| 116 | - private Integer giveIntegral; | ||
| 117 | - | ||
| 118 | - /** | ||
| 119 | * 物流配置模板编号 | 114 | * 物流配置模板编号 |
| 120 | * | 115 | * |
| 121 | * 对应 TradeDeliveryExpressTemplateDO 的 id 编号 | 116 | * 对应 TradeDeliveryExpressTemplateDO 的 id 编号 |
| 122 | */ | 117 | */ |
| 123 | private Long deliveryTemplateId; | 118 | private Long deliveryTemplateId; |
| 124 | 119 | ||
| 120 | + // ========== 营销相关字段 ========= | ||
| 121 | + | ||
| 122 | + /** | ||
| 123 | + * 赠送积分 | ||
| 124 | + */ | ||
| 125 | + private Integer giveIntegral; | ||
| 126 | + | ||
| 125 | // ========== 统计相关字段 ========= | 127 | // ========== 统计相关字段 ========= |
| 126 | 128 | ||
| 127 | /** | 129 | /** |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java
| @@ -146,18 +146,20 @@ public class TradeOrderItemDO extends BaseDO { | @@ -146,18 +146,20 @@ public class TradeOrderItemDO extends BaseDO { | ||
| 146 | private Integer pointPrice; | 146 | private Integer pointPrice; |
| 147 | /** | 147 | /** |
| 148 | * 使用的积分 | 148 | * 使用的积分 |
| 149 | + * | ||
| 150 | + * 目的:用于后续取消或者售后订单时,需要归还赠送 | ||
| 149 | */ | 151 | */ |
| 150 | private Integer usePoint; | 152 | private Integer usePoint; |
| 151 | /** | 153 | /** |
| 152 | * 赠送的积分 | 154 | * 赠送的积分 |
| 155 | + * | ||
| 156 | + * 目的:用于后续取消或者售后订单时,需要扣减赠送 | ||
| 153 | */ | 157 | */ |
| 154 | private Integer givePoint; | 158 | private Integer givePoint; |
| 155 | /** | 159 | /** |
| 156 | * VIP 减免金额,单位:分 | 160 | * VIP 减免金额,单位:分 |
| 157 | */ | 161 | */ |
| 158 | private Integer vipPrice; | 162 | private Integer vipPrice; |
| 159 | - // TODO @芋艿:如果商品 vip 折扣时,到底是新增一个 vipPrice 记录优惠记录,还是 vipDiscountPrice,记录 vip 的优惠;还是直接使用 vipPrice; | ||
| 160 | - // 目前 crmeb 的选择,单独一个 vipPrice 记录优惠价格;感觉不一定合理,可以在看看有赞的; | ||
| 161 | 163 | ||
| 162 | // ========== 售后基本信息 ========== | 164 | // ========== 售后基本信息 ========== |
| 163 | 165 |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java
| @@ -348,7 +348,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -348,7 +348,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 348 | // TODO 芋艿:OrderLog | 348 | // TODO 芋艿:OrderLog |
| 349 | 349 | ||
| 350 | // 增加用户积分(赠送) | 350 | // 增加用户积分(赠送) |
| 351 | - addUserPoint(order.getUserId(), order.getGivePoint(), MemberPointBizTypeEnum.ORDER_REWARD, order.getId()); | 351 | + addUserPoint(order.getUserId(), order.getGivePoint(), MemberPointBizTypeEnum.ORDER_GIVE, order.getId()); |
| 352 | // 增加用户经验 | 352 | // 增加用户经验 |
| 353 | getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); | 353 | getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); |
| 354 | // 增加用户佣金 | 354 | // 增加用户佣金 |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointGiveCalculator.java
| @@ -16,6 +16,7 @@ import java.util.Optional; | @@ -16,6 +16,7 @@ import java.util.Optional; | ||
| 16 | 16 | ||
| 17 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; | 17 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; |
| 18 | 18 | ||
| 19 | +// TODO @疯狂:这个可以搞个单测; | ||
| 19 | /** | 20 | /** |
| 20 | * 赠送积分的 {@link TradePriceCalculator} 实现类 | 21 | * 赠送积分的 {@link TradePriceCalculator} 实现类 |
| 21 | * | 22 | * |
| @@ -25,6 +26,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | @@ -25,6 +26,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | ||
| 25 | @Order(TradePriceCalculator.ORDER_POINT_GIVE) | 26 | @Order(TradePriceCalculator.ORDER_POINT_GIVE) |
| 26 | @Slf4j | 27 | @Slf4j |
| 27 | public class TradePointGiveCalculator implements TradePriceCalculator { | 28 | public class TradePointGiveCalculator implements TradePriceCalculator { |
| 29 | + | ||
| 28 | @Resource | 30 | @Resource |
| 29 | private MemberPointApi memberPointApi; | 31 | private MemberPointApi memberPointApi; |
| 30 | 32 | ||
| @@ -54,9 +56,10 @@ public class TradePointGiveCalculator implements TradePriceCalculator { | @@ -54,9 +56,10 @@ public class TradePointGiveCalculator implements TradePriceCalculator { | ||
| 54 | TradePriceCalculateRespBO.OrderItem orderItem = orderItems.get(i); | 56 | TradePriceCalculateRespBO.OrderItem orderItem = orderItems.get(i); |
| 55 | // 商品可能赠送了积分,所以这里要加上 | 57 | // 商品可能赠送了积分,所以这里要加上 |
| 56 | orderItem.setGivePoint(orderItem.getGivePoint() + dividePoints.get(i)); | 58 | orderItem.setGivePoint(orderItem.getGivePoint() + dividePoints.get(i)); |
| 57 | - TradePriceCalculatorHelper.recountPayPrice(orderItem); | 59 | + TradePriceCalculatorHelper.recountPayPrice(orderItem); // TODO @疯狂:这个应该不用调用哇?不影响支付金额 |
| 58 | } | 60 | } |
| 59 | // 3.3 更新订单赠送积分 | 61 | // 3.3 更新订单赠送积分 |
| 60 | TradePriceCalculatorHelper.recountAllGivePoint(result); | 62 | TradePriceCalculatorHelper.recountAllGivePoint(result); |
| 61 | } | 63 | } |
| 64 | + | ||
| 62 | } | 65 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointUsePriceCalculator.java
| @@ -20,6 +20,7 @@ import java.util.List; | @@ -20,6 +20,7 @@ import java.util.List; | ||
| 20 | 20 | ||
| 21 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; | 21 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; |
| 22 | 22 | ||
| 23 | +// TODO @疯狂:搞个单测,嘿嘿; | ||
| 23 | /** | 24 | /** |
| 24 | * 使用积分的 {@link TradePriceCalculator} 实现类 | 25 | * 使用积分的 {@link TradePriceCalculator} 实现类 |
| 25 | * | 26 | * |
| @@ -29,6 +30,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | @@ -29,6 +30,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | ||
| 29 | @Order(TradePriceCalculator.ORDER_POINT_USE) | 30 | @Order(TradePriceCalculator.ORDER_POINT_USE) |
| 30 | @Slf4j | 31 | @Slf4j |
| 31 | public class TradePointUsePriceCalculator implements TradePriceCalculator { | 32 | public class TradePointUsePriceCalculator implements TradePriceCalculator { |
| 33 | + | ||
| 32 | @Resource | 34 | @Resource |
| 33 | private MemberPointApi memberPointApi; | 35 | private MemberPointApi memberPointApi; |
| 34 | @Resource | 36 | @Resource |
| @@ -48,13 +50,14 @@ public class TradePointUsePriceCalculator implements TradePriceCalculator { | @@ -48,13 +50,14 @@ public class TradePointUsePriceCalculator implements TradePriceCalculator { | ||
| 48 | } | 50 | } |
| 49 | // 1.3 校验用户积分余额 | 51 | // 1.3 校验用户积分余额 |
| 50 | MemberUserRespDTO user = memberUserApi.getUser(param.getUserId()); | 52 | MemberUserRespDTO user = memberUserApi.getUser(param.getUserId()); |
| 51 | - if (user.getPoint() == null || user.getPoint() < 0) { | 53 | + if (user.getPoint() == null || user.getPoint() <= 0) { |
| 52 | return; | 54 | return; |
| 53 | } | 55 | } |
| 54 | 56 | ||
| 55 | // 2.1 计算积分优惠金额 | 57 | // 2.1 计算积分优惠金额 |
| 58 | + // TODO @疯狂:如果计算出来,优惠金额为 0,那是不是不用执行后续逻辑哈 | ||
| 56 | int pointPrice = calculatePointPrice(config, user.getPoint(), result); | 59 | int pointPrice = calculatePointPrice(config, user.getPoint(), result); |
| 57 | - // 2.1 计算分摊的积分、抵扣金额 | 60 | + // 2.2 计算分摊的积分、抵扣金额 |
| 58 | List<TradePriceCalculateRespBO.OrderItem> orderItems = filterList(result.getItems(), TradePriceCalculateRespBO.OrderItem::getSelected); | 61 | List<TradePriceCalculateRespBO.OrderItem> orderItems = filterList(result.getItems(), TradePriceCalculateRespBO.OrderItem::getSelected); |
| 59 | List<Integer> dividePointPrices = TradePriceCalculatorHelper.dividePrice(orderItems, pointPrice); | 62 | List<Integer> dividePointPrices = TradePriceCalculatorHelper.dividePrice(orderItems, pointPrice); |
| 60 | List<Integer> divideUsePoints = TradePriceCalculatorHelper.dividePrice(orderItems, result.getUsePoint()); | 63 | List<Integer> divideUsePoints = TradePriceCalculatorHelper.dividePrice(orderItems, result.getUsePoint()); |
| @@ -74,7 +77,9 @@ public class TradePointUsePriceCalculator implements TradePriceCalculator { | @@ -74,7 +77,9 @@ public class TradePointUsePriceCalculator implements TradePriceCalculator { | ||
| 74 | TradePriceCalculatorHelper.recountAllPrice(result); | 77 | TradePriceCalculatorHelper.recountAllPrice(result); |
| 75 | } | 78 | } |
| 76 | 79 | ||
| 80 | + // TODO @疯狂:这个最好是 is 开头;因为 check 或者 validator,更多失败,会抛出异常; | ||
| 77 | private boolean checkDeductPointEnable(MemberPointConfigRespDTO config) { | 81 | private boolean checkDeductPointEnable(MemberPointConfigRespDTO config) { |
| 82 | + // TODO @疯狂:这个要不直接写成 return config != null && config .... 多行这样一个形式; | ||
| 78 | if (config == null) { | 83 | if (config == null) { |
| 79 | return false; | 84 | return false; |
| 80 | } | 85 | } |
| @@ -93,7 +98,7 @@ public class TradePointUsePriceCalculator implements TradePriceCalculator { | @@ -93,7 +98,7 @@ public class TradePointUsePriceCalculator implements TradePriceCalculator { | ||
| 93 | } | 98 | } |
| 94 | // 积分优惠金额(分) | 99 | // 积分优惠金额(分) |
| 95 | int pointPrice = usePoint * config.getTradeDeductUnitPrice(); | 100 | int pointPrice = usePoint * config.getTradeDeductUnitPrice(); |
| 96 | - // 0元购!!!:用户积分比较多时,积分可以抵扣的金额要大于支付金额, 这时需要根据支付金额反推使用多少积分 | 101 | + // 0 元购!!!:用户积分比较多时,积分可以抵扣的金额要大于支付金额,这时需要根据支付金额反推使用多少积分 |
| 97 | if (result.getPrice().getPayPrice() < pointPrice) { | 102 | if (result.getPrice().getPayPrice() < pointPrice) { |
| 98 | pointPrice = result.getPrice().getPayPrice(); | 103 | pointPrice = result.getPrice().getPayPrice(); |
| 99 | // 反推需要扣除的积分 | 104 | // 反推需要扣除的积分 |
| @@ -103,7 +108,7 @@ public class TradePointUsePriceCalculator implements TradePriceCalculator { | @@ -103,7 +108,7 @@ public class TradePointUsePriceCalculator implements TradePriceCalculator { | ||
| 103 | } | 108 | } |
| 104 | // 记录使用的积分 | 109 | // 记录使用的积分 |
| 105 | result.setUsePoint(usePoint); | 110 | result.setUsePoint(usePoint); |
| 106 | - | ||
| 107 | return pointPrice; | 111 | return pointPrice; |
| 108 | } | 112 | } |
| 113 | + | ||
| 109 | } | 114 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java
| @@ -21,11 +21,13 @@ public interface TradePriceCalculator { | @@ -21,11 +21,13 @@ public interface TradePriceCalculator { | ||
| 21 | /** | 21 | /** |
| 22 | * 快递运费的计算 | 22 | * 快递运费的计算 |
| 23 | * | 23 | * |
| 24 | - * 放在各种营销活动、优惠劵后面 TODO | 24 | + * 放在各种营销活动、优惠劵后面 |
| 25 | */ | 25 | */ |
| 26 | int ORDER_DELIVERY = 50; | 26 | int ORDER_DELIVERY = 50; |
| 27 | /** | 27 | /** |
| 28 | * 赠送积分,放最后 | 28 | * 赠送积分,放最后 |
| 29 | + * | ||
| 30 | + * 放在 {@link #ORDER_DELIVERY} 后面的原因,是运费也会产生费用,需要赠送对应积分 | ||
| 29 | */ | 31 | */ |
| 30 | int ORDER_POINT_GIVE = 999; | 32 | int ORDER_POINT_GIVE = 999; |
| 31 | 33 |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java
| @@ -199,6 +199,8 @@ public class TradePriceCalculatorHelper { | @@ -199,6 +199,8 @@ public class TradePriceCalculatorHelper { | ||
| 199 | /** | 199 | /** |
| 200 | * 按照支付金额,返回每个订单项的分摊金额数组 | 200 | * 按照支付金额,返回每个订单项的分摊金额数组 |
| 201 | * | 201 | * |
| 202 | + * 实际上 price 不仅仅可以传递的是金额,也可以是积分。因为它的实现逻辑,就是根据 payPrice 做分摊而已 | ||
| 203 | + * | ||
| 202 | * @param orderItems 订单项数组 | 204 | * @param orderItems 订单项数组 |
| 203 | * @param price 金额 | 205 | * @param price 金额 |
| 204 | * @return 分摊金额数组,和传入的 orderItems 一一对应 | 206 | * @return 分摊金额数组,和传入的 orderItems 一一对应 |
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApi.java
| @@ -12,6 +12,7 @@ import javax.validation.constraints.Min; | @@ -12,6 +12,7 @@ import javax.validation.constraints.Min; | ||
| 12 | */ | 12 | */ |
| 13 | public interface MemberPointApi { | 13 | public interface MemberPointApi { |
| 14 | 14 | ||
| 15 | + // TODO @疯狂:这个我们要不要搞成通用的会员配置?MemberConfig? | ||
| 15 | /** | 16 | /** |
| 16 | * 获得积分配置 | 17 | * 获得积分配置 |
| 17 | * | 18 | * |
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/dto/MemberPointConfigRespDTO.java
| @@ -9,6 +9,7 @@ import lombok.Data; | @@ -9,6 +9,7 @@ import lombok.Data; | ||
| 9 | */ | 9 | */ |
| 10 | @Data | 10 | @Data |
| 11 | public class MemberPointConfigRespDTO { | 11 | public class MemberPointConfigRespDTO { |
| 12 | + | ||
| 12 | /** | 13 | /** |
| 13 | * 积分抵扣开关 | 14 | * 积分抵扣开关 |
| 14 | */ | 15 | */ |
| @@ -27,4 +28,5 @@ public class MemberPointConfigRespDTO { | @@ -27,4 +28,5 @@ public class MemberPointConfigRespDTO { | ||
| 27 | * 1 元赠送多少分 | 28 | * 1 元赠送多少分 |
| 28 | */ | 29 | */ |
| 29 | private Integer tradeGivePoint; | 30 | private Integer tradeGivePoint; |
| 31 | + | ||
| 30 | } | 32 | } |
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java
| @@ -17,11 +17,11 @@ import java.util.Objects; | @@ -17,11 +17,11 @@ import java.util.Objects; | ||
| 17 | public enum MemberPointBizTypeEnum implements IntArrayValuable { | 17 | public enum MemberPointBizTypeEnum implements IntArrayValuable { |
| 18 | 18 | ||
| 19 | SIGN(1, "签到", "签到获得 {} 积分", true), | 19 | SIGN(1, "签到", "签到获得 {} 积分", true), |
| 20 | - ORDER_REWARD(10, "订单奖励", "下单获得 {} 积分", true), | ||
| 21 | - ORDER_CANCEL(11, "订单取消", "订单取消,退还 {} 积分", true), // 退回积分 | ||
| 22 | - ORDER_USE(12, "订单使用", "下单使用 {} 积分", false), // 扣减积分 | ||
| 23 | - AFTER_SALE_REFUND_USED(13, "订单退款", "订单退款,退还 {} 积分", true), // 退回积分 | ||
| 24 | - AFTER_SALE_DEDUCT_GIVE(14, "订单退款", "订单退款,扣除赠送的 {} 积分", false), // 扣减积分 | 20 | + ORDER_GIVE(10, "订单奖励", "下单获得 {} 积分", true), // 支付订单时,赠送积分 |
| 21 | + ORDER_CANCEL(11, "订单取消", "订单取消,退还 {} 积分", true), // 取消订单时,退回积分 | ||
| 22 | + ORDER_USE(12, "订单使用", "下单使用 {} 积分", false), // 下单时,扣减积分 | ||
| 23 | + AFTER_SALE_REFUND_USED(13, "订单退款", "订单退款,退还 {} 积分", true), // 售后订单成功时,退回积分(对应 ORDER_USE 操作) | ||
| 24 | + AFTER_SALE_DEDUCT_GIVE(14, "订单退款", "订单退款,扣除赠送的 {} 积分", false), // 售后订单成功时,扣减积分(对应 ORDER_GIVE 操作) | ||
| 25 | ; | 25 | ; |
| 26 | 26 | ||
| 27 | /** | 27 | /** |