Commit 36ce968893dfc218c6b5946ccb7305af58250ed0
1 parent
f1fa8ead
mall + trade:review 运费价格计算
Showing
5 changed files
with
23 additions
and
11 deletions
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/spu/ProductSpuDO.java
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 { |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * 校验快递运费模板 |
| 69 | + * | |
| 70 | + * 如果校验不通过,抛出 {@link cn.iocoder.yudao.framework.common.exception.ServiceException} 异常 | |
| 71 | + * | |
| 69 | 72 | * @param templateId 模板编号 |
| 70 | - * @return DeliveryExpressTemplateDO 非空 | |
| 73 | + * @return 快递运费模板 | |
| 71 | 74 | */ |
| 72 | 75 | DeliveryExpressTemplateDO validateDeliveryExpressTemplate(Long templateId); |
| 73 | 76 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java
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. |
| 34 | 34 | @Component |
| 35 | 35 | @Order(TradePriceCalculator.ORDER_DELIVERY) |
| 36 | 36 | public class TradeDeliveryPriceCalculator implements TradePriceCalculator { |
| 37 | + | |
| 37 | 38 | @Resource |
| 38 | 39 | private AddressApi addressApi; |
| 39 | 40 | @Resource |
| 40 | 41 | private ProductSkuApi productSkuApi; |
| 42 | + | |
| 41 | 43 | @Resource |
| 42 | 44 | private DeliveryExpressTemplateService deliveryExpressTemplateService; |
| 45 | + // TODO @jason:走 Service 哈。Mapper 只允许自己的 Service 调用,保护好数据结构; | |
| 43 | 46 | @Resource |
| 44 | 47 | private DeliveryExpressTemplateChargeMapper templateChargeMapper; |
| 45 | 48 | @Resource |
| ... | ... | @@ -106,20 +109,22 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { |
| 106 | 109 | // 得到SKU 详情。得到 重量体积 |
| 107 | 110 | Map<Long, ProductSkuRespDTO> skuRespMap = convertMap(productSkuApi.getSkuList(skuIds), ProductSkuRespDTO::getId); |
| 108 | 111 | // 一个 spuId 可能对应多条订单商品 SKU |
| 112 | + // TODO @jason:得确认下,按照 sku 算,还是 spu 算; | |
| 109 | 113 | Map<Long, List<OrderItem>> spuIdItemMap = convertMultiMap(selectedItem, OrderItem::getSpuId); |
| 110 | 114 | // 依次计算每个 SPU 的快递运费 |
| 111 | 115 | for (Map.Entry<Long, List<OrderItem>> entry : spuIdItemMap.entrySet()) { |
| 112 | 116 | List<OrderItem> orderItems = entry.getValue(); |
| 113 | 117 | // 总件数, 总金额, 总重量, 总体积 |
| 114 | - int totalCount = 0, totalPrice = 0; | |
| 118 | + int totalCount = 0; | |
| 119 | + int totalPrice = 0; | |
| 115 | 120 | double totalWeight = 0; |
| 116 | 121 | double totalVolume = 0; |
| 117 | 122 | for (OrderItem orderItem : orderItems) { |
| 118 | 123 | totalCount += orderItem.getCount(); |
| 119 | - totalPrice += orderItem.getPrice(); | |
| 124 | + totalPrice += orderItem.getPrice(); // TODO jason:应该按照 payPrice? | |
| 120 | 125 | ProductSkuRespDTO skuResp = skuRespMap.get(orderItem.getSkuId()); |
| 121 | 126 | if (skuResp != null) { |
| 122 | - totalWeight = totalWeight + skuResp.getWeight(); | |
| 127 | + totalWeight = totalWeight + skuResp.getWeight(); // TODO @jason:* 数量 | |
| 123 | 128 | totalVolume = totalVolume + skuResp.getVolume(); |
| 124 | 129 | } |
| 125 | 130 | } |
| ... | ... | @@ -130,6 +135,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { |
| 130 | 135 | continue; |
| 131 | 136 | } |
| 132 | 137 | // 计算快递运费 |
| 138 | + // TODO @jason:貌似也可以抽成 checkExpressFree 类似方法 | |
| 133 | 139 | if (areaTemplateChargeMap.containsKey(receiverAreaId)) { |
| 134 | 140 | DeliveryExpressTemplateChargeDO templateCharge = areaTemplateChargeMap.get(receiverAreaId); |
| 135 | 141 | DeliveryExpressChargeModeEnum chargeModeEnum = DeliveryExpressChargeModeEnum.valueOf(chargeMode); |
| ... | ... | @@ -170,8 +176,8 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { |
| 170 | 176 | int extraPrice = templateCharge.getExtraPrice() * extraNum; |
| 171 | 177 | deliveryPrice = templateCharge.getStartPrice() + extraPrice; |
| 172 | 178 | } |
| 173 | - // | |
| 174 | - // TODO @芋艿 分摊快递费用到 SKU. 是不是搞复杂了 | |
| 179 | + // TODO @芋艿 分摊快递费用到 SKU. 是不是搞复杂了; | |
| 180 | + // TODO @jason:因为退费的时候,可能按照 SKU 考虑退费金额 | |
| 175 | 181 | divideDeliveryPrice(deliveryPrice, orderItems); |
| 176 | 182 | } |
| 177 | 183 | ... | ... |
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; |
| 11 | 11 | public interface TradePriceCalculator { |
| 12 | 12 | |
| 13 | 13 | int ORDER_DISCOUNT_ACTIVITY = 10; |
| 14 | - /** | |
| 15 | - * TODO @芋艿 快递运费的计算在满减之前。 例如有满多少包邮 | |
| 16 | - */ | |
| 17 | - int ORDER_DELIVERY = 15; | |
| 18 | 14 | int ORDER_REWARD_ACTIVITY = 20; |
| 19 | 15 | int ORDER_COUPON = 30; |
| 16 | + /** | |
| 17 | + * 快递运费的计算 | |
| 18 | + * | |
| 19 | + * 放在各种营销活动、优惠劵后面 TODO | |
| 20 | + */ | |
| 21 | + int ORDER_DELIVERY = 40; | |
| 20 | 22 | |
| 21 | 23 | void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result); |
| 22 | 24 | ... | ... |