Forráskód Böngészése

运费计算封装

xdd 2 hónapja
szülő
commit
a9357d35e6
25 módosított fájl, 707 hozzáadás és 69 törlés
  1. 13 1
      fs-service-system/src/main/java/com/fs/store/domain/FsStoreProductPackage.java
  2. 12 8
      fs-service-system/src/main/java/com/fs/store/mapper/FsShippingTemplatesFreeMapper.java
  3. 15 8
      fs-service-system/src/main/java/com/fs/store/mapper/FsShippingTemplatesMapper.java
  4. 11 8
      fs-service-system/src/main/java/com/fs/store/mapper/FsShippingTemplatesRegionMapper.java
  5. 16 8
      fs-service-system/src/main/java/com/fs/store/service/IFsShippingTemplatesFreeService.java
  6. 9 8
      fs-service-system/src/main/java/com/fs/store/service/IFsShippingTemplatesRegionService.java
  7. 12 9
      fs-service-system/src/main/java/com/fs/store/service/IFsShippingTemplatesService.java
  8. 2 1
      fs-service-system/src/main/java/com/fs/store/service/IFsStoreProductPackageService.java
  9. 15 8
      fs-service-system/src/main/java/com/fs/store/service/impl/FsShippingTemplatesFreeServiceImpl.java
  10. 14 8
      fs-service-system/src/main/java/com/fs/store/service/impl/FsShippingTemplatesRegionServiceImpl.java
  11. 6 0
      fs-service-system/src/main/java/com/fs/store/service/impl/FsShippingTemplatesServiceImpl.java
  12. 52 2
      fs-service-system/src/main/java/com/fs/store/service/impl/FsStoreOrderServiceImpl.java
  13. 11 0
      fs-service-system/src/main/java/com/fs/store/strategy/FeeCalculationStrategy.java
  14. 27 0
      fs-service-system/src/main/java/com/fs/store/strategy/FreeShippingDecorator.java
  15. 32 0
      fs-service-system/src/main/java/com/fs/store/strategy/FreeShippingRule.java
  16. 68 0
      fs-service-system/src/main/java/com/fs/store/strategy/Region.java
  17. 10 0
      fs-service-system/src/main/java/com/fs/store/strategy/ShippingFeeDecorator.java
  18. 29 0
      fs-service-system/src/main/java/com/fs/store/strategy/ShippingOrder.java
  19. 23 0
      fs-service-system/src/main/java/com/fs/store/strategy/ShippingStrategyFactory.java
  20. 85 0
      fs-service-system/src/main/java/com/fs/store/strategy/ShippingTemplate.java
  21. 11 0
      fs-service-system/src/main/java/com/fs/store/strategy/ShippingTemplateConfig.java
  22. 128 0
      fs-service-system/src/main/java/com/fs/store/strategy/ShippingTemplateManager.java
  23. 41 0
      fs-service-system/src/main/java/com/fs/store/strategy/impl/CountBasedStrategy.java
  24. 32 0
      fs-service-system/src/main/java/com/fs/store/strategy/impl/VolumeBasedStrategy.java
  25. 33 0
      fs-service-system/src/main/java/com/fs/store/strategy/impl/WeightBasedStrategy.java

+ 13 - 1
fs-service-system/src/main/java/com/fs/store/domain/FsStoreProductPackage.java

@@ -53,6 +53,8 @@ public class FsStoreProductPackage extends BaseEntity
     /** 支付金额 */
     @Excel(name = "支付金额")
     private BigDecimal payMoney;
+    /** 邮费 */
+    private BigDecimal postMoney;
 
     /** 公司ID */
     @Excel(name = "公司ID")
@@ -131,6 +133,16 @@ public class FsStoreProductPackage extends BaseEntity
      */
     private String icgMark;
 
-    List<StoreOrderProductDTO> productList;
+    /**
+     * 产品列表
+     */
+    private List<StoreOrderProductDTO> productList;
+
+
+    /**
+     * 邮费模板
+     */
+    private Long templateId;
+
 
 }

+ 12 - 8
fs-service-system/src/main/java/com/fs/store/mapper/FsShippingTemplatesFreeMapper.java

@@ -3,21 +3,22 @@ package com.fs.store.mapper;
 import java.util.List;
 import com.fs.store.domain.FsShippingTemplatesFree;
 import com.fs.store.dto.TemplateDTO;
+import com.fs.store.strategy.FreeShippingRule;
 import org.apache.ibatis.annotations.Delete;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
 /**
  * 免邮费Mapper接口
- * 
+ *
  * @author fs
  * @date 2022-03-15
  */
-public interface FsShippingTemplatesFreeMapper 
+public interface FsShippingTemplatesFreeMapper
 {
     /**
      * 查询免邮费
-     * 
+     *
      * @param id 免邮费ID
      * @return 免邮费
      */
@@ -25,7 +26,7 @@ public interface FsShippingTemplatesFreeMapper
 
     /**
      * 查询免邮费列表
-     * 
+     *
      * @param fsShippingTemplatesFree 免邮费
      * @return 免邮费集合
      */
@@ -33,7 +34,7 @@ public interface FsShippingTemplatesFreeMapper
 
     /**
      * 新增免邮费
-     * 
+     *
      * @param fsShippingTemplatesFree 免邮费
      * @return 结果
      */
@@ -41,7 +42,7 @@ public interface FsShippingTemplatesFreeMapper
 
     /**
      * 修改免邮费
-     * 
+     *
      * @param fsShippingTemplatesFree 免邮费
      * @return 结果
      */
@@ -49,7 +50,7 @@ public interface FsShippingTemplatesFreeMapper
 
     /**
      * 删除免邮费
-     * 
+     *
      * @param id 免邮费ID
      * @return 结果
      */
@@ -57,7 +58,7 @@ public interface FsShippingTemplatesFreeMapper
 
     /**
      * 批量删除免邮费
-     * 
+     *
      * @param ids 需要删除的数据ID
      * @return 结果
      */
@@ -86,4 +87,7 @@ public interface FsShippingTemplatesFreeMapper
             "</if>" +
             "</script>"})
     int selectCountByTemplateDTO(@Param("maps") TemplateDTO mapValue);
