From f9a50116bc0848f398e393926deee9b9ba63cb42 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 2 May 2024 09:13:31 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E5=95=86?= =?UTF-8?q?=E5=9F=8E=E7=B3=BB=E7=BB=9F=EF=BC=9A=E7=AE=A1=E7=90=86=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E4=BF=AE=E6=94=B9=E5=BE=85=E6=94=AF=E4=BB=98=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=EF=BC=8C=E8=B0=83=E6=95=B4=E4=BB=B7=E6=A0=BC=E5=8F=96?= =?UTF-8?q?=E5=80=BC=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/enums/order/TradeOrderOperateTypeEnum.java | 2 +- .../trade/service/order/TradeOrderUpdateServiceImpl.java | 7 +++---- .../price/calculator/TradePriceCalculatorHelper.java | 6 +----- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java index 8973ff973..695cb41ce 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java @@ -14,7 +14,7 @@ import lombok.RequiredArgsConstructor; public enum TradeOrderOperateTypeEnum { MEMBER_CREATE(1, "用户下单"), - ADMIN_UPDATE_PRICE(2, "订单价格 {oldPayPrice} 修改,实际支付金额为 {newPayPrice} 元"), + ADMIN_UPDATE_PRICE(2, "订单价格 {oldPayPrice} 修改,调整价格 {adjustPrice},实际支付金额为 {newPayPrice} 元"), MEMBER_PAY(10, "用户付款成功"), ADMIN_UPDATE_ADDRESS(11, "收货地址修改"), ADMIN_DELIVERY(20, "已发货,快递公司:{deliveryName},快递单号:{logisticsNo}"), 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 4065ed05e..c5ab35d62 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 @@ -631,7 +631,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 2. 更新订单 tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId()) - .setAdjustPrice(reqVO.getAdjustPrice()).setPayPrice(newPayPrice)); + .setAdjustPrice(reqVO.getAdjustPrice() + order.getAdjustPrice()).setPayPrice(newPayPrice)); // 3. 更新 TradeOrderItem,需要做 adjustPrice 的分摊 List orderOrderItems = tradeOrderItemMapper.selectListByOrderId(order.getId()); @@ -639,9 +639,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { 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)) + updateItems.add(new TradeOrderItemDO().setId(item.getId()).setAdjustPrice(item.getAdjustPrice() + dividePrices.get(i)) .setPayPrice((item.getPayPrice() - item.getAdjustPrice()) + dividePrices.get(i))); } tradeOrderItemMapper.updateBatch(updateItems); @@ -652,6 +650,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 5. 记录订单日志 TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), order.getStatus(), MapUtil.builder().put("oldPayPrice", MoneyUtils.fenToYuanStr(order.getPayPrice())) + .put("adjustPrice", MoneyUtils.fenToYuanStr(reqVO.getAdjustPrice())) .put("newPayPrice", MoneyUtils.fenToYuanStr(newPayPrice)).build()); } 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 850226fbb..2862012af 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 @@ -245,7 +245,7 @@ public class TradePriceCalculatorHelper { * @return 分摊金额数组,和传入的 orderItems 一一对应 */ public static List dividePrice2(List items, Integer price) { - Integer total = getSumValue(items, TradeOrderItemDO::getPrice, Integer::sum); + Integer total = getSumValue(items, TradeOrderItemDO::getPayPrice, Integer::sum); assert total != null; // 遍历每一个,进行分摊 List prices = new ArrayList<>(items.size()); @@ -254,15 +254,11 @@ public class TradePriceCalculatorHelper { TradeOrderItemDO orderItem = items.get(i); int partPrice; if (i < items.size() - 1) { // 减一的原因,是因为拆分时,如果按照比例,可能会出现.所以最后一个,使用反减 - // partPrice = (int) (price * (1.0D * orderItem.getPayPrice() / total)); - // pr fix: 改为了使用订单原价来计算比例 partPrice = (int) (price * (1.0D * orderItem.getPrice() / total)); remainPrice -= partPrice; } else { partPrice = remainPrice; } - // TODO puhui999: 如果是减价的情况这里过不了 - // Assert.isTrue(partPrice >= 0, "分摊金额必须大于等于 0"); prices.add(partPrice); } return prices;