fix: 创建订单返还积分

This commit is contained in:
张松
2024-11-22 13:39:24 +08:00
parent 7a0e0f1343
commit 836b384f9c

View File

@@ -913,26 +913,32 @@ public class CartService {
} }
} }
private BigDecimal calcPointsDiscountAndReturn(TbOrderInfo orderInfo, int pointsNum) { private BigDecimal calcPointsDiscountAndReturn(TbOrderInfo orderInfo, Integer pointsNum) {
Long memberId = Long.valueOf(orderInfo.getMemberId()); Long memberId = Long.valueOf(orderInfo.getMemberId());
if (orderInfo.getPointsNum() != null && orderInfo.getPointsNum() != 0) { if (orderInfo.getPointsNum() != null && orderInfo.getPointsNum() != 0) {
memberPointsService.addPoints(memberId, orderInfo.getPointsNum(), "用户未支付订单积分返还: " + orderInfo.getPointsNum() + "积分", Long.valueOf(orderInfo.getId()), orderInfo.getOrderNo()); memberPointsService.addPoints(memberId, orderInfo.getPointsNum(), "用户未支付订单积分返还: " + orderInfo.getPointsNum() + "积分", Long.valueOf(orderInfo.getId()), orderInfo.getOrderNo());
orderInfo.setPointsNum(0);
orderInfo.setPointsDiscountAmount(BigDecimal.ZERO);
} }
OrderDeductionPointsDTO memberUsablePoints = memberPointsService.getMemberUsablePoints(memberId, orderInfo.getOrderAmount()); if (pointsNum != null) {
if (!memberUsablePoints.getUsable()) { OrderDeductionPointsDTO memberUsablePoints = memberPointsService.getMemberUsablePoints(memberId, orderInfo.getOrderAmount());
throw new MsgException(memberUsablePoints.getUnusableReason()); if (!memberUsablePoints.getUsable()) {
} throw new MsgException(memberUsablePoints.getUnusableReason());
if (pointsNum < memberUsablePoints.getMinDeductionPoints() || pointsNum > memberUsablePoints.getMaxUsablePoints()) { }
throw new MsgException("可抵扣积分区间为: [" + memberUsablePoints.getMinDeductionPoints() + "-" + memberUsablePoints.getMaxUsablePoints() + "]"); if (pointsNum < memberUsablePoints.getMinDeductionPoints() || pointsNum > memberUsablePoints.getMaxUsablePoints()) {
} throw new MsgException("可抵扣积分区间为: [" + memberUsablePoints.getMinDeductionPoints() + "-" + memberUsablePoints.getMaxUsablePoints() + "]");
}
BigDecimal discountAmount = memberPointsService.calcDeductionAmount(memberId, orderInfo.getOrderAmount(), pointsNum); BigDecimal discountAmount = memberPointsService.calcDeductionAmount(memberId, orderInfo.getOrderAmount(), pointsNum);
orderInfo.setPointsNum(pointsNum); orderInfo.setPointsNum(pointsNum);
orderInfo.setPointsDiscountAmount(discountAmount); orderInfo.setPointsDiscountAmount(discountAmount);
memberPointsService.deductPoints(memberId, pointsNum, "订单积分抵扣" + discountAmount + "", Long.valueOf(orderInfo.getId())); memberPointsService.deductPoints(memberId, pointsNum, "订单积分抵扣" + discountAmount + "", Long.valueOf(orderInfo.getId()));
return discountAmount; return discountAmount;
}else {
return null;
}
} }
private TbActivateOutRecord calcOrderInfoDiscount(CreateOrderDTO orderDTO, TbOrderInfo orderInfo, OrderCouponInfoDTO couponInfo, Integer memberId) { private TbActivateOutRecord calcOrderInfoDiscount(CreateOrderDTO orderDTO, TbOrderInfo orderInfo, OrderCouponInfoDTO couponInfo, Integer memberId) {
@@ -957,8 +963,8 @@ public class CartService {
} }
// 计算积分优惠 // 计算积分优惠
if (orderDTO.getPointsNum() != null && orderDTO.getPointsNum() != 0) { BigDecimal discountPointsAmount = calcPointsDiscountAndReturn(orderInfo, orderDTO.getPointsNum());
BigDecimal discountPointsAmount = calcPointsDiscountAndReturn(orderInfo, orderDTO.getPointsNum()); if (discountPointsAmount != null) {
finalAmount = finalAmount.subtract(discountPointsAmount); finalAmount = finalAmount.subtract(discountPointsAmount);
orderInfo.setPointsDiscountAmount(discountPointsAmount); orderInfo.setPointsDiscountAmount(discountPointsAmount);
} }
@@ -1263,7 +1269,6 @@ public class CartService {
// 更新购物车信息 // 更新购物车信息
if (!resetCouponList.isEmpty()) { if (!resetCouponList.isEmpty()) {
// 取消之前使用的历史券 // 取消之前使用的历史券
ArrayList<Integer> resetCartIds = new ArrayList<>(); ArrayList<Integer> resetCartIds = new ArrayList<>();
resetCouponList.forEach(item -> { resetCouponList.forEach(item -> {
if (item.getUserCouponId() == null) { if (item.getUserCouponId() == null) {