fix: 退款增加可退款金额

This commit is contained in:
张松 2024-11-23 16:53:31 +08:00
parent a470d8c472
commit d555f66d3a
2 changed files with 39 additions and 5 deletions

View File

@ -135,6 +135,7 @@ public class TbOrderDetail implements Serializable {
private Boolean isPrint;
private String useCouponInfo;
private BigDecimal returnAmount;
private BigDecimal canReturnAmount;
public void copy(TbOrderDetail source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));

View File

@ -2111,6 +2111,28 @@ public class TbShopTableServiceImpl implements TbShopTableService {
return productDiscount;
}
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 BigDecimal calcDiscountAndUpdateInfo(PayDTO payDTO, TbOrderInfo orderInfo) {
// 返还上次使用的券
returnCoupon(orderInfo, true);
@ -2178,6 +2200,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
// orderInfo.setCouponInfoList(JSONObject.toJSONString(couponInfo));
// 修改订单detail
updateOrderDetailCanReturn(priceDTO.getOrderDetailList(), orderInfo);
mpOrderDetailService.saveOrUpdateBatch(priceDTO.getOrderDetailList());
return orderInfo.getOrderAmount();
}
@ -2803,6 +2826,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
} else if (oldOrderInfo.getFullCouponDiscountAmount().compareTo(BigDecimal.ZERO) > 0 || oldOrderInfo.getPointsDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
hasNormalReturn = true;
// 计算当前商品占比
returnAmount = calcDetailReturnAmount(orderDetail, returnNum);
BigDecimal ratio = calcDetailRatio(orderDetail, returnNum);
currentDetailAMount = orderDetail.getPriceAmount().divide(orderDetail.getNum(), 8, RoundingMode.HALF_UP)
.multiply(returnNum).setScale(2, RoundingMode.HALF_DOWN);
@ -2810,11 +2834,11 @@ public class TbShopTableServiceImpl implements TbShopTableService {
oldOrderInfo.setRefundAmount(BigDecimal.ZERO);
}
if (ratio.compareTo(BigDecimal.ONE) == 0) {
returnAmount = oldOrderInfo.getPayAmount().subtract(oldOrderInfo.getRefundAmount());
}else {
returnAmount = returnAmount.add(oldOrderInfo.getPayAmount().subtract(oldOrderInfo.getRefundAmount()).multiply(ratio));
}
// if (ratio.compareTo(BigDecimal.ONE) == 0) {
// returnAmount = oldOrderInfo.getPayAmount().subtract(oldOrderInfo.getRefundAmount());
// }else {
// returnAmount = returnAmount.add(oldOrderInfo.getPayAmount().subtract(oldOrderInfo.getRefundAmount()).multiply(ratio));
// }
saleAmount = saleAmount.add(orderDetail.getPrice());
packAMount = packAMount.add(orderDetail.getPackAmount()
.divide(orderDetail.getNum(), 8, RoundingMode.HALF_UP)
@ -2846,7 +2870,9 @@ public class TbShopTableServiceImpl implements TbShopTableService {
remainOrderDetail.setPackAmount(originalPackAmount.subtract(returnPackFee));
remainOrderDetail.setReturnNum("0");
remainOrderDetail.setId(null);
remainOrderDetail.setCanReturnAmount(remainOrderDetail.getCanReturnAmount().subtract(returnAmount));
remainOrderDetailList.add(remainOrderDetail);
orderDetail.setCanReturnAmount(returnAmount);
}
orderDetail.setNum(returnNum);
@ -2926,6 +2952,13 @@ public class TbShopTableServiceImpl implements TbShopTableService {
.divide(orderDetail.getNum(), 10, RoundingMode.HALF_DOWN).multiply(returnNum).setScale(2, RoundingMode.HALF_DOWN);
}
private BigDecimal calcDetailReturnAmount(TbOrderDetail orderDetail, BigDecimal returnNum) {
if (orderDetail.getNum().compareTo(returnNum) == 0) {
return orderDetail.getCanReturnAmount();
}
return orderDetail.getCanReturnAmount().divide(orderDetail.getNum(), 10, RoundingMode.HALF_DOWN).multiply(returnNum).setScale(2, RoundingMode.HALF_DOWN);
}
private void updateStockAndRecord(List<TbOrderDetail> orderDetailList) {
// 更新商品库存
for (TbOrderDetail detail : orderDetailList) {