update 会员组计算折扣逻辑

This commit is contained in:
Lemon
2024-01-13 15:28:02 +08:00
parent 54e6a00a79
commit 1363042a2f
2 changed files with 100 additions and 10 deletions

View File

@@ -744,6 +744,9 @@ public abstract class AbstractProgramLogic implements InitializingBean {
// 服务费折扣金额
BigDecimal discountServiceAmount = BigDecimal.ZERO;
BigDecimal afterServiceAmountDiscount = BigDecimal.ZERO;
BigDecimal afterElectricityAmountDiscount = BigDecimal.ZERO;
// 查询会员在此站点会员折扣
MemberDiscountVO memberDiscountVO = memberGroupService.queryMemberDiscount(merchantId, stationId, memberId);
if (memberDiscountVO != null) {
@@ -752,16 +755,28 @@ public abstract class AbstractProgramLogic implements InitializingBean {
BigDecimal totalElectricityAmount = orderDetail.getTotalElectricityAmount(); // 电费
BigDecimal totalServiceAmount = orderDetail.getTotalServiceAmount(); // 服务费
BigDecimal afterServiceAmountDiscount = totalServiceAmount.multiply(discount).setScale(2, RoundingMode.DOWN);
BigDecimal afterElectricityAmountDiscount = totalElectricityAmount.multiply(discount).setScale(2, RoundingMode.DOWN);
// 未进行打折前
afterServiceAmountDiscount = totalServiceAmount;
afterElectricityAmountDiscount = totalElectricityAmount;
if (Constants.ONE.equals(groupType)) {
// 服务费折扣
afterServiceAmountDiscount = totalServiceAmount.multiply(discount).setScale(4, RoundingMode.DOWN);
discountServiceAmount = totalServiceAmount.subtract(afterServiceAmountDiscount);
} else if (Constants.TWO.equals(groupType)) {
// 电费折扣
afterElectricityAmountDiscount = totalElectricityAmount.multiply(discount).setScale(4, RoundingMode.DOWN);
discountElectricityAmount = totalElectricityAmount.subtract(afterElectricityAmountDiscount);
} else {
// BigDecimal afterServiceAmountDiscount = totalServiceAmount.multiply(discount).setScale(2, RoundingMode.DOWN);
discountServiceAmount = totalServiceAmount.subtract(afterServiceAmountDiscount);
// discountServiceAmount = totalServiceAmount.subtract(afterServiceAmountDiscount);
// BigDecimal afterElectricityAmountDiscount = totalElectricityAmount.multiply(discount).setScale(2, RoundingMode.DOWN);
// discountElectricityAmount = totalElectricityAmount.subtract(afterElectricityAmountDiscount);
// 电费和服务费一起折扣
afterServiceAmountDiscount = totalServiceAmount.multiply(discount).setScale(4, RoundingMode.DOWN);
afterElectricityAmountDiscount = totalElectricityAmount.multiply(discount).setScale(4, RoundingMode.DOWN);
discountServiceAmount = totalServiceAmount.subtract(afterServiceAmountDiscount);
discountElectricityAmount = totalElectricityAmount.subtract(afterElectricityAmountDiscount);
}
}
@@ -769,12 +784,18 @@ public abstract class AbstractProgramLogic implements InitializingBean {
BigDecimal discountAmount = discountServiceAmount.add(discountElectricityAmount);
orderBasicInfo.setDiscountAmount(discountAmount);
// 更新退款金额 = 退款金额 - 折扣金额
BigDecimal refundAmount = orderBasicInfo.getRefundAmount().subtract(discountAmount);
// BigDecimal refundAmount = orderBasicInfo.getRefundAmount().subtract(discountAmount);
// 总消费金额 = 折扣后电费 + 折扣后服务费
BigDecimal totalConsumeAmount = afterServiceAmountDiscount.add(afterElectricityAmountDiscount);
// 更新退款金额
BigDecimal refundAmount = orderBasicInfo.getPayAmount().subtract(totalConsumeAmount).setScale(2, RoundingMode.DOWN);
orderBasicInfo.setRefundAmount(refundAmount);
orderDetail.setDiscountElectricityAmount(discountElectricityAmount);
orderDetail.setDiscountServiceAmount(discountServiceAmount);
logger.info("计算订单折扣, orderCode:{}, memberId:{}, discountAmount:{}, discountElectricityAmount:{}, discountServiceAmount:{}",
orderBasicInfo.getOrderCode(), memberId, discountAmount, discountElectricityAmount, discountServiceAmount);
logger.info("计算订单折扣, orderCode:{}, memberId:{}, discountAmount:{}, discountElectricityAmount:{}, discountServiceAmount:{}, totalConsumeAmount:{}",
orderBasicInfo.getOrderCode(), memberId, discountAmount, discountElectricityAmount, discountServiceAmount, totalConsumeAmount);
}
/**