Bläddra i källkod

修改虚拟商品的金额精度

Yangzw 10 månader sedan
förälder
incheckning
0fddfd66c0

+ 9 - 7
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/order/TradeOrderUpdateServiceImpl.java

@@ -231,6 +231,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
             settlementReqVO.setAddressId(address.getId());
         }
 
+        //如果是虚拟商品,则用自己的编写的程序返回
+        if (Objects.equals(settlementReqVO.getDeliveryType(), VIRTUAL_PRODUCT.getType())) {
+            return getSettlement(address,settlementReqVO.getItems());
+        }
+
         // add by Ben 20240314
         // 4. 查询每个sku对应的店铺ID,并传回页面
         List<AppTradeOrderSettlementReqVO.Item> productSkuList = settlementReqVO.getItems();
@@ -280,11 +285,6 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
             shopNameMap.put(shopDO.getId(), shopDO.getName());
         }
 
-        //如果是虚拟商品,则用自己的编写的程序返回
-        if (Objects.equals(settlementReqVO.getDeliveryType(), VIRTUAL_PRODUCT.getType())) {
-            return getSettlement(settlementReqVO.getItems());
-        }
-
         // 2. 计算价格
         /*
           add by Ben 20240402
@@ -361,10 +361,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
     /**
      * 虚拟商品自走程序
      *
-     * @param items 商品项数组
+     * @param address
+     * @param items   商品项数组
      * @return AppTradeOrderSettlementRespVO
      */
-    private AppTradeOrderSettlementRespVO getSettlement(List<AppTradeOrderSettlementReqVO.Item> items) {
+    private AppTradeOrderSettlementRespVO getSettlement(MemberAddressRespDTO address, List<AppTradeOrderSettlementReqVO.Item> items) {
 
         // 4. 查询每个sku对应的店铺ID,并传回页面
         List<AppTradeOrderSettlementReqVO.Item> productSkuList = items;
@@ -463,6 +464,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
 
         respVO.setShopRespVOMap(shopRespVOMap);
         respVO.setPrice(shopCalculateRespBO);
+        respVO.setAddress(cn.newfeifan.mall.framework.common.util.object.BeanUtils.toBean(address, AppTradeOrderSettlementRespVO.Address.class));
         return respVO;
     }
 

+ 19 - 6
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/price/TradePriceServiceImpl.java

@@ -4,6 +4,10 @@ import cn.newfeifan.mall.module.product.api.sku.ProductSkuApi;
 import cn.newfeifan.mall.module.product.api.sku.dto.ProductSkuRespDTO;
 import cn.newfeifan.mall.module.product.api.spu.ProductSpuApi;
 import cn.newfeifan.mall.module.product.api.spu.dto.ProductSpuRespDTO;
+import cn.newfeifan.mall.module.product.dal.dataobject.sku.ProductSkuDO;
+import cn.newfeifan.mall.module.product.dal.dataobject.spu.ProductSpuDO;
+import cn.newfeifan.mall.module.product.dal.mysql.sku.ProductSkuMapper;
+import cn.newfeifan.mall.module.product.dal.mysql.spu.ProductSpuMapper;
 import cn.newfeifan.mall.module.trade.service.price.bo.TradePriceCalculateReqBO;
 import cn.newfeifan.mall.module.trade.service.price.bo.TradePriceCalculateRespBO;
 import cn.newfeifan.mall.module.trade.service.price.calculator.TradeDeliveryPriceCalculator;
@@ -42,6 +46,11 @@ public class TradePriceServiceImpl implements TradePriceService {
     @Resource
     private List<TradePriceCalculator> priceCalculators;
 
+    @Resource
+    private ProductSkuMapper productSkuMapper;
+    @Resource
+    private ProductSpuMapper productSpuMapper;
+
     /**
      * add by Ben
      * 计算订单含积分的各项商品价格
@@ -77,9 +86,9 @@ public class TradePriceServiceImpl implements TradePriceService {
 //        priceCalculators.forEach(calculator -> calculator.calculate(calculateReqBO, calculateRespBO));
         //计算运费
         TradeDeliveryPriceCalculator tradeDeliveryPriceCalculator = null;
-        for(TradePriceCalculator tpc:priceCalculators){
+        for (TradePriceCalculator tpc : priceCalculators) {
             //把计算运费对象取出来,这个对象不能new,因为自己new会缺少地址信息
-            if(tpc.getClass().getName().equals("cn.newfeifan.mall.module.trade.service.price.calculator.TradeDeliveryPriceCalculator")){
+            if (tpc.getClass().getName().equals("cn.newfeifan.mall.module.trade.service.price.calculator.TradeDeliveryPriceCalculator")) {
                 tradeDeliveryPriceCalculator = (TradeDeliveryPriceCalculator) tpc;
                 break;
             }
@@ -88,10 +97,14 @@ public class TradePriceServiceImpl implements TradePriceService {
         tradeDeliveryPriceCalculator.calculate(calculateReqBO, calculateRespBO);
 
         // 2.2  如果最终支付金额小于等于 0,则抛出业务异常
-        if (calculateRespBO.getPrice().getPayPrice() <= 0) {
-            log.error("[calculatePrice][价格计算不正确,请求 calculateReqDTO({}),结果 priceCalculate({})]",
-                    calculateReqBO, calculateRespBO);
-            throw exception(PRICE_CALCULATE_PAY_PRICE_ILLEGAL);
+        ProductSkuDO sku = productSkuMapper.selectById(calculateReqBO.getItems().get(0).getSkuId());
+        ProductSpuDO spu = productSpuMapper.selectById(sku.getSpuId());
+        if (!spu.getHighPrecision()) {
+            if (calculateRespBO.getPrice().getPayPrice() <= 0) {
+                log.error("[calculatePrice][价格计算不正确,请求 calculateReqDTO({}),结果 priceCalculate({})]",
+                        calculateReqBO, calculateRespBO);
+                throw exception(PRICE_CALCULATE_PAY_PRICE_ILLEGAL);
+            }
         }
         return calculateRespBO;
     }