+
+    @Select("select * from fs_shipping_templates_free where temp_id=${templateId}")
+    List<FsShippingTemplatesFree> selectFreeShippingRuleByTempId(@Param("templateId") Long templateId);
 }

+ 15 - 8
fs-service-system/src/main/java/com/fs/store/mapper/FsShippingTemplatesMapper.java

@@ -6,15 +6,15 @@ import org.apache.ibatis.annotations.Select;
 
 /**
  * 运费模板Mapper接口
- * 
+ *
  * @author fs
  * @date 2022-03-15
  */
-public interface FsShippingTemplatesMapper 
+public interface FsShippingTemplatesMapper
 {
     /**
      * 查询运费模板
-     * 
+     *
      * @param shippingId 运费模板ID
      * @return 运费模板
      */
@@ -22,7 +22,7 @@ public interface FsShippingTemplatesMapper
 
     /**
      * 查询运费模板列表
-     * 
+     *
      * @param fsShippingTemplates 运费模板
      * @return 运费模板集合
      */
@@ -30,7 +30,7 @@ public interface FsShippingTemplatesMapper
 
     /**
      * 新增运费模板
-     * 
+     *
      * @param fsShippingTemplates 运费模板
      * @return 结果
      */
@@ -38,7 +38,7 @@ public interface FsShippingTemplatesMapper
 
     /**
      * 修改运费模板
-     * 
+     *
      * @param fsShippingTemplates 运费模板
      * @return 结果
      */
@@ -46,7 +46,7 @@ public interface FsShippingTemplatesMapper
 
     /**
      * 删除运费模板
-     * 
+     *
      * @param shippingId 运费模板ID
      * @return 结果
      */
@@ -54,11 +54,18 @@ public interface FsShippingTemplatesMapper
 
     /**
      * 批量删除运费模板
-     * 
+     *
      * @param shippingIds 需要删除的数据ID
      * @return 结果
      */
     public int deleteFsShippingTemplatesByIds(Long[] id);
     @Select("select * from fs_shipping_templates where find_in_set(id,#{ids})")
     List<FsShippingTemplates> selectFsShippingTemplatesByIds(String ids);
+
+    /**
+     * 查询所有模板
+     * @return List<FsShippingTemplates>
+     */
+    @Select("select * from fs_shipping_templates")
+    List<FsShippingTemplates> listAllTemplate();
 }

+ 11 - 8
fs-service-system/src/main/java/com/fs/store/mapper/FsShippingTemplatesRegionMapper.java

@@ -8,15 +8,15 @@ import org.apache.ibatis.annotations.Select;
 
 /**
  * 邮费区域Mapper接口
- * 
+ *
  * @author fs
  * @date 2022-03-15
  */
-public interface FsShippingTemplatesRegionMapper 
+public interface FsShippingTemplatesRegionMapper
 {
     /**
      * 查询邮费区域
-     * 
+     *
      * @param id 邮费区域ID
      * @return 邮费区域
      */
@@ -24,7 +24,7 @@ public interface FsShippingTemplatesRegionMapper
 
     /**
      * 查询邮费区域列表
-     * 
+     *
      * @param fsShippingTemplatesRegion 邮费区域
      * @return 邮费区域集合
      */
@@ -32,7 +32,7 @@ public interface FsShippingTemplatesRegionMapper
 
     /**
      * 新增邮费区域
-     * 
+     *
      * @param fsShippingTemplatesRegion 邮费区域
      * @return 结果
      */
@@ -40,7 +40,7 @@ public interface FsShippingTemplatesRegionMapper
 
     /**
      * 修改邮费区域
-     * 
+     *
      * @param fsShippingTemplatesRegion 邮费区域
      * @return 结果
      */
@@ -48,7 +48,7 @@ public interface FsShippingTemplatesRegionMapper
 
     /**
      * 删除邮费区域
-     * 
+     *
      * @param id 邮费区域ID
      * @return 结果
      */
@@ -56,7 +56,7 @@ public interface FsShippingTemplatesRegionMapper
 
     /**
      * 批量删除邮费区域
-     * 
+     *
      * @param ids 需要删除的数据ID
      * @return 结果
      */
@@ -66,4 +66,7 @@ public interface FsShippingTemplatesRegionMapper
     int deleteFsShippingTemplatesRegionByTempId(Long tempId);
     @Select("select * from fs_shipping_templates_region where find_in_set(temp_id,#{tempIds}) and find_in_set(city_id,#{cityIds})")
     List<FsShippingTemplatesRegion> selectFsShippingTemplatesRegionListByTempIdsAndCityIds(@Param("tempIds") String tempIds,@Param("cityIds") String cityIds);
+
+    @Select("select * from fs_shipping_templates_region where temp_id=${templateId}")
+    List<FsShippingTemplatesRegion> selectTempRegionByTempIdAndCityId(@Param("templateId") Long templateId);
 }

+ 16 - 8
fs-service-system/src/main/java/com/fs/store/service/IFsShippingTemplatesFreeService.java

@@ -3,18 +3,19 @@ package com.fs.store.service;
 import java.util.List;
 import com.fs.store.domain.FsShippingTemplatesFree;
 import com.fs.store.dto.TemplateDTO;
+import com.fs.store.strategy.FreeShippingRule;
 
 /**
  * 免邮费Service接口
- * 
+ *
  * @author fs
  * @date 2022-03-15
  */
