diff --git a/jsowell-admin/src/test/java/SpringBootTestController.java b/jsowell-admin/src/test/java/SpringBootTestController.java index 2e3c7ae6d..fcba4b536 100644 --- a/jsowell-admin/src/test/java/SpringBootTestController.java +++ b/jsowell-admin/src/test/java/SpringBootTestController.java @@ -65,10 +65,7 @@ import com.jsowell.pile.vo.base.MemberWalletVO; import com.jsowell.pile.vo.base.PileInfoVO; import com.jsowell.pile.vo.uniapp.MemberVO; import com.jsowell.pile.vo.uniapp.PileConnectorDetailVO; -import com.jsowell.pile.vo.web.BalanceDeductionAmountVO; -import com.jsowell.pile.vo.web.BillingTemplateVO; -import com.jsowell.pile.vo.web.OrderListVO; -import com.jsowell.pile.vo.web.PileDetailVO; +import com.jsowell.pile.vo.web.*; import com.jsowell.service.MemberService; import com.jsowell.service.OrderService; import com.jsowell.service.PileService; @@ -96,6 +93,7 @@ import org.springframework.util.StopWatch; import java.io.UnsupportedEncodingException; import java.math.BigDecimal; +import java.math.RoundingMode; import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -243,6 +241,9 @@ public class SpringBootTestController { @Autowired private MemberWalletInfoService memberWalletInfoService; + @Autowired + private MemberGroupService memberGroupService; + @Test public void queryPaymentRefundTest() { String paymentId = "002212023122615542010585629628950949888"; @@ -276,6 +277,74 @@ public class SpringBootTestController { // 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 public void queryPaymentByOrderNoTest() { diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/programlogic/AbstractProgramLogic.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/programlogic/AbstractProgramLogic.java index 774b83da6..187909384 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/programlogic/AbstractProgramLogic.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/programlogic/AbstractProgramLogic.java @@ -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); } /**