fix: 优惠券使用顺序调整

This commit is contained in:
张松 2024-11-18 11:40:40 +08:00
parent c3409461c8
commit 4821892a35
1 changed files with 13 additions and 9 deletions

View File

@ -2187,12 +2187,16 @@ public class TbShopTableServiceImpl implements TbShopTableService {
List<TbCashierCart> cashierCarts = mpCashierCartService.selectByOrderIdAndState(orderInfo.getId());
List<TbOrderDetail> detailList = mpOrderDetailService.selectByOrderId(orderInfo.getId());
BigDecimal discount = payDTO.getDiscount();
cashierCarts.forEach(item -> {
item.setTotalAmount(item.getTotalAmount().multiply(discount).setScale(2, RoundingMode.HALF_UP));
BigDecimal totalAmount = BigDecimal.ZERO;
for (TbCashierCart cashierCart : cashierCarts) {
if (cashierCart.getUserCouponId() == null) {
cashierCart.setTotalAmount(cashierCart.getTotalAmount().multiply(discount).setScale(2, RoundingMode.HALF_UP));
totalAmount = cashierCart.getTotalAmount();
}
// item.setSalePrice(item.getSalePrice().multiply(discount).setScale(2, RoundingMode.HALF_UP));
// item.setMemberPrice(item.getMemberPrice().multiply(discount).setScale(2, RoundingMode.HALF_UP));
});
}
detailList.forEach(item -> {
item.setPriceAmount(item.getPriceAmount().multiply(discount).setScale(2, RoundingMode.HALF_UP));
@ -2203,15 +2207,15 @@ public class TbShopTableServiceImpl implements TbShopTableService {
mpCashierCartService.updateBatchById(cashierCarts);
mpOrderDetailService.updateBatchById(detailList);
BigDecimal oldAmount = orderInfo.getOrderAmount();
BigDecimal finalAmount = orderInfo.getOrderAmount().multiply(payDTO.getDiscount()).setScale(2, RoundingMode.HALF_UP);
BigDecimal discountAmount = oldAmount.subtract(finalAmount);
// BigDecimal finalAmount = orderInfo.getOrderAmount().multiply(payDTO.getDiscount()).setScale(2, RoundingMode.HALF_UP);
BigDecimal discountAmount = oldAmount.subtract(totalAmount);
orderInfo.setDiscountAmount(discountAmount);
orderInfo.setDiscountRatio(payDTO.getDiscount());
orderInfo.setOrderAmount(finalAmount);
orderInfo.setAmount(finalAmount);
orderInfo.setSettlementAmount(finalAmount);
orderInfo.setOrderAmount(totalAmount);
orderInfo.setAmount(totalAmount);
orderInfo.setSettlementAmount(totalAmount);
mpOrderInfoService.updateById(orderInfo);
return finalAmount;
return totalAmount;
}
@Override