-public interface IFsShippingTemplatesFreeService 
+public interface IFsShippingTemplatesFreeService
 {
     /**
      * 查询免邮费
-     * 
+     *
      * @param id 免邮费ID
      * @return 免邮费
      */
@@ -22,7 +23,7 @@ public interface IFsShippingTemplatesFreeService
 
     /**
      * 查询免邮费列表
-     * 
+     *
      * @param fsShippingTemplatesFree 免邮费
      * @return 免邮费集合
      */
@@ -30,7 +31,7 @@ public interface IFsShippingTemplatesFreeService
 
     /**
      * 新增免邮费
-     * 
+     *
      * @param fsShippingTemplatesFree 免邮费
      * @return 结果
      */
@@ -38,7 +39,7 @@ public interface IFsShippingTemplatesFreeService
 
     /**
      * 修改免邮费
-     * 
+     *
      * @param fsShippingTemplatesFree 免邮费
      * @return 结果
      */
@@ -46,7 +47,7 @@ public interface IFsShippingTemplatesFreeService
 
     /**
      * 批量删除免邮费
-     * 
+     *
      * @param ids 需要删除的免邮费ID
      * @return 结果
      */
@@ -54,11 +55,18 @@ public interface IFsShippingTemplatesFreeService
 
     /**
      * 删除免邮费信息
-     * 
+     *
      * @param id 免邮费ID
      * @return 结果
      */
     public int deleteFsShippingTemplatesFreeById(Long id);
 
     int selectCountByTemplateDTO(TemplateDTO mapValue);
+
+    /**
+     * 查询免邮费规则
+     * @param templateId 模板id
+     * @return List<FreeShippingRule>
+     */
+    List<FsShippingTemplatesFree> selectFreeShippingRuleByTempId(Long templateId);
 }

+ 9 - 8
fs-service-system/src/main/java/com/fs/store/service/IFsShippingTemplatesRegionService.java

@@ -5,15 +5,15 @@ import com.fs.store.domain.FsShippingTemplatesRegion;
 
 /**
  * 邮费区域Service接口
- * 
+ *
  * @author fs
  * @date 2022-03-15
  */
-public interface IFsShippingTemplatesRegionService 
+public interface IFsShippingTemplatesRegionService
 {
     /**
      * 查询邮费区域
-     * 
+     *
      * @param id 邮费区域ID
      * @return 邮费区域
      */
@@ -21,7 +21,7 @@ public interface IFsShippingTemplatesRegionService
 
     /**
      * 查询邮费区域列表
-     * 
+     *
      * @param fsShippingTemplatesRegion 邮费区域
      * @return 邮费区域集合
      */
@@ -29,7 +29,7 @@ public interface IFsShippingTemplatesRegionService
 
     /**
      * 新增邮费区域
-     * 
+     *
      * @param fsShippingTemplatesRegion 邮费区域
      * @return 结果
      */
@@ -37,7 +37,7 @@ public interface IFsShippingTemplatesRegionService
 
     /**
      * 修改邮费区域
-     * 
+     *
      * @param fsShippingTemplatesRegion 邮费区域
      * @return 结果
      */
@@ -45,7 +45,7 @@ public interface IFsShippingTemplatesRegionService
 
     /**
      * 批量删除邮费区域
-     * 
+     *
      * @param ids 需要删除的邮费区域ID
      * @return 结果
      */
@@ -53,11 +53,12 @@ public interface IFsShippingTemplatesRegionService
 
     /**
      * 删除邮费区域信息
-     * 
+     *
      * @param id 邮费区域ID
      * @return 结果
      */
     public int deleteFsShippingTemplatesRegionById(Long id);
 
     List<FsShippingTemplatesRegion> selectFsShippingTemplatesRegionListByTempIdsAndCityIds(String tempIds, String cityIds);
+    List<FsShippingTemplatesRegion> selectTempRegionByTempIdAndCityId(Long templateId);
 }

+ 12 - 9
fs-service-system/src/main/java/com/fs/store/service/IFsShippingTemplatesService.java

@@ -8,23 +8,23 @@ import com.fs.store.param.FsShippingTemplatesAddEditParam;
 
 /**
  * 运费模板Service接口
- * 
+ *
  * @author fs
  * @date 2022-03-15
  */
-public interface IFsShippingTemplatesService 
+public interface IFsShippingTemplatesService
 {
     /**
      * 查询运费模板
-     * 
-     * @param shippingId 运费模板ID
+     *
+     * @param id 运费模板ID
      * @return 运费模板
      */
     public FsShippingTemplates selectFsShippingTemplatesById(Long id);
 
     /**
      * 查询运费模板列表
-     * 
+     *
      * @param fsShippingTemplates 运费模板
      * @return 运费模板集合
      */
@@ -32,7 +32,7 @@ public interface IFsShippingTemplatesService
 
     /**
      * 新增运费模板
-     * 
+     *
      * @param fsShippingTemplates 运费模板
      * @return 结果
      */
@@ -40,7 +40,7 @@ public interface IFsShippingTemplatesService
 
     /**
      * 修改运费模板
-     * 
+     *
      * @param fsShippingTemplates 运费模板
      * @return 结果
      */
@@ -48,7 +48,7 @@ public interface IFsShippingTemplatesService
 
     /**
      * 批量删除运费模板
-     * 
+     *
      * @param shippingIds 需要删除的运费模板ID
      * @return 结果
      */
@@ -56,7 +56,7 @@ public interface IFsShippingTemplatesService
 
     /**
      * 删除运费模板信息
-     * 
+     *
      * @param shippingId 运费模板ID
      * @return 结果
      */
@@ -65,4 +65,7 @@ public interface IFsShippingTemplatesService
     R addOrEdit(FsShippingTemplatesAddEditParam fsShippingTemplates);
 
     List<FsShippingTemplates> selectFsShippingTemplatesByIds(String ids);
+
+    List<FsShippingTemplates> listAllTemplate();
+
 }

+ 2 - 1
fs-service-system/src/main/java/com/fs/store/service/IFsStoreProductPackageService.java

@@ -69,7 +69,8 @@ public interface IFsStoreProductPackageService
     /**
      * 批量修改商品组合套餐
      *
-     * @param packageIds 需要修改的数据ID
+     * @param orderIds 订单id
+     * @param status 状态
      * @return 结果
      */
     public int updateFsStoreProductPackages(Long[] orderIds,Long status);

+ 15 - 8
fs-service-system/src/main/java/com/fs/store/service/impl/FsShippingTemplatesFreeServiceImpl.java

@@ -1,8 +1,10 @@
 package com.fs.store.service.impl;
 
+import java.util.Collections;
 import java.util.List;
 
 import com.fs.store.dto.TemplateDTO;
+import com.fs.store.strategy.FreeShippingRule;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.fs.store.mapper.FsShippingTemplatesFreeMapper;
@@ -11,19 +13,19 @@ import com.fs.store.service.IFsShippingTemplatesFreeService;
 
 /**
  * 免邮费Service业务层处理
- * 
+ *
  * @author fs
  * @date 2022-03-15
  */
 @Service
-public class FsShippingTemplatesFreeServiceImpl implements IFsShippingTemplatesFreeService 
+public class FsShippingTemplatesFreeServiceImpl implements IFsShippingTemplatesFreeService
 {
     @Autowired
     private FsShippingTemplatesFreeMapper fsShippingTemplatesFreeMapper;
 
     /**
      * 查询免邮费
-     * 
+     *
      * @param id 免邮费ID
      * @return 免邮费
      */
@@ -35,7 +37,7 @@ public class FsShippingTemplatesFreeServiceImpl implements IFsShippingTemplatesF
 
     /**
      * 查询免邮费列表
-     * 
+     *
      * @param fsShippingTemplatesFree 免邮费
      * @return 免邮费
      */
@@ -47,7 +49,7 @@ public class FsShippingTemplatesFreeServiceImpl implements IFsShippingTemplatesF
 
     /**
      * 新增免邮费
-     * 
+     *
      * @param fsShippingTemplatesFree 免邮费
      * @return 结果
      */
@@ -59,7 +61,7 @@ public class FsShippingTemplatesFreeServiceImpl implements IFsShippingTemplatesF
 
     /**
      * 修改免邮费
-     * 
+     *
      * @param fsShippingTemplatesFree 免邮费
      * @return 结果
      */
@@ -71,7 +73,7 @@ public class FsShippingTemplatesFreeServiceImpl implements IFsShippingTemplatesF
 
     /**
      * 批量删除免邮费
-     * 
+     *
      * @param ids 需要删除的免邮费ID
      * @return 结果
      */
@@ -83,7 +85,7 @@ public class FsShippingTemplatesFreeServiceImpl implements IFsShippingTemplatesF
 
     /**
      * 删除免邮费信息
-     * 
+     *
      * @param id 免邮费ID
      * @return 结果
      */
@@ -97,4 +99,9 @@ public class FsShippingTemplatesFreeServiceImpl implements IFsShippingTemplatesF
     public int selectCountByTemplateDTO(TemplateDTO mapValue) {
         return fsShippingTemplatesFreeMapper.selectCountByTemplateDTO(mapValue);
     }
+
+    @Override
+    public List<FsShippingTemplatesFree> selectFreeShippingRuleByTempId(Long templateId) {
+        return fsShippingTemplatesFreeMapper.selectFreeShippingRuleByTempId(templateId);
+    }
 }

+ 14 - 8
fs-service-system/src/main/java/com/fs/store/service/impl/FsShippingTemplatesRegionServiceImpl.java

@@ -1,5 +1,6 @@
 package com.fs.store.service.impl;
 
+import java.util.Collections;
 import java.util.List;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -9,19 +10,19 @@ import com.fs.store.service.IFsShippingTemplatesRegionService;
 
 /**
  * 邮费区域Service业务层处理
- * 
+ *
  * @author fs
  * @date 2022-03-15
  */
 @Service
-public class FsShippingTemplatesRegionServiceImpl implements IFsShippingTemplatesRegionService 
+public class FsShippingTemplatesRegionServiceImpl implements IFsShippingTemplatesRegionService
 {
     @Autowired
     private FsShippingTemplatesRegionMapper fsShippingTemplatesRegionMapper;
 
     /**
      * 查询邮费区域
-     * 
+     *
      * @param id 邮费区域ID
      * @return 邮费区域
      */
@@ -33,7 +34,7 @@ public class FsShippingTemplatesRegionServiceImpl implements IFsShippingTemplate
 
     /**
      * 查询邮费区域列表
-     * 
+     *
      * @param fsShippingTemplatesRegion 邮费区域
      * @return 邮费区域
      */
@@ -45,7 +46,7 @@ public class FsShippingTemplatesRegionServiceImpl implements IFsShippingTemplate
 
     /**
      * 新增邮费区域
-     * 
+     *
      * @param fsShippingTemplatesRegion 邮费区域
      * @return 结果
      */
@@ -57,7 +58,7 @@ public class FsShippingTemplatesRegionServiceImpl implements IFsShippingTemplate
 
     /**
      * 修改邮费区域
-     * 
+     *
      * @param fsShippingTemplatesRegion 邮费区域
      * @return 结果
      */
@@ -69,7 +70,7 @@ public class FsShippingTemplatesRegionServiceImpl implements IFsShippingTemplate
 
     /**
      * 批量删除邮费区域
-     * 
+     *
      * @param ids 需要删除的邮费区域ID
      * @return 结果
      */
@@ -81,7 +82,7 @@ public class FsShippingTemplatesRegionServiceImpl implements IFsShippingTemplate
 
     /**
      * 删除邮费区域信息
-     * 
+     *
      * @param id 邮费区域ID
      * @return 结果
      */
@@ -95,4 +96,9 @@ public class FsShippingTemplatesRegionServiceImpl implements IFsShippingTemplate
     public List<FsShippingTemplatesRegion> selectFsShippingTemplatesRegionListByTempIdsAndCityIds(String tempIds, String cityIds) {
         return fsShippingTemplatesRegionMapper.selectFsShippingTemplatesRegionListByTempIdsAndCityIds(tempIds,cityIds);
     }
+
+    @Override
+    public List<FsShippingTemplatesRegion> selectTempRegionByTempIdAndCityId(Long templateId) {
+        return fsShippingTemplatesRegionMapper.selectTempRegionByTempIdAndCityId(templateId);
+    }
 }

+ 6 - 0
fs-service-system/src/main/java/com/fs/store/service/impl/FsShippingTemplatesServiceImpl.java

@@ -1,6 +1,7 @@
 package com.fs.store.service.impl;
 
 import java.math.BigDecimal;
+import java.util.Collections;
 import java.util.List;
 
 import cn.hutool.core.bean.BeanUtil;
@@ -144,6 +145,11 @@ public class FsShippingTemplatesServiceImpl implements IFsShippingTemplatesServi
         return fsShippingTemplatesMapper.selectFsShippingTemplatesByIds(ids);
     }
 
+    @Override
+    public List<FsShippingTemplates> listAllTemplate() {
+        return fsShippingTemplatesMapper.listAllTemplate();
+    }
+
     /**
      * 保存模板设置的区域价格
      * @param param ShippingTemplatesDTO

+ 52 - 2
fs-service-system/src/main/java/com/fs/store/service/impl/FsStoreOrderServiceImpl.java

@@ -220,6 +220,9 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
     @Value("${fsConfig.omsCode}")
     private String deliverOmsCode;
 
+    @Autowired
+    private IFsShippingTemplatesService fsShippingTemplatesService;
+
     /**
      * 查询订单
      *
@@ -577,7 +580,7 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
 
 
     @Override
-    @Transactional
+    @Transactional(rollbackFor = Throwable.class,propagation = Propagation.REQUIRED)
     public R createOrder(long userId, FsStoreOrderCreateParam param) {
         FsStoreOrderComputedParam computedParam=new FsStoreOrderComputedParam();
         BeanUtils.copyProperties(param, computedParam);
@@ -1199,9 +1202,56 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
                 }
             }
         }
+        BigDecimal postMoney = BigDecimal.ZERO;
+        // 计算套餐邮费
+        if(ObjectUtil.isNotNull(storeProductPackage.getTemplateId())){
+            FsShippingTemplates fsShippingTemplates = fsShippingTemplatesService.selectFsShippingTemplatesById(storeProductPackage.getTemplateId());
+            Asserts.notNull(fsShippingTemplates,"该套餐没有绑定邮费模板!");
+
+            // 如果不包邮
+            if(ObjectUtil.equal(0,fsShippingTemplates.getAppoint())){
+                // 邮费等于商品总量
+                // 商品总量 重量、件、体积
+                BigDecimal totalSum = BigDecimal.ZERO;
+                Integer type = fsShippingTemplates.getType();
+                // 获取当前套餐的商品列表
+
+
+                // 按件数
+                if(ObjectUtil.equal(ShippingTempEnum.TYPE_1,type)){
+
+                // 按重量
+                } else if(ObjectUtil.equal(ShippingTempEnum.TYPE_2,type)){
+
+                // 按体积
+                } else if(ObjectUtil.equal(ShippingTempEnum.TYPE_3,type)){
+
+                }
+
+//                ShippingTempEnum
+                // 计算体积
+            }
+        }
 
         redisCache.setCacheObject("orderKey:"+uuid, storeProductPackage.getPackageId().toString(), 300, TimeUnit.SECONDS);
-        return R.ok().put("orderKey",uuid).put("address",address).put("package",storeProductPackage).put("totalMoney",totalMoney);
+        return R.ok().put("orderKey",uuid)
+                .put("address",address)
+                .put("package",storeProductPackage)
+                .put("totalMoney",totalMoney)
+                .put("postMoney",postMoney);
+    }
+
+    @Autowired
+    private IFsStoreProductService fsStoreProductService;
+    private List<FsStoreProduct> getProducts(FsStoreProductPackage storeProductPackage){
+        String products = storeProductPackage.getProducts();
+        com.alibaba.fastjson.JSONArray objects = JSON.parseArray(products);
+
+        for(int i=0;i<objects.size();i++){
+            JSONObject jsonObject = objects.getJSONObject(i);
+            Long id = jsonObject.getLong("id");
+        }
+        return null;
     }
 
     @Override

+ 11 - 0
fs-service-system/src/main/java/com/fs/store/strategy/FeeCalculationStrategy.java

@@ -0,0 +1,11 @@
+package com.fs.store.strategy;
+
+import java.math.BigDecimal;
+
+/**
+ * 运费计算的策略接口
+ */
+public interface FeeCalculationStrategy {
+    BigDecimal calculate(ShippingOrder order, Region region);
+    String getStrategyName();
+}

+ 27 - 0
fs-service-system/src/main/java/com/fs/store/strategy/FreeShippingDecorator.java

@@ -0,0 +1,27 @@
+package com.fs.store.strategy;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * 指定包邮装饰器
+ */
+public class FreeShippingDecorator implements ShippingFeeDecorator {
+    private final List<FreeShippingRule> freeShippingRules;
+
+    public FreeShippingDecorator(List<FreeShippingRule> freeShippingRules) {
+        this.freeShippingRules = freeShippingRules;
+    }
+
+    @Override
+    public BigDecimal calculateFee(BigDecimal baseFee, ShippingOrder order, Region region) {
+        // 检查是否有适用的包邮规则
+        for (FreeShippingRule rule : freeShippingRules) {
+            if (rule.getRegion().equals(region.getCityId()) &&
+                    (order.getWeight().compareTo(rule.getMinWeight()) <= 0)) {
+                return BigDecimal.ZERO;
+            }
+        }
+        return baseFee;
+    }
+}

+ 32 - 0
fs-service-system/src/main/java/com/fs/store/strategy/FreeShippingRule.java

@@ -0,0 +1,32 @@
+package com.fs.store.strategy;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * 包邮规则类
+ */
+@Data
+public class FreeShippingRule {
+    /**
+     * 区域
+     */
+    private Long region;
+    /**
+     * 包邮重量
+     */
+    private BigDecimal minWeight;
+    /**
+     * 包邮件数
+     */
+    private BigDecimal minCount;
+    /**
+     * 包邮体积
+     */
+    private BigDecimal minVolume;
+    /**
+     * 包邮金额
+     */
+    private BigDecimal minAmount;
+}

+ 68 - 0
fs-service-system/src/main/java/com/fs/store/strategy/Region.java

@@ -0,0 +1,68 @@
+package com.fs.store.strategy;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * 区域信息类
+ */
+@Data
+public class Region {
+    /**
+     * 区域名称
+     */
+    private Long cityId;
+
+    /**
+     * 区域代码
+     */
+    private String code;
+    /**
+     * 首件-运费
+     */
+    private BigDecimal firstItemFee;
+    /**
+     * 首件-件数
+     */
+    private BigDecimal firstItem;
+    /**
+     * 续件-续费
+     */
+    private BigDecimal additionalItemFee;
+
+    /**
+     * 首件重量
+     */
+    private BigDecimal firstWeight;
+    /**
+     * 首件-重量-运费
+     */
+    private BigDecimal firstWeightFee;
+
+    /**
+     * 重量-续件重量
+     */
+    private BigDecimal additionalWeight;
+    /**
+     * 续件-重量-运费
+     */
+    private BigDecimal additionalWeightFee;
+
+    /**
+     * 首件-体积
+     */
+    private BigDecimal firstVolume;
+    /**
+     * 首件-体积-运费
+     */
+    private BigDecimal firstVolumeFee;
+    /**
+     * 续件-体积-运费
+     */
+    private BigDecimal additionalVolumeFee;
+    /**
+     * 体积-续件体积
+     */
+    private BigDecimal additionalVolume;
+}

+ 10 - 0
fs-service-system/src/main/java/com/fs/store/strategy/ShippingFeeDecorator.java

@@ -0,0 +1,10 @@
+package com.fs.store.strategy;
+
+import java.math.BigDecimal;
+
+/**
+ * 装饰器模式 - 基础装饰器接口
+ */
+public interface ShippingFeeDecorator {
+    BigDecimal calculateFee(BigDecimal baseFee, ShippingOrder order, Region region);
+}

+ 29 - 0
fs-service-system/src/main/java/com/fs/store/strategy/ShippingOrder.java

@@ -0,0 +1,29 @@
+package com.fs.store.strategy;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * 订单类
+ */
+@Data
+public class ShippingOrder {
+    /**
+     * 商品数量
+     */
+    private Integer itemCount;
+    /**
+     * 商品重量
+     */
+    private BigDecimal weight;
+    /**
+     * 商品体积
+     */
+    private BigDecimal volume;
+    /**
+     * 区域名称
+     */
+    private Long cityId;
+
+}

+ 23 - 0
fs-service-system/src/main/java/com/fs/store/strategy/ShippingStrategyFactory.java

@@ -0,0 +1,23 @@
+package com.fs.store.strategy;
+
+import com.fs.store.strategy.impl.CountBasedStrategy;
+import com.fs.store.strategy.impl.VolumeBasedStrategy;
+import com.fs.store.strategy.impl.WeightBasedStrategy;
+
+/**
+ * 策略工厂,创建计费策略
+ */
+public class ShippingStrategyFactory {
+    public static FeeCalculationStrategy createStrategy(String strategyType) {
+        switch (strategyType) {
+            case "count":
+                return new CountBasedStrategy();
+            case "weight":
+                return new WeightBasedStrategy();
+            case "volume":
+                return new VolumeBasedStrategy();
+            default:
+                throw new IllegalArgumentException("不支持的计费方式: " + strategyType);
+        }
+    }
+}

+ 85 - 0
fs-service-system/src/main/java/com/fs/store/strategy/ShippingTemplate.java

@@ -0,0 +1,85 @@
+package com.fs.store.strategy;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 运费模板类
+ */
+@Data
+public class ShippingTemplate {
+    private Long id;
+    /**
+     * count, weight, volume
+     */
+    private String calculationType;
+    /**
+     * 区域列表
+     */
+    private List<Region> regions;
+    /**
+     * 包邮规则列表
+     */
+    private List<FreeShippingRule> freeShippingRules;
+    /**
+     * 计费方式
+     */
+    private FeeCalculationStrategy strategy;
+    private List<ShippingFeeDecorator> decorators;
+    /**
+     * 排序
+     */
+    private int rank;
+
+    public ShippingTemplate(Long id, String calculationType) {
+        this.id = id;
+        this.calculationType = calculationType;
+        this.regions = new ArrayList<>();
+        this.freeShippingRules = new ArrayList<>();
+        this.decorators = new ArrayList<>();
+        this.strategy = ShippingStrategyFactory.createStrategy(calculationType);
+    }
+
+    public void addRegion(Region region) {
+        regions.add(region);
+    }
+
+    public void addFreeShippingRule(FreeShippingRule rule) {
+        freeShippingRules.add(rule);
+        // 添加包邮装饰器
+        decorators.add(new FreeShippingDecorator(freeShippingRules));
+    }
+
+    public BigDecimal calculateShippingFee(ShippingOrder order) {
+        // 找到对应区域
+        Region targetRegion = null;
+        for (Region region : regions) {
+            if (region.getCityId().equals(order.getCityId())) {
+                targetRegion = region;
+                break;
+            }
+        }
+
+        if (targetRegion == null) {
+            throw new IllegalArgumentException("找不到匹配的配送区域: " + order.getCityId());
+        }
+
+        // 计算基础运费
+        BigDecimal baseFee = strategy.calculate(order, targetRegion);
+
+        // 是否包邮
+        BigDecimal finalFee = baseFee;
+        for (ShippingFeeDecorator decorator : decorators) {
+            finalFee = decorator.calculateFee(finalFee, order, targetRegion);
+        }
+
+        return finalFee;
+    }
+
+    public boolean isFreeShippingEnabled() {
+        return !freeShippingRules.isEmpty();
+    }
+}

+ 11 - 0
fs-service-system/src/main/java/com/fs/store/strategy/ShippingTemplateConfig.java

@@ -0,0 +1,11 @@
+package com.fs.store.strategy;
+
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * 运费模板管理器配置
+ */
+@Configuration
+public class ShippingTemplateConfig {
+
+}

+ 128 - 0
fs-service-system/src/main/java/com/fs/store/strategy/ShippingTemplateManager.java

@@ -0,0 +1,128 @@
+package com.fs.store.strategy;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.fs.store.domain.FsShippingTemplates;
+import com.fs.store.domain.FsShippingTemplatesFree;
+import com.fs.store.domain.FsShippingTemplatesRegion;
+import com.fs.store.enums.ShippingTempEnum;
+import com.fs.store.service.IFsShippingTemplatesFreeService;
+import com.fs.store.service.IFsShippingTemplatesRegionService;
+import com.fs.store.service.IFsShippingTemplatesService;
+import com.fs.store.strategy.impl.CountBasedStrategy;
+import com.fs.store.strategy.impl.WeightBasedStrategy;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.http.util.Asserts;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * 运费模板管理器
+ */
+@Slf4j
+@Service
+public class ShippingTemplateManager {
+    @Autowired
+    private IFsShippingTemplatesService fsShippingTemplatesService;
+    @Autowired
+    private IFsShippingTemplatesRegionService fsShippingTemplatesRegionService;
+    @Autowired
+    private IFsShippingTemplatesFreeService fsShippingTemplatesFreeService;
+
+    private final Map<Long, ShippingTemplate> TEMPLATES = new ConcurrentHashMap<>();
+
+    private static final Map<Integer, String> TEMPLATE_TYPE_MAP = new ConcurrentHashMap<>();
+    static {
+        TEMPLATE_TYPE_MAP.put(1,"count");
+        TEMPLATE_TYPE_MAP.put(2,"weight");
+        TEMPLATE_TYPE_MAP.put(3,"volume");
+    }
+
+    @PostConstruct
+    public void init(){
+        log.info("正在初始化运费模板管理器...");
+        // 查询运费模板
+        List<FsShippingTemplates> fsShippingTemplates = fsShippingTemplatesService.listAllTemplate();
+        for (FsShippingTemplates template : fsShippingTemplates) {
+            String type = TEMPLATE_TYPE_MAP.get(template.getType());
+            Asserts.notNull(type,"不支持的模板类型");
+
+            ShippingTemplate shippingTemplate = new ShippingTemplate(template.getId(),type);
+
+            log.info("正在加载模板配送区域及运费");
+            List<FsShippingTemplatesRegion> fsShippingTemplatesRegions = fsShippingTemplatesRegionService.selectTempRegionByTempIdAndCityId(template.getId());
+            for (FsShippingTemplatesRegion templatesRegion : fsShippingTemplatesRegions) {
+                Region region = new Region();
+                region.setCityId(templatesRegion.getCityId());
+                // 如果是按重量
+                if(ObjectUtil.equal(templatesRegion.getType(), ShippingTempEnum.TYPE_2.getValue())){
+                    region.setFirstWeight(templatesRegion.getFirst());
+                    region.setFirstWeightFee(templatesRegion.getFirstPrice());
+                    region.setAdditionalWeight(templatesRegion.getContinues());
+                    region.setAdditionalWeightFee(templatesRegion.getContinuePrice());
+                } else if(ObjectUtil.equal(templatesRegion.getType(),ShippingTempEnum.TYPE_1.getValue())){
+                    region.setFirstItem(templatesRegion.getFirst());
+                    region.setFirstItemFee(templatesRegion.getFirst());
+                    region.setAdditionalItemFee(templatesRegion.getFirstPrice());
+                } else if(ObjectUtil.equal(templatesRegion.getType(), ShippingTempEnum.TYPE_3.getValue())){
+                    region.setFirstVolume(templatesRegion.getFirst());
+                    region.setFirstVolumeFee(templatesRegion.getFirstPrice());
+                    region.setAdditionalVolume(templatesRegion.getContinues());
+                    region.setAdditionalVolumeFee(templatesRegion.getContinuePrice());
+                }
+                shippingTemplate.addRegion(region);
+            }
+
+
+            log.info("模板加载完成: {}", shippingTemplate);
+
+            log.info("正在加载模板包邮规则");
+            List<FsShippingTemplatesFree> freeShippingRules = fsShippingTemplatesFreeService.selectFreeShippingRuleByTempId(template.getId());
+            for (FsShippingTemplatesFree freeShippingRule : freeShippingRules) {
+                FreeShippingRule rule = new FreeShippingRule();
+                rule.setRegion(freeShippingRule.getCityId());
+
+                if(ObjectUtil.equal(freeShippingRule.getType(), ShippingTempEnum.TYPE_2.getValue())){
+                    rule.setMinWeight(freeShippingRule.getNumber());
+                    rule.setMinAmount(freeShippingRule.getPrice());
+                } else if(ObjectUtil.equal(freeShippingRule.getType(),ShippingTempEnum.TYPE_1.getValue())){
+                    rule.setMinCount(freeShippingRule.getNumber());
+                    rule.setMinAmount(freeShippingRule.getPrice());
+                } else if(ObjectUtil.equal(freeShippingRule.getType(), ShippingTempEnum.TYPE_3.getValue())){
+                    rule.setMinVolume(freeShippingRule.getNumber());
+                    rule.setMinAmount(freeShippingRule.getPrice());
+                }
+
+                shippingTemplate.addFreeShippingRule(rule);
+            }
+            log.info("模板包邮规则加载完成: {}", shippingTemplate);
+
+            this.addTemplate(shippingTemplate);
+        }
+
+    }
+
+    public void addTemplate(ShippingTemplate template) {
+        TEMPLATES.put(template.getId(), template);
+    }
+
+    public ShippingTemplate getTemplate(Long templateId) {
+        return TEMPLATES.get(templateId);
+    }
+
+    public BigDecimal calculateShippingFee(Long templateId, ShippingOrder order) {
+        ShippingTemplate template = TEMPLATES.get(templateId);
+        if (template == null) {
+            throw new IllegalArgumentException("找不到运费模板: " + templateId);
+        }
+        return template.calculateShippingFee(order);
+    }
+}
+

