From 36ce968893dfc218c6b5946ccb7305af58250ed0 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 3 Jun 2023 18:08:59 +0800 Subject: [PATCH] =?UTF-8?q?mall=20+=20trade=EF=BC=9Areview=20=E8=BF=90?= =?UTF-8?q?=E8=B4=B9=E4=BB=B7=E6=A0=BC=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/dal/dataobject/spu/ProductSpuDO.java | 2 +- .../delivery/DeliveryExpressTemplateService.java | 5 ++++- .../price/bo/TradePriceCalculateReqBO.java | 1 + .../calculator/TradeDeliveryPriceCalculator.java | 16 +++++++++++----- .../price/calculator/TradePriceCalculator.java | 10 ++++++---- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/spu/ProductSpuDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/spu/ProductSpuDO.java index 5ee4f1d28..905bb890b 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/spu/ProductSpuDO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/spu/ProductSpuDO.java @@ -141,7 +141,7 @@ public class ProductSpuDO extends BaseDO { /** * 物流配置模板编号 * - * 对应 { TradeDeliveryExpressTemplateDO 的 id 编号} + * 对应 TradeDeliveryExpressTemplateDO 的 id 编号 */ private Long deliveryTemplateId; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateService.java index 2b69c6147..e4fb5e69a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateService.java @@ -66,8 +66,11 @@ public interface DeliveryExpressTemplateService { /** * 校验快递运费模板 + * + * 如果校验不通过,抛出 {@link cn.iocoder.yudao.framework.common.exception.ServiceException} 异常 + * * @param templateId 模板编号 - * @return DeliveryExpressTemplateDO 非空 + * @return 快递运费模板 */ DeliveryExpressTemplateDO validateDeliveryExpressTemplate(Long templateId); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java index eb59f22e0..7f9d333ae 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java @@ -58,6 +58,7 @@ public class TradePriceCalculateReqBO { * * 关联 {@link DeliveryExpressTemplateDO#getId()} */ + // TODO @jason:运费模版,是不是每个 SKU 传入哈 private Long templateId; /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java index aaefc76c5..1f53bf8cc 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java @@ -34,12 +34,15 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. @Component @Order(TradePriceCalculator.ORDER_DELIVERY) public class TradeDeliveryPriceCalculator implements TradePriceCalculator { + @Resource private AddressApi addressApi; @Resource private ProductSkuApi productSkuApi; + @Resource private DeliveryExpressTemplateService deliveryExpressTemplateService; + // TODO @jason:走 Service 哈。Mapper 只允许自己的 Service 调用,保护好数据结构; @Resource private DeliveryExpressTemplateChargeMapper templateChargeMapper; @Resource @@ -106,20 +109,22 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { // 得到SKU 详情。得到 重量体积 Map skuRespMap = convertMap(productSkuApi.getSkuList(skuIds), ProductSkuRespDTO::getId); // 一个 spuId 可能对应多条订单商品 SKU + // TODO @jason:得确认下,按照 sku 算,还是 spu 算; Map> spuIdItemMap = convertMultiMap(selectedItem, OrderItem::getSpuId); // 依次计算每个 SPU 的快递运费 for (Map.Entry> entry : spuIdItemMap.entrySet()) { List orderItems = entry.getValue(); // 总件数, 总金额, 总重量, 总体积 - int totalCount = 0, totalPrice = 0; + int totalCount = 0; + int totalPrice = 0; double totalWeight = 0; double totalVolume = 0; for (OrderItem orderItem : orderItems) { totalCount += orderItem.getCount(); - totalPrice += orderItem.getPrice(); + totalPrice += orderItem.getPrice(); // TODO jason:应该按照 payPrice? ProductSkuRespDTO skuResp = skuRespMap.get(orderItem.getSkuId()); if (skuResp != null) { - totalWeight = totalWeight + skuResp.getWeight(); + totalWeight = totalWeight + skuResp.getWeight(); // TODO @jason:* 数量 totalVolume = totalVolume + skuResp.getVolume(); } } @@ -130,6 +135,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { continue; } // 计算快递运费 + // TODO @jason:貌似也可以抽成 checkExpressFree 类似方法 if (areaTemplateChargeMap.containsKey(receiverAreaId)) { DeliveryExpressTemplateChargeDO templateCharge = areaTemplateChargeMap.get(receiverAreaId); DeliveryExpressChargeModeEnum chargeModeEnum = DeliveryExpressChargeModeEnum.valueOf(chargeMode); @@ -170,8 +176,8 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { int extraPrice = templateCharge.getExtraPrice() * extraNum; deliveryPrice = templateCharge.getStartPrice() + extraPrice; } - // - // TODO @芋艿 分摊快递费用到 SKU. 是不是搞复杂了 + // TODO @芋艿 分摊快递费用到 SKU. 是不是搞复杂了; + // TODO @jason:因为退费的时候,可能按照 SKU 考虑退费金额 divideDeliveryPrice(deliveryPrice, orderItems); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java index ba7fd6c8e..92ae9c2ee 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java @@ -11,12 +11,14 @@ import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; public interface TradePriceCalculator { int ORDER_DISCOUNT_ACTIVITY = 10; - /** - * TODO @芋艿 快递运费的计算在满减之前。 例如有满多少包邮 - */ - int ORDER_DELIVERY = 15; int ORDER_REWARD_ACTIVITY = 20; int ORDER_COUPON = 30; + /** + * 快递运费的计算 + * + * 放在各种营销活动、优惠劵后面 TODO + */ + int ORDER_DELIVERY = 40; void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result);