拼团活动:完善拼团下单金额结算
parent
07d6ab5842
commit
0b2943ba8b
@ -1,41 +0,0 @@
|
|||||||
package cn.iocoder.yudao.module.promotion.api.combination.dto;
|
|
||||||
|
|
||||||
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 拼团记录 Response DTO
|
|
||||||
*
|
|
||||||
* @author HUIHUI
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class CombinationRecordRespDTO {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 拼团活动编号
|
|
||||||
*/
|
|
||||||
private Long activityId;
|
|
||||||
/**
|
|
||||||
* SPU 编号
|
|
||||||
*/
|
|
||||||
private Long spuId;
|
|
||||||
/**
|
|
||||||
* SKU 编号
|
|
||||||
*/
|
|
||||||
private Long skuId;
|
|
||||||
/**
|
|
||||||
* 用户编号
|
|
||||||
*/
|
|
||||||
private Long userId;
|
|
||||||
/**
|
|
||||||
* 订单编号
|
|
||||||
*/
|
|
||||||
private Long orderId;
|
|
||||||
/**
|
|
||||||
* 开团状态
|
|
||||||
*
|
|
||||||
* 枚举 {@link CombinationRecordStatusEnum}
|
|
||||||
*/
|
|
||||||
private Integer status;
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
package cn.iocoder.yudao.module.promotion.api.combination.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验参与拼团 Response DTO
|
||||||
|
*
|
||||||
|
* @author HUIHUI
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class CombinationValidateJoinRespDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 砍价活动编号
|
||||||
|
*/
|
||||||
|
private Long activityId;
|
||||||
|
/**
|
||||||
|
* 砍价活动名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拼团金额
|
||||||
|
*/
|
||||||
|
private Integer combinationPrice;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
package cn.iocoder.yudao.module.trade.service.price.calculator;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi;
|
||||||
|
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO;
|
||||||
|
import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
|
||||||
|
import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
|
||||||
|
import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拼团活动的 {@link TradePriceCalculator} 实现类
|
||||||
|
*
|
||||||
|
* @author HUIHUI
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Order(TradePriceCalculator.ORDER_COMBINATION_ACTIVITY)
|
||||||
|
public class TradeCombinationActivityPriceCalculator implements TradePriceCalculator {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CombinationRecordApi combinationRecordApi;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) {
|
||||||
|
// 1. 判断订单类型和是否具有拼团活动编号
|
||||||
|
if (param.getCombinationActivityId() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.isTrue(param.getItems().size() == 1, "拼团时,只允许选择一个商品");
|
||||||
|
// 2. 校验是否可以参与拼团
|
||||||
|
TradePriceCalculateRespBO.OrderItem orderItem = result.getItems().get(0);
|
||||||
|
CombinationValidateJoinRespDTO combinationActivity = combinationRecordApi.validateJoinCombination(
|
||||||
|
param.getCombinationActivityId(), param.getUserId(),
|
||||||
|
orderItem.getSkuId(), orderItem.getCount());
|
||||||
|
|
||||||
|
// 3.1 记录优惠明细
|
||||||
|
Integer discountPrice = orderItem.getPayPrice() - combinationActivity.getCombinationPrice() * orderItem.getCount();
|
||||||
|
TradePriceCalculatorHelper.addPromotion(result, orderItem,
|
||||||
|
param.getCombinationActivityId(), combinationActivity.getName(), PromotionTypeEnum.COMBINATION_ACTIVITY.getType(),
|
||||||
|
StrUtil.format("拼团活动:省 {} 元", TradePriceCalculatorHelper.formatPrice(discountPrice)),
|
||||||
|
discountPrice);
|
||||||
|
// 3.2 更新 SKU 优惠金额
|
||||||
|
orderItem.setDiscountPrice(orderItem.getDiscountPrice() + discountPrice);
|
||||||
|
TradePriceCalculatorHelper.recountPayPrice(orderItem);
|
||||||
|
TradePriceCalculatorHelper.recountAllPrice(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue