mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-09 04:20:08 +08:00
update 会员组计算折扣逻辑
This commit is contained in:
@@ -65,10 +65,7 @@ import com.jsowell.pile.vo.base.MemberWalletVO;
|
|||||||
import com.jsowell.pile.vo.base.PileInfoVO;
|
import com.jsowell.pile.vo.base.PileInfoVO;
|
||||||
import com.jsowell.pile.vo.uniapp.MemberVO;
|
import com.jsowell.pile.vo.uniapp.MemberVO;
|
||||||
import com.jsowell.pile.vo.uniapp.PileConnectorDetailVO;
|
import com.jsowell.pile.vo.uniapp.PileConnectorDetailVO;
|
||||||
import com.jsowell.pile.vo.web.BalanceDeductionAmountVO;
|
import com.jsowell.pile.vo.web.*;
|
||||||
import com.jsowell.pile.vo.web.BillingTemplateVO;
|
|
||||||
import com.jsowell.pile.vo.web.OrderListVO;
|
|
||||||
import com.jsowell.pile.vo.web.PileDetailVO;
|
|
||||||
import com.jsowell.service.MemberService;
|
import com.jsowell.service.MemberService;
|
||||||
import com.jsowell.service.OrderService;
|
import com.jsowell.service.OrderService;
|
||||||
import com.jsowell.service.PileService;
|
import com.jsowell.service.PileService;
|
||||||
@@ -96,6 +93,7 @@ import org.springframework.util.StopWatch;
|
|||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@@ -243,6 +241,9 @@ public class SpringBootTestController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private MemberWalletInfoService memberWalletInfoService;
|
private MemberWalletInfoService memberWalletInfoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MemberGroupService memberGroupService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void queryPaymentRefundTest() {
|
public void queryPaymentRefundTest() {
|
||||||
String paymentId = "002212023122615542010585629628950949888";
|
String paymentId = "002212023122615542010585629628950949888";
|
||||||
@@ -276,6 +277,74 @@ public class SpringBootTestController {
|
|||||||
// System.out.println(future.toString());
|
// System.out.println(future.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDiscount() {
|
||||||
|
OrderBasicInfo orderBasicInfo = new OrderBasicInfo();
|
||||||
|
orderBasicInfo.setMemberId("12345678");
|
||||||
|
orderBasicInfo.setMerchantId("1");
|
||||||
|
orderBasicInfo.setStationId("19");
|
||||||
|
orderBasicInfo.setPayAmount(new BigDecimal("200"));
|
||||||
|
|
||||||
|
OrderDetail orderDetail = new OrderDetail();
|
||||||
|
orderDetail.setTotalElectricityAmount(new BigDecimal("3"));
|
||||||
|
orderDetail.setTotalServiceAmount(new BigDecimal("0.18"));
|
||||||
|
|
||||||
|
|
||||||
|
String memberId = orderBasicInfo.getMemberId(); // 会员id
|
||||||
|
String merchantId = orderBasicInfo.getMerchantId(); // 运营商id
|
||||||
|
String stationId = orderBasicInfo.getStationId(); // 站点id
|
||||||
|
|
||||||
|
// 电费折扣金额
|
||||||
|
BigDecimal discountElectricityAmount = BigDecimal.ZERO;
|
||||||
|
// 服务费折扣金额
|
||||||
|
BigDecimal discountServiceAmount = BigDecimal.ZERO;
|
||||||
|
|
||||||
|
BigDecimal afterServiceAmountDiscount = BigDecimal.ZERO;
|
||||||
|
BigDecimal afterElectricityAmountDiscount = BigDecimal.ZERO;
|
||||||
|
|
||||||
|
// 查询会员在此站点会员折扣
|
||||||
|
MemberDiscountVO memberDiscountVO = memberGroupService.queryMemberDiscount(merchantId, stationId, memberId);
|
||||||
|
if (memberDiscountVO != null) {
|
||||||
|
BigDecimal discount = memberDiscountVO.getDiscount(); // 折扣率
|
||||||
|
String groupType = memberDiscountVO.getGroupType(); // 类型(1-服务费折扣,2-电费折扣 ,3-电费和服务费一起折扣)
|
||||||
|
BigDecimal totalElectricityAmount = orderDetail.getTotalElectricityAmount(); // 电费
|
||||||
|
BigDecimal totalServiceAmount = orderDetail.getTotalServiceAmount(); // 服务费
|
||||||
|
|
||||||
|
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);
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 订单折扣金额
|
||||||
|
BigDecimal discountAmount = discountServiceAmount.add(discountElectricityAmount);
|
||||||
|
orderBasicInfo.setDiscountAmount(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);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void queryPaymentByOrderNoTest() {
|
public void queryPaymentByOrderNoTest() {
|
||||||
|
|||||||
@@ -744,6 +744,9 @@ public abstract class AbstractProgramLogic implements InitializingBean {
|
|||||||
// 服务费折扣金额
|
// 服务费折扣金额
|
||||||
BigDecimal discountServiceAmount = BigDecimal.ZERO;
|
BigDecimal discountServiceAmount = BigDecimal.ZERO;
|
||||||
|
|
||||||
|
BigDecimal afterServiceAmountDiscount = BigDecimal.ZERO;
|
||||||
|
BigDecimal afterElectricityAmountDiscount = BigDecimal.ZERO;
|
||||||
|
|
||||||
// 查询会员在此站点会员折扣
|
// 查询会员在此站点会员折扣
|
||||||
MemberDiscountVO memberDiscountVO = memberGroupService.queryMemberDiscount(merchantId, stationId, memberId);
|
MemberDiscountVO memberDiscountVO = memberGroupService.queryMemberDiscount(merchantId, stationId, memberId);
|
||||||
if (memberDiscountVO != null) {
|
if (memberDiscountVO != null) {
|
||||||
@@ -752,16 +755,28 @@ public abstract class AbstractProgramLogic implements InitializingBean {
|
|||||||
BigDecimal totalElectricityAmount = orderDetail.getTotalElectricityAmount(); // 电费
|
BigDecimal totalElectricityAmount = orderDetail.getTotalElectricityAmount(); // 电费
|
||||||
BigDecimal totalServiceAmount = orderDetail.getTotalServiceAmount(); // 服务费
|
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)) {
|
if (Constants.ONE.equals(groupType)) {
|
||||||
|
// 服务费折扣
|
||||||
|
afterServiceAmountDiscount = totalServiceAmount.multiply(discount).setScale(4, RoundingMode.DOWN);
|
||||||
discountServiceAmount = totalServiceAmount.subtract(afterServiceAmountDiscount);
|
discountServiceAmount = totalServiceAmount.subtract(afterServiceAmountDiscount);
|
||||||
} else if (Constants.TWO.equals(groupType)) {
|
} else if (Constants.TWO.equals(groupType)) {
|
||||||
|
// 电费折扣
|
||||||
|
afterElectricityAmountDiscount = totalElectricityAmount.multiply(discount).setScale(4, RoundingMode.DOWN);
|
||||||
discountElectricityAmount = totalElectricityAmount.subtract(afterElectricityAmountDiscount);
|
discountElectricityAmount = totalElectricityAmount.subtract(afterElectricityAmountDiscount);
|
||||||
} else {
|
} else {
|
||||||
// BigDecimal afterServiceAmountDiscount = totalServiceAmount.multiply(discount).setScale(2, RoundingMode.DOWN);
|
// 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);
|
// 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);
|
discountElectricityAmount = totalElectricityAmount.subtract(afterElectricityAmountDiscount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -769,12 +784,18 @@ public abstract class AbstractProgramLogic implements InitializingBean {
|
|||||||
BigDecimal discountAmount = discountServiceAmount.add(discountElectricityAmount);
|
BigDecimal discountAmount = discountServiceAmount.add(discountElectricityAmount);
|
||||||
orderBasicInfo.setDiscountAmount(discountAmount);
|
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);
|
orderBasicInfo.setRefundAmount(refundAmount);
|
||||||
|
|
||||||
orderDetail.setDiscountElectricityAmount(discountElectricityAmount);
|
orderDetail.setDiscountElectricityAmount(discountElectricityAmount);
|
||||||
orderDetail.setDiscountServiceAmount(discountServiceAmount);
|
orderDetail.setDiscountServiceAmount(discountServiceAmount);
|
||||||
logger.info("计算订单折扣, orderCode:{}, memberId:{}, discountAmount:{}, discountElectricityAmount:{}, discountServiceAmount:{}",
|
logger.info("计算订单折扣, orderCode:{}, memberId:{}, discountAmount:{}, discountElectricityAmount:{}, discountServiceAmount:{}, totalConsumeAmount:{}",
|
||||||
orderBasicInfo.getOrderCode(), memberId, discountAmount, discountElectricityAmount, discountServiceAmount);
|
orderBasicInfo.getOrderCode(), memberId, discountAmount, discountElectricityAmount, discountServiceAmount, totalConsumeAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user