Bladeren bron

运费计算封装

xdd 2 maanden geleden
bovenliggende
commit
eb4b85adf7

+ 18 - 14
fs-service-system/src/main/java/com/fs/store/service/impl/FsStoreOrderServiceImpl.java

@@ -1213,10 +1213,13 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
         BigDecimal postMoney = calPostMoney(storeProductPackage, address);
 
         redisCache.setCacheObject("orderKey:"+uuid, storeProductPackage.getPackageId().toString(), 300, TimeUnit.SECONDS);
+
+        logger.info("orderKey: {},address: {},package: {},totalMoney: {},postMoney: {}",uuid,address,storeProductPackage,totalMoney,postMoney);
+
         return R.ok().put("orderKey",uuid)
                 .put("address",address)
                 .put("package",storeProductPackage)
-                .put("totalMoney",totalMoney)
+                .put("totalMoney",totalMoney.add(postMoney))
                 .put("postMoney",postMoney);
     }
 
@@ -1236,13 +1239,13 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
                 BigDecimal productSum = getProductSum(storeProductPackage, type);
 
                 // 按件数
-                if(ObjectUtil.equal(ShippingTempEnum.TYPE_1,type)){
+                if(ObjectUtil.equal(ShippingTempEnum.TYPE_1.getValue(),type)){
                     shippingOrderBuilder.itemCount(productSum.intValue());
                 // 按重量
-                } else if(ObjectUtil.equal(ShippingTempEnum.TYPE_2,type)){
+                } else if(ObjectUtil.equal(ShippingTempEnum.TYPE_2.getValue(),type)){
                     shippingOrderBuilder.weight(productSum);
                 // 按体积
-                } else if(ObjectUtil.equal(ShippingTempEnum.TYPE_3,type)){
+                } else if(ObjectUtil.equal(ShippingTempEnum.TYPE_3.getValue(),type)){
                     shippingOrderBuilder.volume(productSum);
                 }
 
@@ -1264,22 +1267,22 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
         BigDecimal sum = BigDecimal.ZERO;
         for(int i=0;i<objects.size();i++){
             JSONObject jsonObject = objects.getJSONObject(i);
-            Long productId = jsonObject.getLong("id");
+            Long id = jsonObject.getLong("id");
             Long count = jsonObject.getLong("count");
 
             // 按件数
-            if(ObjectUtil.equal(ShippingTempEnum.TYPE_1,type)){
+            if(ObjectUtil.equal(ShippingTempEnum.TYPE_1.getValue(),type)){
                 sum = sum.add(BigDecimal.valueOf(count));
                 // 按重量
-            } else if(ObjectUtil.equal(ShippingTempEnum.TYPE_2,type)){
-                List<FsStoreProductAttrValue> fsStoreProductAttrValues
-                        = fsStoreProductAttrValueService.selectFsStoreProductAttrValueByProductId(productId);
-                sum = fsStoreProductAttrValues.stream().map(FsStoreProductAttrValue::getWeight).reduce(BigDecimal.ZERO, BigDecimal::add);
+            } else if(ObjectUtil.equal(ShippingTempEnum.TYPE_2.getValue(),type)){
+                FsStoreProductAttrValue fsStoreProductAttrValues
+                        = fsStoreProductAttrValueService.selectFsStoreProductAttrValueById(id);
+                sum = sum.add(fsStoreProductAttrValues.getWeight());
                 // 按体积
-            } else if(ObjectUtil.equal(ShippingTempEnum.TYPE_3,type)){
-                List<FsStoreProductAttrValue> fsStoreProductAttrValues
-                        = fsStoreProductAttrValueService.selectFsStoreProductAttrValueByProductId(productId);
-                sum = fsStoreProductAttrValues.stream().map(FsStoreProductAttrValue::getVolume).reduce(BigDecimal.ZERO, BigDecimal::add);
+            } else if(ObjectUtil.equal(ShippingTempEnum.TYPE_3.getValue(),type)){
+                FsStoreProductAttrValue fsStoreProductAttrValues
+                        = fsStoreProductAttrValueService.selectFsStoreProductAttrValueById(id);
+                sum = sum.add(fsStoreProductAttrValues.getVolume());
             }
         }
         return sum;
@@ -1307,6 +1310,7 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
             }
             //获取地址
             FsUserAddress address=userAddressMapper.selectFsUserAddressById(param.getAddressId());
+            Asserts.notNull(address,"当前地址不存在,请检查是否有维护!");
             //获取套餐数据
             JSONArray jsonArray=JSONUtil.parseArray(storeProductPackage.getProducts());
             List<StorePackageProductDTO> goodsList=JSONUtil.toList(jsonArray,StorePackageProductDTO.class);

+ 3 - 1
fs-service-system/src/main/resources/mapper/store/FsStoreProductPackageMapper.xml

@@ -28,7 +28,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectFsStoreProductPackageVo">
-        select package_id, title, descs, content, img_url,images, products, money, pay_money, company_id, dept_id,pay_type,limit_count,cate_id,sort,status,icg_enable,icg_month,icg_coupons,icg_url,icg_mark from fs_store_product_package
+        select package_id, title, descs, content, img_url,images, products, money, pay_money, company_id, dept_id,pay_type,limit_count,cate_id,sort,status,icg_enable,icg_month,icg_coupons,icg_url,icg_mark,template_id from fs_store_product_package
     </sql>
 
     <select id="selectFsStoreProductPackageList" parameterType="FsStoreProductPackage" resultMap="FsStoreProductPackageResult">
@@ -50,6 +50,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="icgCoupons != null "> and icg_coupons = #{icgCoupons}</if>
             <if test="icgUrl != null "> and icg_url = #{icgUrl}</if>
             <if test="icgMark != null "> and icg_mark = #{icgMark}</if>
+            <if test="templateId != null "> and template_id = #{templateId}</if>
         </where>
     </select>
 
@@ -133,6 +134,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="icgCoupons != null">icg_coupons = #{icgCoupons},</if>
             <if test="icgUrl != null">icg_url = #{icgUrl},</if>
             <if test="icgMark != null">icg_mark = #{icgMark},</if>
+            <if test="templateId != null">template_id = #{templateId},</if>
         </trim>
         where package_id = #{packageId}
     </update>