fix: 创建订单返还积分
This commit is contained in:
@@ -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());
|
||||
|
||||
if (orderInfo.getPointsNum() != null && orderInfo.getPointsNum() != 0) {
|
||||
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 (!memberUsablePoints.getUsable()) {
|
||||
throw new MsgException(memberUsablePoints.getUnusableReason());
|
||||
}
|
||||
if (pointsNum < memberUsablePoints.getMinDeductionPoints() || pointsNum > memberUsablePoints.getMaxUsablePoints()) {
|
||||
throw new MsgException("可抵扣积分区间为: [" + memberUsablePoints.getMinDeductionPoints() + "-" + memberUsablePoints.getMaxUsablePoints() + "]");
|
||||
}
|
||||
if (pointsNum != null) {
|
||||
OrderDeductionPointsDTO memberUsablePoints = memberPointsService.getMemberUsablePoints(memberId, orderInfo.getOrderAmount());
|
||||
if (!memberUsablePoints.getUsable()) {
|
||||
throw new MsgException(memberUsablePoints.getUnusableReason());
|
||||
}
|
||||
if (pointsNum < memberUsablePoints.getMinDeductionPoints() || pointsNum > memberUsablePoints.getMaxUsablePoints()) {
|
||||
throw new MsgException("可抵扣积分区间为: [" + memberUsablePoints.getMinDeductionPoints() + "-" + memberUsablePoints.getMaxUsablePoints() + "]");
|
||||
}
|
||||
|
||||
BigDecimal discountAmount = memberPointsService.calcDeductionAmount(memberId, orderInfo.getOrderAmount(), pointsNum);
|
||||
orderInfo.setPointsNum(pointsNum);
|
||||
orderInfo.setPointsDiscountAmount(discountAmount);
|
||||
memberPointsService.deductPoints(memberId, pointsNum, "订单积分抵扣" + discountAmount + "元", Long.valueOf(orderInfo.getId()));
|
||||
return discountAmount;
|
||||
BigDecimal discountAmount = memberPointsService.calcDeductionAmount(memberId, orderInfo.getOrderAmount(), pointsNum);
|
||||
orderInfo.setPointsNum(pointsNum);
|
||||
orderInfo.setPointsDiscountAmount(discountAmount);
|
||||
memberPointsService.deductPoints(memberId, pointsNum, "订单积分抵扣" + discountAmount + "元", Long.valueOf(orderInfo.getId()));
|
||||
return discountAmount;
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
orderInfo.setPointsDiscountAmount(discountPointsAmount);
|
||||
}
|
||||
@@ -1263,7 +1269,6 @@ public class CartService {
|
||||
// 更新购物车信息
|
||||
if (!resetCouponList.isEmpty()) {
|
||||
// 取消之前使用的历史券
|
||||
|
||||
ArrayList<Integer> resetCartIds = new ArrayList<>();
|
||||
resetCouponList.forEach(item -> {
|
||||
if (item.getUserCouponId() == null) {
|
||||
|
||||
Reference in New Issue
Block a user