mirror of
				https://github.com/YunaiV/ruoyi-vue-pro.git
				synced 2025-10-31 02:28:03 +08:00 
			
		
		
		
	trade:积分相关的价格计算
This commit is contained in:
		| @ -110,11 +110,6 @@ public class ProductSpuRespDTO { | |||||||
|  |  | ||||||
|     // ========== 物流相关字段 ========= |     // ========== 物流相关字段 ========= | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 赠送积分 |  | ||||||
|      */ |  | ||||||
|     private Integer giveIntegral; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 物流配置模板编号 |      * 物流配置模板编号 | ||||||
|      * |      * | ||||||
| @ -122,6 +117,13 @@ public class ProductSpuRespDTO { | |||||||
|      */ |      */ | ||||||
|     private Long deliveryTemplateId; |     private Long deliveryTemplateId; | ||||||
|  |  | ||||||
|  |     // ========== 营销相关字段 ========= | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 赠送积分 | ||||||
|  |      */ | ||||||
|  |     private Integer giveIntegral; | ||||||
|  |  | ||||||
|     // ========== 统计相关字段 ========= |     // ========== 统计相关字段 ========= | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -146,18 +146,20 @@ public class TradeOrderItemDO extends BaseDO { | |||||||
|     private Integer pointPrice; |     private Integer pointPrice; | ||||||
|     /** |     /** | ||||||
|      * 使用的积分 |      * 使用的积分 | ||||||
|  |      * | ||||||
|  |      * 目的:用于后续取消或者售后订单时,需要归还赠送 | ||||||
|      */ |      */ | ||||||
|     private Integer usePoint; |     private Integer usePoint; | ||||||
|     /** |     /** | ||||||
|      * 赠送的积分 |      * 赠送的积分 | ||||||
|  |      * | ||||||
|  |      * 目的:用于后续取消或者售后订单时,需要扣减赠送 | ||||||
|      */ |      */ | ||||||
|     private Integer givePoint; |     private Integer givePoint; | ||||||
|     /** |     /** | ||||||
|      * VIP 减免金额,单位:分 |      * VIP 减免金额,单位:分 | ||||||
|      */ |      */ | ||||||
|     private Integer vipPrice; |     private Integer vipPrice; | ||||||
|     // TODO @芋艿:如果商品 vip 折扣时,到底是新增一个 vipPrice 记录优惠记录,还是 vipDiscountPrice,记录 vip 的优惠;还是直接使用 vipPrice; |  | ||||||
|     // 目前 crmeb 的选择,单独一个 vipPrice 记录优惠价格;感觉不一定合理,可以在看看有赞的; |  | ||||||
|  |  | ||||||
|     // ========== 售后基本信息 ========== |     // ========== 售后基本信息 ========== | ||||||
|  |  | ||||||
|  | |||||||
| @ -348,7 +348,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | |||||||
|         // TODO 芋艿:OrderLog |         // TODO 芋艿:OrderLog | ||||||
|  |  | ||||||
|         // 增加用户积分(赠送) |         // 增加用户积分(赠送) | ||||||
|         addUserPoint(order.getUserId(), order.getGivePoint(), MemberPointBizTypeEnum.ORDER_REWARD, order.getId()); |         addUserPoint(order.getUserId(), order.getGivePoint(), MemberPointBizTypeEnum.ORDER_GIVE, order.getId()); | ||||||
|         // 增加用户经验 |         // 增加用户经验 | ||||||
|         getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); |         getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); | ||||||
|         // 增加用户佣金 |         // 增加用户佣金 | ||||||
|  | |||||||
| @ -16,6 +16,7 @@ import java.util.Optional; | |||||||
|  |  | ||||||
| import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; | ||||||
|  |  | ||||||
|  | // TODO @疯狂:这个可以搞个单测; | ||||||
| /** | /** | ||||||
|  * 赠送积分的 {@link TradePriceCalculator} 实现类 |  * 赠送积分的 {@link TradePriceCalculator} 实现类 | ||||||
|  * |  * | ||||||
| @ -25,6 +26,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | |||||||
| @Order(TradePriceCalculator.ORDER_POINT_GIVE) | @Order(TradePriceCalculator.ORDER_POINT_GIVE) | ||||||
| @Slf4j | @Slf4j | ||||||
| public class TradePointGiveCalculator implements TradePriceCalculator { | public class TradePointGiveCalculator implements TradePriceCalculator { | ||||||
|  |  | ||||||
|     @Resource |     @Resource | ||||||
|     private MemberPointApi memberPointApi; |     private MemberPointApi memberPointApi; | ||||||
|  |  | ||||||
| @ -54,9 +56,10 @@ public class TradePointGiveCalculator implements TradePriceCalculator { | |||||||
|             TradePriceCalculateRespBO.OrderItem orderItem = orderItems.get(i); |             TradePriceCalculateRespBO.OrderItem orderItem = orderItems.get(i); | ||||||
|             // 商品可能赠送了积分,所以这里要加上 |             // 商品可能赠送了积分,所以这里要加上 | ||||||
|             orderItem.setGivePoint(orderItem.getGivePoint() + dividePoints.get(i)); |             orderItem.setGivePoint(orderItem.getGivePoint() + dividePoints.get(i)); | ||||||
|             TradePriceCalculatorHelper.recountPayPrice(orderItem); |             TradePriceCalculatorHelper.recountPayPrice(orderItem); // TODO @疯狂:这个应该不用调用哇?不影响支付金额 | ||||||
|         } |         } | ||||||
|         // 3.3 更新订单赠送积分 |         // 3.3 更新订单赠送积分 | ||||||
|         TradePriceCalculatorHelper.recountAllGivePoint(result); |         TradePriceCalculatorHelper.recountAllGivePoint(result); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -20,6 +20,7 @@ import java.util.List; | |||||||
|  |  | ||||||
| import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; | ||||||
|  |  | ||||||
|  | // TODO @疯狂:搞个单测,嘿嘿; | ||||||
| /** | /** | ||||||
|  * 使用积分的 {@link TradePriceCalculator} 实现类 |  * 使用积分的 {@link TradePriceCalculator} 实现类 | ||||||
|  * |  * | ||||||
| @ -29,6 +30,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | |||||||
| @Order(TradePriceCalculator.ORDER_POINT_USE) | @Order(TradePriceCalculator.ORDER_POINT_USE) | ||||||
| @Slf4j | @Slf4j | ||||||
| public class TradePointUsePriceCalculator implements TradePriceCalculator { | public class TradePointUsePriceCalculator implements TradePriceCalculator { | ||||||
|  |  | ||||||
|     @Resource |     @Resource | ||||||
|     private MemberPointApi memberPointApi; |     private MemberPointApi memberPointApi; | ||||||
|     @Resource |     @Resource | ||||||
| @ -48,13 +50,14 @@ public class TradePointUsePriceCalculator implements TradePriceCalculator { | |||||||
|         } |         } | ||||||
|         // 1.3 校验用户积分余额 |         // 1.3 校验用户积分余额 | ||||||
|         MemberUserRespDTO user = memberUserApi.getUser(param.getUserId()); |         MemberUserRespDTO user = memberUserApi.getUser(param.getUserId()); | ||||||
|         if (user.getPoint() == null || user.getPoint() < 0) { |         if (user.getPoint() == null || user.getPoint() <= 0) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // 2.1 计算积分优惠金额 |         // 2.1 计算积分优惠金额 | ||||||
|  |         // TODO @疯狂:如果计算出来,优惠金额为 0,那是不是不用执行后续逻辑哈 | ||||||
|         int pointPrice = calculatePointPrice(config, user.getPoint(), result); |         int pointPrice = calculatePointPrice(config, user.getPoint(), result); | ||||||
|         // 2.1 计算分摊的积分、抵扣金额 |         // 2.2 计算分摊的积分、抵扣金额 | ||||||
|         List<TradePriceCalculateRespBO.OrderItem> orderItems = filterList(result.getItems(), TradePriceCalculateRespBO.OrderItem::getSelected); |         List<TradePriceCalculateRespBO.OrderItem> orderItems = filterList(result.getItems(), TradePriceCalculateRespBO.OrderItem::getSelected); | ||||||
|         List<Integer> dividePointPrices = TradePriceCalculatorHelper.dividePrice(orderItems, pointPrice); |         List<Integer> dividePointPrices = TradePriceCalculatorHelper.dividePrice(orderItems, pointPrice); | ||||||
|         List<Integer> divideUsePoints = TradePriceCalculatorHelper.dividePrice(orderItems, result.getUsePoint()); |         List<Integer> divideUsePoints = TradePriceCalculatorHelper.dividePrice(orderItems, result.getUsePoint()); | ||||||
| @ -74,7 +77,9 @@ public class TradePointUsePriceCalculator implements TradePriceCalculator { | |||||||
|         TradePriceCalculatorHelper.recountAllPrice(result); |         TradePriceCalculatorHelper.recountAllPrice(result); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     // TODO @疯狂:这个最好是 is 开头;因为 check 或者 validator,更多失败,会抛出异常; | ||||||
|     private boolean checkDeductPointEnable(MemberPointConfigRespDTO config) { |     private boolean checkDeductPointEnable(MemberPointConfigRespDTO config) { | ||||||
|  |         // TODO @疯狂:这个要不直接写成 return config != null && config .... 多行这样一个形式; | ||||||
|         if (config == null) { |         if (config == null) { | ||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
| @ -93,7 +98,7 @@ public class TradePointUsePriceCalculator implements TradePriceCalculator { | |||||||
|         } |         } | ||||||
|         // 积分优惠金额(分) |         // 积分优惠金额(分) | ||||||
|         int pointPrice = usePoint * config.getTradeDeductUnitPrice(); |         int pointPrice = usePoint * config.getTradeDeductUnitPrice(); | ||||||
|         // 0元购!!!:用户积分比较多时,积分可以抵扣的金额要大于支付金额, 这时需要根据支付金额反推使用多少积分 |         // 0 元购!!!:用户积分比较多时,积分可以抵扣的金额要大于支付金额,这时需要根据支付金额反推使用多少积分 | ||||||
|         if (result.getPrice().getPayPrice() < pointPrice) { |         if (result.getPrice().getPayPrice() < pointPrice) { | ||||||
|             pointPrice = result.getPrice().getPayPrice(); |             pointPrice = result.getPrice().getPayPrice(); | ||||||
|             // 反推需要扣除的积分 |             // 反推需要扣除的积分 | ||||||
| @ -103,7 +108,7 @@ public class TradePointUsePriceCalculator implements TradePriceCalculator { | |||||||
|         } |         } | ||||||
|         // 记录使用的积分 |         // 记录使用的积分 | ||||||
|         result.setUsePoint(usePoint); |         result.setUsePoint(usePoint); | ||||||
|  |  | ||||||
|         return pointPrice; |         return pointPrice; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -21,11 +21,13 @@ public interface TradePriceCalculator { | |||||||
|     /** |     /** | ||||||
|      * 快递运费的计算 |      * 快递运费的计算 | ||||||
|      * |      * | ||||||
|      * 放在各种营销活动、优惠劵后面 TODO |      * 放在各种营销活动、优惠劵后面 | ||||||
|      */ |      */ | ||||||
|     int ORDER_DELIVERY = 50; |     int ORDER_DELIVERY = 50; | ||||||
|     /** |     /** | ||||||
|      * 赠送积分,放最后 |      * 赠送积分,放最后 | ||||||
|  |      * | ||||||
|  |      * 放在 {@link #ORDER_DELIVERY} 后面的原因,是运费也会产生费用,需要赠送对应积分 | ||||||
|      */ |      */ | ||||||
|     int ORDER_POINT_GIVE = 999; |     int ORDER_POINT_GIVE = 999; | ||||||
|  |  | ||||||
|  | |||||||
| @ -199,6 +199,8 @@ public class TradePriceCalculatorHelper { | |||||||
|     /** |     /** | ||||||
|      * 按照支付金额,返回每个订单项的分摊金额数组 |      * 按照支付金额,返回每个订单项的分摊金额数组 | ||||||
|      * |      * | ||||||
|  |      * 实际上 price 不仅仅可以传递的是金额,也可以是积分。因为它的实现逻辑,就是根据 payPrice 做分摊而已 | ||||||
|  |      * | ||||||
|      * @param orderItems 订单项数组 |      * @param orderItems 订单项数组 | ||||||
|      * @param price      金额 |      * @param price      金额 | ||||||
|      * @return 分摊金额数组,和传入的 orderItems 一一对应 |      * @return 分摊金额数组,和传入的 orderItems 一一对应 | ||||||
|  | |||||||
| @ -12,6 +12,7 @@ import javax.validation.constraints.Min; | |||||||
|  */ |  */ | ||||||
| public interface MemberPointApi { | public interface MemberPointApi { | ||||||
|  |  | ||||||
|  |     // TODO @疯狂:这个我们要不要搞成通用的会员配置?MemberConfig? | ||||||
|     /** |     /** | ||||||
|      * 获得积分配置 |      * 获得积分配置 | ||||||
|      * |      * | ||||||
|  | |||||||
| @ -9,6 +9,7 @@ import lombok.Data; | |||||||
|  */ |  */ | ||||||
| @Data | @Data | ||||||
| public class MemberPointConfigRespDTO { | public class MemberPointConfigRespDTO { | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 积分抵扣开关 |      * 积分抵扣开关 | ||||||
|      */ |      */ | ||||||
| @ -27,4 +28,5 @@ public class MemberPointConfigRespDTO { | |||||||
|      * 1 元赠送多少分 |      * 1 元赠送多少分 | ||||||
|      */ |      */ | ||||||
|     private Integer tradeGivePoint; |     private Integer tradeGivePoint; | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -51,4 +51,5 @@ public class MemberUserRespDTO { | |||||||
|      * 积分 |      * 积分 | ||||||
|      */ |      */ | ||||||
|     private Integer point; |     private Integer point; | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -17,11 +17,11 @@ import java.util.Objects; | |||||||
| public enum MemberPointBizTypeEnum implements IntArrayValuable { | public enum MemberPointBizTypeEnum implements IntArrayValuable { | ||||||
|  |  | ||||||
|     SIGN(1, "签到", "签到获得 {} 积分", true), |     SIGN(1, "签到", "签到获得 {} 积分", true), | ||||||
|     ORDER_REWARD(10, "订单奖励", "下单获得 {} 积分", true), |     ORDER_GIVE(10, "订单奖励", "下单获得 {} 积分", true), // 支付订单时,赠送积分 | ||||||
|     ORDER_CANCEL(11, "订单取消", "订单取消,退还 {} 积分", true), // 退回积分 |     ORDER_CANCEL(11, "订单取消", "订单取消,退还 {} 积分", true), // 取消订单时,退回积分 | ||||||
|     ORDER_USE(12, "订单使用", "下单使用 {} 积分", false), // 扣减积分 |     ORDER_USE(12, "订单使用", "下单使用 {} 积分", false), // 下单时,扣减积分 | ||||||
|     AFTER_SALE_REFUND_USED(13, "订单退款", "订单退款,退还 {} 积分", true), // 退回积分 |     AFTER_SALE_REFUND_USED(13, "订单退款", "订单退款,退还 {} 积分", true), // 售后订单成功时,退回积分(对应 ORDER_USE 操作) | ||||||
|     AFTER_SALE_DEDUCT_GIVE(14, "订单退款", "订单退款,扣除赠送的 {} 积分", false), // 扣减积分 |     AFTER_SALE_DEDUCT_GIVE(14, "订单退款", "订单退款,扣除赠送的 {} 积分", false), // 售后订单成功时,扣减积分(对应 ORDER_GIVE 操作) | ||||||
|     ; |     ; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV