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