乱七八糟折扣计算

This commit is contained in:
2025-10-24 15:59:20 +08:00
parent 69c0de7651
commit fa868f6414
3 changed files with 39 additions and 4 deletions

View File

@@ -102,6 +102,10 @@ public class CheckOrderPay implements Serializable {
* 积分抵扣金额(tb_points_basic_setting表) * 积分抵扣金额(tb_points_basic_setting表)
*/ */
private BigDecimal pointsDiscountAmount; private BigDecimal pointsDiscountAmount;
/**
* 会员折扣减免金额
*/
private BigDecimal vipDiscountAmount;
/** /**
* 使用的积分数量 (扣除各类折扣 enable_deduction后使用) * 使用的积分数量 (扣除各类折扣 enable_deduction后使用)
@@ -161,6 +165,10 @@ public class CheckOrderPay implements Serializable {
return roundAmount == null ? BigDecimal.ZERO : roundAmount; return roundAmount == null ? BigDecimal.ZERO : roundAmount;
} }
public BigDecimal getVipDiscountAmount(){
return vipDiscountAmount == null ? BigDecimal.ZERO : vipDiscountAmount;
}
public boolean isVipPrice() { public boolean isVipPrice() {
return vipPrice != null && vipPrice == 1; return vipPrice != null && vipPrice == 1;

View File

@@ -112,6 +112,10 @@ public class OrderInfo implements Serializable {
* 其它优惠券抵扣金额 * 其它优惠券抵扣金额
*/ */
private BigDecimal otherCouponDiscountAmount; private BigDecimal otherCouponDiscountAmount;
/**
* 会员折扣金额
*/
private BigDecimal vipDiscountAmount;
/** /**
* 折扣金额 * 折扣金额
@@ -290,6 +294,8 @@ public class OrderInfo implements Serializable {
private String failMsg; private String failMsg;
public String getRefundRemark() { public String getRefundRemark() {
return StrUtil.isBlank(refundRemark) ? "" : refundRemark + " "; return StrUtil.isBlank(refundRemark) ? "" : refundRemark + " ";
} }
@@ -298,6 +304,10 @@ public class OrderInfo implements Serializable {
return newCustomerDiscountAmount == null ? BigDecimal.ZERO : newCustomerDiscountAmount; return newCustomerDiscountAmount == null ? BigDecimal.ZERO : newCustomerDiscountAmount;
} }
public BigDecimal getVipDiscountAmount() {
return vipDiscountAmount == null ? BigDecimal.ZERO : vipDiscountAmount;
}
public BigDecimal getOriginAmount() { public BigDecimal getOriginAmount() {
return originAmount == null ? BigDecimal.ZERO : originAmount; return originAmount == null ? BigDecimal.ZERO : originAmount;
} }

View File

@@ -400,8 +400,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
} }
orderInfo.setUserId(userInfo.getId()); orderInfo.setUserId(userInfo.getId());
} }
//TODO 会员价开关 //会员价校验
if (param.isVipPrice() && (shopUser == null || shopUser.getIsVip().equals(0))) { if (param.isVipPrice() && (shopUser == null || shopUser.getIsMemberPrice() == 0 || shopUser.getIsVip().equals(0))) {
throw new ValidateException("生成支付订单失败,仅会员可使用会员价"); throw new ValidateException("生成支付订单失败,仅会员可使用会员价");
} }
@@ -477,8 +477,20 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
} }
newTotalAmount = newTotalAmount.subtract(discountActAmount); newTotalAmount = newTotalAmount.subtract(discountActAmount);
//TODO 会员整单折扣 //会员整单折扣
if (shopUser != null && shopUser.getDiscount() != null && shopUser.getDiscount() < 100 && shopUser.getDiscount() > 0) {
if (param.getVipDiscountAmount().compareTo(BigDecimal.ZERO) <= 0) {
param.setVipDiscountAmount(BigDecimal.ZERO);
} else {
BigDecimal discount = BigDecimal.valueOf(100).subtract(BigDecimal.valueOf(shopUser.getDiscount())).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP);
BigDecimal discountAmount = newTotalAmount.multiply(discount);
discountAmount = discountAmount.setScale(2, RoundingMode.HALF_UP);
if (discountAmount.compareTo(param.getVipDiscountAmount()) != 0) {
throw new ValidateException("生成支付订单失败,未满足积分抵扣最低门槛");
}
newTotalAmount = newTotalAmount.subtract(discountAmount);
}
}
//积分抵扣 金额范围校验 抵扣金额校验 //积分抵扣 金额范围校验 抵扣金额校验
if (param.getPointsNum() > 0) { if (param.getPointsNum() > 0) {
if (pointSetting.getMinPaymentAmount().compareTo(newTotalAmount) > 0) { if (pointSetting.getMinPaymentAmount().compareTo(newTotalAmount) > 0) {
@@ -1426,6 +1438,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
orderInfo.setCouponInfoList(CollUtil.isEmpty(param.getCouponList()) ? "" : JSONObject.toJSONString(param.getCouponList())); orderInfo.setCouponInfoList(CollUtil.isEmpty(param.getCouponList()) ? "" : JSONObject.toJSONString(param.getCouponList()));
//满减活动抵扣金额 //满减活动抵扣金额
orderInfo.setDiscountActAmount(param.getDiscountActAmount()); orderInfo.setDiscountActAmount(param.getDiscountActAmount());
//会员折扣金额
orderInfo.setVipDiscountAmount(param.getVipDiscountAmount());
//折扣信息 //折扣信息
orderInfo.setDiscountInfo(buildDiscountInfo(orderInfo)); orderInfo.setDiscountInfo(buildDiscountInfo(orderInfo));
//0元按照现金支付处理 //0元按照现金支付处理
@@ -1484,6 +1498,9 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
if (orderInfo.getDiscountActAmount() != null && orderInfo.getDiscountActAmount().compareTo(BigDecimal.ZERO) > 0) { if (orderInfo.getDiscountActAmount() != null && orderInfo.getDiscountActAmount().compareTo(BigDecimal.ZERO) > 0) {
jsonObject.put("满减活动抵扣", orderInfo.getDiscountActAmount()); jsonObject.put("满减活动抵扣", orderInfo.getDiscountActAmount());
} }
if (orderInfo.getVipDiscountAmount() != null && orderInfo.getVipDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
jsonObject.put("会员整单折扣", orderInfo.getVipDiscountAmount());
}
if (orderInfo.getOtherCouponDiscountAmount().compareTo(BigDecimal.ZERO) > 0) { if (orderInfo.getOtherCouponDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
jsonObject.put("其它优惠券折扣", orderInfo.getOtherCouponDiscountAmount()); jsonObject.put("其它优惠券折扣", orderInfo.getOtherCouponDiscountAmount());
} }