|
@@ -56,36 +56,36 @@ public class TradePointActivityPriceCalculator implements TradePriceCalculator {
|
|
|
Assert.isTrue(param.getItems().size() == 1, "积分商城兑换商品时,只允许选择一个商品");
|
|
|
// 2. 校验是否可以参与积分商城活动
|
|
|
TradePriceCalculateRespBO.OrderItem orderItem = result.getItems().get(0);
|
|
|
- PointValidateJoinRespDTO activity = validateJoinSeckill(
|
|
|
+ PointValidateJoinRespDTO activity = validateJoinPointActivity(
|
|
|
param.getUserId(), param.getPointActivityId(),
|
|
|
orderItem.getSkuId(), orderItem.getCount());
|
|
|
|
|
|
+ // 3.0 积分兑换前置校验
|
|
|
+ Assert.isTrue(activity.getPoint() >= 1, "积分商城商品兑换积分必须大于 1");
|
|
|
// 3.1 记录优惠明细
|
|
|
+ int usePoint = activity.getPoint() * orderItem.getCount();
|
|
|
+ result.setUsePoint(usePoint);
|
|
|
+ orderItem.setUsePoint(usePoint);
|
|
|
int discountPrice = orderItem.getPayPrice(); // 情况一:单使用积分兑换
|
|
|
- Assert.isTrue(activity.getPoint() >= 1, "积分商城商品兑换积分必须大于 1");
|
|
|
- result.setUsePoint(activity.getPoint() * orderItem.getCount());
|
|
|
- orderItem.setUsePoint(activity.getPoint() * orderItem.getCount());
|
|
|
if (activity.getPrice() != null && activity.getPrice() > 0) { // 情况二:积分 + 金额
|
|
|
discountPrice = orderItem.getPayPrice() - activity.getPrice() * orderItem.getCount();
|
|
|
}
|
|
|
- // 3.2 记录优惠明细
|
|
|
TradePriceCalculatorHelper.addPromotion(result, orderItem,
|
|
|
param.getPointActivityId(), "积分商城活动", PromotionTypeEnum.POINT.getType(),
|
|
|
StrUtil.format("积分商城活动:省 {} 元", TradePriceCalculatorHelper.formatPrice(discountPrice)),
|
|
|
discountPrice);
|
|
|
-
|
|
|
- // 3.3 更新 SKU 优惠金额
|
|
|
+ // 3.2 更新 SKU 优惠金额
|
|
|
orderItem.setDiscountPrice(orderItem.getDiscountPrice() + discountPrice);
|
|
|
TradePriceCalculatorHelper.recountPayPrice(orderItem);
|
|
|
TradePriceCalculatorHelper.recountAllPrice(result);
|
|
|
}
|
|
|
|
|
|
- private PointValidateJoinRespDTO validateJoinSeckill(Long userId, Long activityId, Long skuId, Integer count) {
|
|
|
+ private PointValidateJoinRespDTO validateJoinPointActivity(Long userId, Long activityId, Long skuId, Integer count) {
|
|
|
// 1. 校验是否可以参与积分商城活动
|
|
|
PointValidateJoinRespDTO pointValidateJoinRespDTO = pointActivityApi.validateJoinPointActivity(activityId, skuId, count);
|
|
|
// 2. 校验总限购数量,目前只有 trade 有具体下单的数据,需要交给 trade 价格计算使用
|
|
|
- int activityProductCount = tradeOrderQueryService.getSeckillProductCount(userId, activityId);
|
|
|
- if (activityProductCount + count > pointValidateJoinRespDTO.getCount()) {
|
|
|
+ int pointProductCount = tradeOrderQueryService.getActivityProductCount(userId, activityId, TradeOrderTypeEnum.POINT);
|
|
|
+ if (pointProductCount + count > pointValidateJoinRespDTO.getCount()) {
|
|
|
throw exception(PRICE_CALCULATE_POINT_TOTAL_LIMIT_COUNT);
|
|
|
}
|
|
|
return pointValidateJoinRespDTO;
|