mall + trade:review 运费价格计算

This commit is contained in:
YunaiV 2023-06-03 18:08:59 +08:00
parent f1fa8eadd2
commit 36ce968893
5 changed files with 23 additions and 11 deletions

View File

@ -141,7 +141,7 @@ public class ProductSpuDO extends BaseDO {
/** /**
* 物流配置模板编号 * 物流配置模板编号
* *
* 对应 { TradeDeliveryExpressTemplateDO id 编号} * 对应 TradeDeliveryExpressTemplateDO id 编号
*/ */
private Long deliveryTemplateId; private Long deliveryTemplateId;

View File

@ -66,8 +66,11 @@ public interface DeliveryExpressTemplateService {
/** /**
* 校验快递运费模板 * 校验快递运费模板
*
* 如果校验不通过抛出 {@link cn.iocoder.yudao.framework.common.exception.ServiceException} 异常
*
* @param templateId 模板编号 * @param templateId 模板编号
* @return DeliveryExpressTemplateDO 非空 * @return 快递运费模板
*/ */
DeliveryExpressTemplateDO validateDeliveryExpressTemplate(Long templateId); DeliveryExpressTemplateDO validateDeliveryExpressTemplate(Long templateId);
} }

View File

@ -58,6 +58,7 @@ public class TradePriceCalculateReqBO {
* *
* 关联 {@link DeliveryExpressTemplateDO#getId()} * 关联 {@link DeliveryExpressTemplateDO#getId()}
*/ */
// TODO @jason运费模版是不是每个 SKU 传入哈
private Long templateId; private Long templateId;
/** /**

View File

@ -34,12 +34,15 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
@Component @Component
@Order(TradePriceCalculator.ORDER_DELIVERY) @Order(TradePriceCalculator.ORDER_DELIVERY)
public class TradeDeliveryPriceCalculator implements TradePriceCalculator { public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
@Resource @Resource
private AddressApi addressApi; private AddressApi addressApi;
@Resource @Resource
private ProductSkuApi productSkuApi; private ProductSkuApi productSkuApi;
@Resource @Resource
private DeliveryExpressTemplateService deliveryExpressTemplateService; private DeliveryExpressTemplateService deliveryExpressTemplateService;
// TODO @jason Service Mapper 只允许自己的 Service 调用保护好数据结构
@Resource @Resource
private DeliveryExpressTemplateChargeMapper templateChargeMapper; private DeliveryExpressTemplateChargeMapper templateChargeMapper;
@Resource @Resource
@ -106,20 +109,22 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
// 得到SKU 详情得到 重量体积 // 得到SKU 详情得到 重量体积
Map<Long, ProductSkuRespDTO> skuRespMap = convertMap(productSkuApi.getSkuList(skuIds), ProductSkuRespDTO::getId); Map<Long, ProductSkuRespDTO> skuRespMap = convertMap(productSkuApi.getSkuList(skuIds), ProductSkuRespDTO::getId);
// 一个 spuId 可能对应多条订单商品 SKU // 一个 spuId 可能对应多条订单商品 SKU
// TODO @jason得确认下按照 sku 还是 spu
Map<Long, List<OrderItem>> spuIdItemMap = convertMultiMap(selectedItem, OrderItem::getSpuId); Map<Long, List<OrderItem>> spuIdItemMap = convertMultiMap(selectedItem, OrderItem::getSpuId);
// 依次计算每个 SPU 的快递运费 // 依次计算每个 SPU 的快递运费
for (Map.Entry<Long, List<OrderItem>> entry : spuIdItemMap.entrySet()) { for (Map.Entry<Long, List<OrderItem>> entry : spuIdItemMap.entrySet()) {
List<OrderItem> orderItems = entry.getValue(); List<OrderItem> orderItems = entry.getValue();
// 总件数, 总金额, 总重量 总体积 // 总件数, 总金额, 总重量 总体积
int totalCount = 0, totalPrice = 0; int totalCount = 0;
int totalPrice = 0;
double totalWeight = 0; double totalWeight = 0;
double totalVolume = 0; double totalVolume = 0;
for (OrderItem orderItem : orderItems) { for (OrderItem orderItem : orderItems) {
totalCount += orderItem.getCount(); totalCount += orderItem.getCount();
totalPrice += orderItem.getPrice(); totalPrice += orderItem.getPrice(); // TODO jason应该按照 payPrice
ProductSkuRespDTO skuResp = skuRespMap.get(orderItem.getSkuId()); ProductSkuRespDTO skuResp = skuRespMap.get(orderItem.getSkuId());
if (skuResp != null) { if (skuResp != null) {
totalWeight = totalWeight + skuResp.getWeight(); totalWeight = totalWeight + skuResp.getWeight(); // TODO @jason* 数量
totalVolume = totalVolume + skuResp.getVolume(); totalVolume = totalVolume + skuResp.getVolume();
} }
} }
@ -130,6 +135,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
continue; continue;
} }
// 计算快递运费 // 计算快递运费
// TODO @jason貌似也可以抽成 checkExpressFree 类似方法
if (areaTemplateChargeMap.containsKey(receiverAreaId)) { if (areaTemplateChargeMap.containsKey(receiverAreaId)) {
DeliveryExpressTemplateChargeDO templateCharge = areaTemplateChargeMap.get(receiverAreaId); DeliveryExpressTemplateChargeDO templateCharge = areaTemplateChargeMap.get(receiverAreaId);
DeliveryExpressChargeModeEnum chargeModeEnum = DeliveryExpressChargeModeEnum.valueOf(chargeMode); DeliveryExpressChargeModeEnum chargeModeEnum = DeliveryExpressChargeModeEnum.valueOf(chargeMode);
@ -170,8 +176,8 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
int extraPrice = templateCharge.getExtraPrice() * extraNum; int extraPrice = templateCharge.getExtraPrice() * extraNum;
deliveryPrice = templateCharge.getStartPrice() + extraPrice; deliveryPrice = templateCharge.getStartPrice() + extraPrice;
} }
// // TODO @芋艿 分摊快递费用到 SKU. 是不是搞复杂了
// TODO @芋艿 分摊快递费用到 SKU. 是不是搞复杂了 // TODO @jason因为退费的时候可能按照 SKU 考虑退费金额
divideDeliveryPrice(deliveryPrice, orderItems); divideDeliveryPrice(deliveryPrice, orderItems);
} }

View File

@ -11,12 +11,14 @@ import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
public interface TradePriceCalculator { public interface TradePriceCalculator {
int ORDER_DISCOUNT_ACTIVITY = 10; int ORDER_DISCOUNT_ACTIVITY = 10;
/**
* TODO @芋艿 快递运费的计算在满减之前 例如有满多少包邮
*/
int ORDER_DELIVERY = 15;
int ORDER_REWARD_ACTIVITY = 20; int ORDER_REWARD_ACTIVITY = 20;
int ORDER_COUPON = 30; int ORDER_COUPON = 30;
/**
* 快递运费的计算
*
* 放在各种营销活动优惠劵后面 TODO
*/
int ORDER_DELIVERY = 40;
void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result); void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result);