+ 41 - 0
fs-service-system/src/main/java/com/fs/store/strategy/impl/CountBasedStrategy.java

@@ -0,0 +1,41 @@
+package com.fs.store.strategy.impl;
+
+import com.fs.store.strategy.FeeCalculationStrategy;
+import com.fs.store.strategy.Region;
+import com.fs.store.strategy.ShippingOrder;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+
+/**
+ * 按件数计算运费
+ */
+public class CountBasedStrategy implements FeeCalculationStrategy {
+    @Override
+    public BigDecimal calculate(ShippingOrder order, Region region) {
+        BigDecimal firstItemFee = region.getFirstItemFee();
+        BigDecimal firstItem = region.getFirstItem();
+        int firstItemInt = 0;
+        if(firstItem != null) {
+            firstItemInt = firstItem.intValue();
+        }
+        // 总数-首件数量 = 首次计算数量
+        if (order.getItemCount() <= firstItemInt) {
+            return firstItemFee.multiply(BigDecimal.valueOf(order.getItemCount()));
+        }
+
+        // 首次计算数量
+        int firstItemCount = order.getItemCount() - firstItemInt;
+        int remainingItemCount = order.getItemCount() - firstItemCount;
+        // 总费用 = 首次计算数量*首次费用+剩下数量*续件费用
+        BigDecimal firstFee = firstItemFee.multiply(BigDecimal.valueOf(firstItemCount));
+        BigDecimal remainingFee = region.getAdditionalItemFee().multiply(BigDecimal.valueOf(remainingItemCount));
+
+        return firstFee.add(remainingFee);
+    }
+
+    @Override
+    public String getStrategyName() {
+        return "按件数";
+    }
+}

+ 32 - 0
fs-service-system/src/main/java/com/fs/store/strategy/impl/VolumeBasedStrategy.java

@@ -0,0 +1,32 @@
+package com.fs.store.strategy.impl;
+
+import com.fs.store.strategy.FeeCalculationStrategy;
+import com.fs.store.strategy.Region;
+import com.fs.store.strategy.ShippingOrder;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+
+/**
+ * 按体积计算运费
+ */
+public class VolumeBasedStrategy implements FeeCalculationStrategy {
+    @Override
+    public BigDecimal calculate(ShippingOrder order, Region region) {
+        // 总费用 = 首次计算数量*首次费用+剩下数量*续件费用
+        BigDecimal volume = order.getVolume();
+        BigDecimal firstVolumeFee = region.getFirstVolumeFee();
+        BigDecimal additionalVolumeFee = region.getAdditionalVolumeFee();
+        if (volume.compareTo(region.getFirstVolume()) <= 0) {
+            return firstVolumeFee.multiply(volume);
+        }
+        BigDecimal firstFee = firstVolumeFee.multiply(region.getFirstVolume());
+        BigDecimal remainingFee = additionalVolumeFee.multiply(volume.subtract(region.getFirstVolume()));
+        return firstFee.add(remainingFee);
+    }
+
+    @Override
+    public String getStrategyName() {
+        return "按体积";
+    }
+}

+ 33 - 0
fs-service-system/src/main/java/com/fs/store/strategy/impl/WeightBasedStrategy.java

@@ -0,0 +1,33 @@
+package com.fs.store.strategy.impl;
+
+import com.fs.store.strategy.FeeCalculationStrategy;
+import com.fs.store.strategy.Region;
+import com.fs.store.strategy.ShippingOrder;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+
+/**
+ * 按重量计算运费
+ */
+public class WeightBasedStrategy implements FeeCalculationStrategy {
+    @Override
+    public BigDecimal calculate(ShippingOrder order, Region region) {
+        // 总费用 = 首次计算数量*首次费用+剩下数量*续件费用
+
+        BigDecimal weight = order.getWeight();
+        BigDecimal firstWeightFee = region.getFirstWeightFee();
+        BigDecimal additionalWeightFee = region.getAdditionalWeightFee();
+        if (weight.compareTo(region.getFirstWeight()) <= 0) {
+            return firstWeightFee.multiply(weight);
+        }
+        BigDecimal firstFee = firstWeightFee.multiply(region.getFirstWeight());
+        BigDecimal remainingFee = additionalWeightFee.multiply(weight.subtract(region.getFirstWeight()));
+        return firstFee.add(remainingFee);
+    }
+
+    @Override
+    public String getStrategyName() {
+        return "按重量";
+    }
+}