fix: 退款比例修改,返还积分修改

This commit is contained in:
张松 2024-11-23 14:28:14 +08:00
parent 9744aa3c9a
commit 514533bfed
1 changed files with 36 additions and 22 deletions

View File

@ -2867,7 +2867,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
throw new BadRequestException("退款金额为负数有误"); throw new BadRequestException("退款金额为负数有误");
} }
if (hasNormalReturn && returnAmount.compareTo(new BigDecimal("0.01")) <= 0 && oldOrderInfo.getPayAmount().compareTo(BigDecimal.ZERO) != 0) { if (hasNormalReturn && returnAmount.compareTo(new BigDecimal("0")) <= 0 && oldOrderInfo.getPayAmount().compareTo(BigDecimal.ZERO) != 0) {
throw new BadRequestException("退款金额必须大于0"); throw new BadRequestException("退款金额必须大于0");
} }
@ -2922,12 +2922,17 @@ public class TbShopTableServiceImpl implements TbShopTableService {
totalAmount = totalAmount.add(item.getPriceAmount()); totalAmount = totalAmount.add(item.getPriceAmount());
} }
} }
if (orderDetail.getPriceAmount().compareTo(totalAmount) == 0) { if (orderDetail.getPriceAmount().compareTo(totalAmount) == 0 && orderDetail.getNum().compareTo(BigDecimal.ONE) == 0) {
return BigDecimal.ONE; return BigDecimal.ONE;
} }
if (orderDetail.getNum().compareTo(returnNum) == 0) {
return orderDetail.getPriceAmount().divide(totalAmount, 2, RoundingMode.HALF_DOWN);
}
return orderDetail.getPriceAmount().divide(totalAmount, 10, RoundingMode.HALF_DOWN) return orderDetail.getPriceAmount().divide(totalAmount, 10, RoundingMode.HALF_DOWN)
.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 void updateStockAndRecord(List<TbOrderDetail> orderDetailList) { private void updateStockAndRecord(List<TbOrderDetail> orderDetailList) {
@ -3013,26 +3018,35 @@ public class TbShopTableServiceImpl implements TbShopTableService {
// 订单金额全退退优惠券以及积分 // 订单金额全退退优惠券以及积分
if (orderInfo.getPayAmount().compareTo(orderInfo.getRefundAmount()) <= 0) { if (orderInfo.getPayAmount().compareTo(orderInfo.getRefundAmount()) <= 0) {
String couponInfoList = orderInfo.getCouponInfoList(); long count = mpOrderDetailService.count(new LambdaQueryWrapper<TbOrderDetail>()
if (StrUtil.isNotBlank(couponInfoList)) { .eq(TbOrderDetail::getOrderId, orderInfo.getId())
OrderInfoCouponInfoDTO orderInfoCouponInfoDTO = JSONObject.parseObject(couponInfoList, OrderInfoCouponInfoDTO.class); .eq(TbOrderDetail::getStatus, TableConstant.OrderInfo.Status.CLOSED));
if (orderInfoCouponInfoDTO.getProductCoupon() != null && !orderInfoCouponInfoDTO.getProductCoupon().isEmpty()) { if (count == 0) {
int remainNum = 0; returnCoupon(orderInfo, true);
for (OrderInfoUserCouponVo item : orderInfoCouponInfoDTO.getProductCoupon()) { // 返还积分
if (item.getFinalUseNum() > item.getReturnNum()) { memberPointsService.addPoints(Long.valueOf(orderInfo.getMemberId()), orderInfo.getPointsNum(),
remainNum = remainNum + (item.getFinalUseNum() - item.getReturnNum()); "用户退款订单积分返还: " + orderInfo.getPointsNum() + "积分", Long.valueOf(orderInfo.getId()));
}
}
if (remainNum == 0) {
returnCoupon(orderInfo, true);
// 返还积分
memberPointsService.addPoints(Long.valueOf(orderInfo.getMemberId()), orderInfo.getPointsNum(),
"用户退款订单积分返还: " + orderInfo.getPointsNum() + "积分", Long.valueOf(orderInfo.getId()));
}
}
} }
// String couponInfoList = orderInfo.getCouponInfoList();
// if (StrUtil.isNotBlank(couponInfoList)) {
// OrderInfoCouponInfoDTO orderInfoCouponInfoDTO = JSONObject.parseObject(couponInfoList, OrderInfoCouponInfoDTO.class);
// if (orderInfoCouponInfoDTO.getProductCoupon() != null && !orderInfoCouponInfoDTO.getProductCoupon().isEmpty()) {
// int remainNum = 0;
// for (OrderInfoUserCouponVo item : orderInfoCouponInfoDTO.getProductCoupon()) {
// if (item.getFinalUseNum() > item.getReturnNum()) {
// remainNum = remainNum + (item.getFinalUseNum() - item.getReturnNum());
// }
// }
//
// if (remainNum == 0) {
// returnCoupon(orderInfo, true);
// // 返还积分
// memberPointsService.addPoints(Long.valueOf(orderInfo.getMemberId()), orderInfo.getPointsNum(),
// "用户退款订单积分返还: " + orderInfo.getPointsNum() + "积分", Long.valueOf(orderInfo.getId()));
//
// }
// }
// }
} }
orderInfoMapper.updateById(orderInfo); orderInfoMapper.updateById(orderInfo);
// 打印退款小票 // 打印退款小票