MALL: fix 订单价格分摊

This commit is contained in:
puhui999 2024-03-10 19:07:24 +08:00
parent d556b29214
commit 0dd36f6c5c
2 changed files with 10 additions and 5 deletions

View File

@ -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<TradeOrderItemDO> orderOrderItems = tradeOrderItemMapper.selectListByOrderId(order.getId());
List<Integer> dividePrices = TradePriceCalculatorHelper.dividePrice2(orderOrderItems, newPayPrice);
List<Integer> dividePrices = TradePriceCalculatorHelper.dividePrice2(orderOrderItems, reqVO.getAdjustPrice());
List<TradeOrderItemDO> 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);

View File

@ -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;