From e63f08bb358dd2d53a1bece9fb7654ff196c113b Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Thu, 09 Jan 2025 18:03:58 +0800
Subject: [PATCH] refactor(mall): 优化 BigDecimal 的舍入方式
---
src/main/java/cc/mrbird/febs/mall/service/impl/RunVipServiceImpl.java | 32 ++++++++++----------------------
1 files changed, 10 insertions(+), 22 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/RunVipServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/RunVipServiceImpl.java
index cf29d0c..d46432f 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/RunVipServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/RunVipServiceImpl.java
@@ -33,7 +33,6 @@
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
-import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -105,10 +104,12 @@
.orderByDesc(RunVipGrow::getId)
).stream().findFirst().orElse(null);
if(runVipGrow != null){
- BigDecimal amountNow = runVipGrow.getAmountNow();
- reduceAmount = reduceAmount.add(amountNow);
+ reduceAmount = runVipGrow.getAmountNow();
}
presentAmount = presentAmount.subtract(reduceAmount);
+ if(BigDecimal.ZERO.compareTo(presentAmount) >= 0){
+ throw new FebsException("支付异常,请刷新页面重试");
+ }
Long addressId = apiGoChargeDto.getAddressId();
MallMemberPayment mallMemberPayment = mallMemberPaymentMapper.selectById(addressId);
@@ -202,10 +203,12 @@
.orderByDesc(RunVipGrow::getId)
).stream().findFirst().orElse(null);
if(runVipGrow != null){
- BigDecimal amountNow = runVipGrow.getAmountNow();
- reduceAmount = reduceAmount.add(amountNow);
+ reduceAmount = runVipGrow.getAmountNow();
}
presentAmount = presentAmount.subtract(reduceAmount);
+ if(BigDecimal.ZERO.compareTo(presentAmount) >= 0){
+ throw new FebsException("支付异常,请刷新页面重试");
+ }
MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(memberId);
if(mallMemberWallet.getCommission().compareTo(BigDecimal.ZERO) <= 0){
@@ -535,33 +538,18 @@
BigDecimal subtract = amountAll.subtract(amountNow);
if(subtract.compareTo(amount) <= 0){
- runVipGrow.setAmountNow(amountAll);
-
mallCharge.setVipCode(runVipGrow.getLevelNext());
}else{
- runVipGrow.setAmountNow(amountNow.add(amount).setScale(2, RoundingMode.DOWN));
-
mallCharge.setVipCode(memberLevel);
}
- runVipGrow.setAmount(amount);
- runVipGrowMapper.updateById(runVipGrow);
}else{
BigDecimal presentPrice = runVip.getPresentPrice();
BigDecimal add = presentPrice.add(amount);
BigDecimal presentPriceNext = runVipNext.getPresentPrice();
- runVipGrow = new RunVipGrow();
- runVipGrow.setMemberId(memberId);
- runVipGrow.setLevelNow(memberLevel);
- runVipGrow.setLevelNext(runVipNext.getVipCode());
- runVipGrow.setAmountAll(presentPriceNext);
- runVipGrow.setAmount(add);
- runVipGrow.setAmountNow(add);
- runVipGrowMapper.insert(runVipGrow);
-
if(presentPriceNext.compareTo(add) <= 0){
- mallCharge.setVipCode(runVipGrow.getLevelNext());
+ mallCharge.setVipCode(runVipNext.getVipCode());
}
}
mallChargeMapper.insert(mallCharge);
@@ -709,7 +697,7 @@
).stream().findFirst().orElse(null);
if(runVipGrow != null){
BigDecimal amountNow = runVipGrow.getAmountNow();
- reduceAmount = reduceAmount.add(amountNow);
+ reduceAmount = amountNow;
}
apiReduceAmountVo.setReduceAmount(reduceAmount);
return new FebsResponse().success().data(apiReduceAmountVo);
--
Gitblit v1.9.1