mirror of
				https://github.com/YunaiV/ruoyi-vue-pro.git
				synced 2025-10-31 02:28:03 +08:00 
			
		
		
		
	mall + trade:快递价格计算
This commit is contained in:
		| @ -51,8 +51,8 @@ public interface ErrorCodeConstants { | ||||
|     ErrorCode EXPRESS_CODE_DUPLICATE = new ErrorCode(1011003001, "已经存在该编码的快递公司"); | ||||
|     ErrorCode EXPRESS_TEMPLATE_NOT_EXISTS = new ErrorCode(1011003002, "运费模板不存在"); | ||||
|     ErrorCode EXPRESS_TEMPLATE_NAME_DUPLICATE = new ErrorCode(1011003003, "已经存在该运费模板名"); | ||||
|     ErrorCode DELIVERY_EXPRESS_USER_ADDRESS_IS_EMPTY = new ErrorCode(1011003004, "计算快递运费时,收件人地址编号为空"); | ||||
|     ErrorCode PRODUCT_EXPRESS_TEMPLATE_NOT_FOUND = new ErrorCode(1011003005, "找不到到商品对应的运费模板"); | ||||
|     ErrorCode DELIVERY_EXPRESS_USER_ADDRESS_IS_EMPTY = new ErrorCode(1011003004, "计算快递运费时,收件人地址编号为空"); // TODO @jaosn:这个错误码,放到 Price 这块 | ||||
|     ErrorCode PRODUCT_EXPRESS_TEMPLATE_NOT_FOUND = new ErrorCode(1011003005, "找不到到商品对应的运费模板");  // TODO @jaosn:这个错误码,放到 Price 这块 | ||||
|     ErrorCode EXPRESS_API_QUERY_ERROR = new ErrorCode(1011003006, "快递查询接口异常"); | ||||
|     ErrorCode EXPRESS_API_QUERY_FAILED = new ErrorCode(1011003007, "快递查询返回失败, 原因:{}"); | ||||
|     ErrorCode PICK_UP_STORE_NOT_EXISTS = new ErrorCode(1011003008, "自提门店不存在"); | ||||
|  | ||||
| @ -75,7 +75,7 @@ public interface DeliveryExpressTemplateService { | ||||
|  | ||||
|     /** | ||||
|      * 校验快递运费模板 | ||||
|      * <p> | ||||
|      * | ||||
|      * 如果校验不通过,抛出 {@link cn.iocoder.yudao.framework.common.exception.ServiceException} 异常 | ||||
|      * | ||||
|      * @param templateId 模板编号 | ||||
| @ -83,6 +83,7 @@ public interface DeliveryExpressTemplateService { | ||||
|      */ | ||||
|     DeliveryExpressTemplateDO validateDeliveryExpressTemplate(Long templateId); | ||||
|  | ||||
|     // TODO @jason:可以把 spuIds 改成传递 ids 么?价格计算那,在 TradePriceCalculateRespBO 冗余好 templateId 字段。目的是,减少重复的查询 | ||||
|     /** | ||||
|      * 基于指定的 SPU 编号数组和收件人地址区域编号. 获取匹配运费模板 | ||||
|      * | ||||
|  | ||||
| @ -242,10 +242,9 @@ public class DeliveryExpressTemplateServiceImpl implements DeliveryExpressTempla | ||||
|             if (spu == null) { | ||||
|                 return; | ||||
|             } | ||||
|             // TODO @jason:避免循环查询;最好类似 expressTemplateMapper.selectBatchIds(spuMap.keySet()); 批量查询,内存组合; | ||||
|             SpuDeliveryExpressTemplateRespBO bo = new SpuDeliveryExpressTemplateRespBO() | ||||
|                     .setChargeMode(item.getChargeMode()) | ||||
|                     // TODO @jason:是不是只要查询到一个,就不用查询下一个了;TemplateCharge 和 TemplateFree | ||||
|                     //  @芋艿 包邮的优先级> 费用的优先级 所以两个都要查询 | ||||
|                     .setTemplateCharge(findMatchExpressTemplateCharge(item.getId(), areaId)) | ||||
|                     .setTemplateFree(findMatchExpressTemplateFree(item.getId(), areaId)); | ||||
|             result.put(spu.getId(), bo); | ||||
|  | ||||
| @ -18,6 +18,8 @@ public class SpuDeliveryExpressTemplateRespBO { | ||||
|      */ | ||||
|     private Integer chargeMode; | ||||
|  | ||||
|     // TODO @jaosn:可以把 DeliveryExpressTemplateChargeBO 和 DeliveryExpressTemplateFreeBO 搞成内嵌的类。这样简洁一点 | ||||
|  | ||||
|     /** | ||||
|      * 运费模板快递运费设置 | ||||
|      */ | ||||
|  | ||||
| @ -164,16 +164,7 @@ public class TradePriceCalculateRespBO { | ||||
|          */ | ||||
|         private Integer payPrice; | ||||
|  | ||||
|         /** | ||||
|          * 商品重量,单位:kg 千克 | ||||
|          */ | ||||
|         private Double weight; | ||||
|         /** | ||||
|          * 商品体积,单位:m^3 平米 | ||||
|          */ | ||||
|         private Double volume; | ||||
|  | ||||
|         // ========== 商品信息 ========== | ||||
|         // ========== 商品 SPU 信息 ========== | ||||
|         /** | ||||
|          * 商品名 | ||||
|          */ | ||||
| @ -189,6 +180,16 @@ public class TradePriceCalculateRespBO { | ||||
|          */ | ||||
|         private Long categoryId; | ||||
|  | ||||
|         // ========== 商品 SKU 信息 ========== | ||||
|         /** | ||||
|          * 商品重量,单位:kg 千克 | ||||
|          */ | ||||
|         private Double weight; | ||||
|         /** | ||||
|          * 商品体积,单位:m^3 平米 | ||||
|          */ | ||||
|         private Double volume; | ||||
|  | ||||
|         /** | ||||
|          * 商品属性数组 | ||||
|          */ | ||||
|  | ||||
| @ -62,7 +62,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { | ||||
|                 deliveryExpressTemplateService.getExpressTemplateMapBySpuIdsAndArea(spuIds, address.getAreaId()); | ||||
|         // 3. 计算配送费用 | ||||
|         if (CollUtil.isEmpty(spuExpressTemplateMap)) { | ||||
|             log.error("找不到商品 SPU ID {}, area Id {} ,对应的运费模板", spuIds, address.getAreaId()); | ||||
|             log.error("[calculate][找不到商品 spuId{} areaId{} 对应的运费模板]", spuIds, address.getAreaId()); | ||||
|             throw exception(PRODUCT_EXPRESS_TEMPLATE_NOT_FOUND); | ||||
|         } | ||||
|         calculateDeliveryPrice(selectedItem, spuExpressTemplateMap, result); | ||||
| @ -170,7 +170,8 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { | ||||
|      */ | ||||
|     private void divideDeliveryPrice(int deliveryPrice, List<OrderItem> orderItems) { | ||||
|         // TODO @jason:分摊的话,是不是要按照比例呀?重量、价格、数量等等, | ||||
|         //  按比例是不是有点复杂。后面看看是否需要 | ||||
|         //  按比例是不是有点复杂。后面看看是否需要; | ||||
|         // TODO 可以看看别的项目怎么搞的哈。 | ||||
|         int dividePrice = deliveryPrice / orderItems.size(); | ||||
|         for (OrderItem item : orderItems) { | ||||
|             // 更新快递运费 | ||||
| @ -207,6 +208,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { | ||||
|                 // freeCount 是不是应该是 double ?? | ||||
|                 // TODO @jason:要不配置的时候,把它的单位和商品对齐?到底是 kg、还是斤 | ||||
|                 // TODO @芋艿 目前 包邮 件数/重量/体积 都用的是这个字段 | ||||
|                 // TODO @jason:那要不快递模版也改成 kg?这样是不是就不用 double ? | ||||
|                 if (totalWeight >= templateFree.getFreeCount() | ||||
|                         && totalPrice >= templateFree.getFreePrice()) { | ||||
|                     return true; | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV