【修复】商城系统:管理后台修改待支付订单,调整价格取值错误
This commit is contained in:
parent
dae4e64a64
commit
f9a50116bc
@ -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}"),
|
||||
|
@ -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<TradeOrderItemDO> orderOrderItems = tradeOrderItemMapper.selectListByOrderId(order.getId());
|
||||
@ -639,9 +639,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
||||
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))
|
||||
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.<String, Object>builder().put("oldPayPrice", MoneyUtils.fenToYuanStr(order.getPayPrice()))
|
||||
.put("adjustPrice", MoneyUtils.fenToYuanStr(reqVO.getAdjustPrice()))
|
||||
.put("newPayPrice", MoneyUtils.fenToYuanStr(newPayPrice)).build());
|
||||
}
|
||||
|
||||
|
@ -245,7 +245,7 @@ public class TradePriceCalculatorHelper {
|
||||
* @return 分摊金额数组,和传入的 orderItems 一一对应
|
||||
*/
|
||||
public static List<Integer> dividePrice2(List<TradeOrderItemDO> items, Integer price) {
|
||||
Integer total = getSumValue(items, TradeOrderItemDO::getPrice, Integer::sum);
|
||||
Integer total = getSumValue(items, TradeOrderItemDO::getPayPrice, Integer::sum);
|
||||
assert total != null;
|
||||
// 遍历每一个,进行分摊
|
||||
List<Integer> 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;
|
||||
|
Loading…
Reference in New Issue
Block a user