fix: 订单详情增加可退款金额

This commit is contained in:
张松
2024-11-23 17:09:48 +08:00
parent d390054f07
commit 3eef65777a
2 changed files with 27 additions and 0 deletions

View File

@@ -50,5 +50,6 @@ public class TbOrderDetail implements Serializable {
private static final long serialVersionUID = 1L;
private Integer isMember;
private String useCouponInfo;
private BigDecimal canReturnAmount;
}

View File

@@ -1525,6 +1525,10 @@ public class CartService {
orderInfo.setCouponInfoList(JSONObject.toJSONString(infoDTO));
}
// 计算可退款金额
updateOrderDetailCanReturn(detailPriceDTO.getOrderDetailList(), orderInfo);
// 修改订单详情并打票
updateDetailAndPrint(orderInfo, detailPriceDTO, shopEatTypeInfoDTO, orderDTO.isOnlyChangeCoupon());
@@ -1558,6 +1562,28 @@ public class CartService {
}
}
private void updateOrderDetailCanReturn(List<TbOrderDetail> orderDetailList, TbOrderInfo orderInfo) {
orderDetailList = orderDetailList.stream().filter(item -> TableConstant.OrderInfo.Status.UNPAID.equalsVals(item.getStatus())).collect(Collectors.toList());
BigDecimal totalAmount = BigDecimal.ZERO;
BigDecimal lastAmount = BigDecimal.ZERO;
BigDecimal lastReturnAmount = BigDecimal.ZERO;
BigDecimal orderAmount = orderInfo.getOrderAmount();
for (TbOrderDetail orderDetail : orderDetailList) {
totalAmount = totalAmount.add(orderDetail.getPriceAmount());
}
for (TbOrderDetail item : orderDetailList) {
if (StrUtil.isNotBlank(orderInfo.getCouponInfoList()) || orderInfo.getPointsNum() != null) {
BigDecimal canReturnAmount = item.getPriceAmount().divide(totalAmount.subtract(lastAmount), 10, RoundingMode.HALF_DOWN)
.multiply(orderAmount.subtract(lastReturnAmount)).setScale(2, RoundingMode.HALF_DOWN);
lastReturnAmount = canReturnAmount;
lastAmount = item.getPriceAmount();
item.setCanReturnAmount(canReturnAmount);
}else {
item.setCanReturnAmount(item.getPriceAmount());
}
}
}
private void returnCoupon(TbOrderInfo orderInfo) {
// 返还优惠券
PayService.returnCoupon(orderInfo, shopCouponService, mpCashierCartMapper);