mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 01:01:52 +08:00
MALL: fix 订单价格分摊
This commit is contained in:
parent
d556b29214
commit
0dd36f6c5c
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user