diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 13fe2f0c2..4065ed05e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -624,7 +624,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { throw exception(ORDER_UPDATE_PRICE_FAIL_ALREADY); } // 1.3 支付价格不能为 0 - int newPayPrice = order.getPayPrice() + order.getAdjustPrice(); + int newPayPrice = order.getPayPrice() + reqVO.getAdjustPrice(); if (newPayPrice <= 0) { throw exception(ORDER_UPDATE_PRICE_FAIL_PRICE_ERROR); } @@ -635,12 +635,14 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 3. 更新 TradeOrderItem,需要做 adjustPrice 的分摊 List orderOrderItems = tradeOrderItemMapper.selectListByOrderId(order.getId()); - List dividePrices = TradePriceCalculatorHelper.dividePrice2(orderOrderItems, newPayPrice); + List dividePrices = TradePriceCalculatorHelper.dividePrice2(orderOrderItems, reqVO.getAdjustPrice()); List updateItems = new ArrayList<>(); for (int i = 0; i < orderOrderItems.size(); i++) { TradeOrderItemDO item = orderOrderItems.get(i); + // TODO puhui999: 已有分摊记录的情况下价格是否会不对,也就是说之前订单项 1 分摊了 10 块这次是 -100 + // 那么 setPayPrice 是否改为 (item.getPayPrice()-item.getAdjustPrice()) + dividePrices.get(i) 先减掉原来的价格再加上调价。经过验证可行,修改后订单价格增减都能正确分摊 updateItems.add(new TradeOrderItemDO().setId(item.getId()).setAdjustPrice(dividePrices.get(i)) - .setPayPrice(item.getPayPrice() + dividePrices.get(i))); + .setPayPrice((item.getPayPrice() - item.getAdjustPrice()) + dividePrices.get(i))); } tradeOrderItemMapper.updateBatch(updateItems); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java index 7def3e34e..850226fbb 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java @@ -254,12 +254,15 @@ public class TradePriceCalculatorHelper { TradeOrderItemDO orderItem = items.get(i); int partPrice; if (i < items.size() - 1) { // 减一的原因,是因为拆分时,如果按照比例,可能会出现.所以最后一个,使用反减 - partPrice = (int) (price * (1.0D * orderItem.getPayPrice() / total)); + // partPrice = (int) (price * (1.0D * orderItem.getPayPrice() / total)); + // pr fix: 改为了使用订单原价来计算比例 + partPrice = (int) (price * (1.0D * orderItem.getPrice() / total)); remainPrice -= partPrice; } else { partPrice = remainPrice; } - Assert.isTrue(partPrice >= 0, "分摊金额必须大于等于 0"); + // TODO puhui999: 如果是减价的情况这里过不了 + // Assert.isTrue(partPrice >= 0, "分摊金额必须大于等于 0"); prices.add(partPrice); } return prices;