fix: 退款增加可退款金额
This commit is contained in:
parent
a470d8c472
commit
d555f66d3a
|
|
@ -135,6 +135,7 @@ public class TbOrderDetail implements Serializable {
|
||||||
private Boolean isPrint;
|
private Boolean isPrint;
|
||||||
private String useCouponInfo;
|
private String useCouponInfo;
|
||||||
private BigDecimal returnAmount;
|
private BigDecimal returnAmount;
|
||||||
|
private BigDecimal canReturnAmount;
|
||||||
|
|
||||||
public void copy(TbOrderDetail source){
|
public void copy(TbOrderDetail source){
|
||||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||||
|
|
|
||||||
|
|
@ -2111,6 +2111,28 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
return productDiscount;
|
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) {
|
private BigDecimal calcDiscountAndUpdateInfo(PayDTO payDTO, TbOrderInfo orderInfo) {
|
||||||
// 返还上次使用的券
|
// 返还上次使用的券
|
||||||
returnCoupon(orderInfo, true);
|
returnCoupon(orderInfo, true);
|
||||||
|
|
@ -2178,6 +2200,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
// orderInfo.setCouponInfoList(JSONObject.toJSONString(couponInfo));
|
// orderInfo.setCouponInfoList(JSONObject.toJSONString(couponInfo));
|
||||||
|
|
||||||
// 修改订单detail
|
// 修改订单detail
|
||||||
|
updateOrderDetailCanReturn(priceDTO.getOrderDetailList(), orderInfo);
|
||||||
mpOrderDetailService.saveOrUpdateBatch(priceDTO.getOrderDetailList());
|
mpOrderDetailService.saveOrUpdateBatch(priceDTO.getOrderDetailList());
|
||||||
return orderInfo.getOrderAmount();
|
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) {
|
} else if (oldOrderInfo.getFullCouponDiscountAmount().compareTo(BigDecimal.ZERO) > 0 || oldOrderInfo.getPointsDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||||
hasNormalReturn = true;
|
hasNormalReturn = true;
|
||||||
// 计算当前商品占比
|
// 计算当前商品占比
|
||||||
|
returnAmount = calcDetailReturnAmount(orderDetail, returnNum);
|
||||||
BigDecimal ratio = calcDetailRatio(orderDetail, returnNum);
|
BigDecimal ratio = calcDetailRatio(orderDetail, returnNum);
|
||||||
currentDetailAMount = orderDetail.getPriceAmount().divide(orderDetail.getNum(), 8, RoundingMode.HALF_UP)
|
currentDetailAMount = orderDetail.getPriceAmount().divide(orderDetail.getNum(), 8, RoundingMode.HALF_UP)
|
||||||
.multiply(returnNum).setScale(2, RoundingMode.HALF_DOWN);
|
.multiply(returnNum).setScale(2, RoundingMode.HALF_DOWN);
|
||||||
|
|
@ -2810,11 +2834,11 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
oldOrderInfo.setRefundAmount(BigDecimal.ZERO);
|
oldOrderInfo.setRefundAmount(BigDecimal.ZERO);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ratio.compareTo(BigDecimal.ONE) == 0) {
|
// if (ratio.compareTo(BigDecimal.ONE) == 0) {
|
||||||
returnAmount = oldOrderInfo.getPayAmount().subtract(oldOrderInfo.getRefundAmount());
|
// returnAmount = oldOrderInfo.getPayAmount().subtract(oldOrderInfo.getRefundAmount());
|
||||||
}else {
|
// }else {
|
||||||
returnAmount = returnAmount.add(oldOrderInfo.getPayAmount().subtract(oldOrderInfo.getRefundAmount()).multiply(ratio));
|
// returnAmount = returnAmount.add(oldOrderInfo.getPayAmount().subtract(oldOrderInfo.getRefundAmount()).multiply(ratio));
|
||||||
}
|
// }
|
||||||
saleAmount = saleAmount.add(orderDetail.getPrice());
|
saleAmount = saleAmount.add(orderDetail.getPrice());
|
||||||
packAMount = packAMount.add(orderDetail.getPackAmount()
|
packAMount = packAMount.add(orderDetail.getPackAmount()
|
||||||
.divide(orderDetail.getNum(), 8, RoundingMode.HALF_UP)
|
.divide(orderDetail.getNum(), 8, RoundingMode.HALF_UP)
|
||||||
|
|
@ -2846,7 +2870,9 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
remainOrderDetail.setPackAmount(originalPackAmount.subtract(returnPackFee));
|
remainOrderDetail.setPackAmount(originalPackAmount.subtract(returnPackFee));
|
||||||
remainOrderDetail.setReturnNum("0");
|
remainOrderDetail.setReturnNum("0");
|
||||||
remainOrderDetail.setId(null);
|
remainOrderDetail.setId(null);
|
||||||
|
remainOrderDetail.setCanReturnAmount(remainOrderDetail.getCanReturnAmount().subtract(returnAmount));
|
||||||
remainOrderDetailList.add(remainOrderDetail);
|
remainOrderDetailList.add(remainOrderDetail);
|
||||||
|
orderDetail.setCanReturnAmount(returnAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
orderDetail.setNum(returnNum);
|
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);
|
.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) {
|
private void updateStockAndRecord(List<TbOrderDetail> orderDetailList) {
|
||||||
// 更新商品库存
|
// 更新商品库存
|
||||||
for (TbOrderDetail detail : orderDetailList) {
|
for (TbOrderDetail detail : orderDetailList) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue