transfer 新增门槛校验

This commit is contained in:
tianfeng 2025-12-05 20:24:14 +08:00
parent 58596d0f21
commit 60c396354a
3 changed files with 22 additions and 9 deletions

View File

@ -28,12 +28,14 @@ import com.red.circle.wallet.infra.database.mongo.entity.bank.UserBankRunningWat
import com.red.circle.wallet.infra.database.mongo.service.bank.UserBankBalanceService;
import com.red.circle.wallet.infra.database.mongo.service.bank.UserBankRunningWaterService;
import com.red.circle.wallet.infra.database.mongo.service.bank.UserBankWithdrawGoldApplyService;
import com.red.circle.wallet.infra.database.rds.entity.freight.FreightBalance;
import com.red.circle.wallet.infra.database.rds.entity.freight.FreightBalanceRunningWater;
import com.red.circle.wallet.infra.database.rds.service.auth.PayAuthService;
import com.red.circle.wallet.infra.database.rds.service.diamond.SalaryDiamondBalanceService;
import com.red.circle.wallet.infra.database.rds.service.diamond.SalaryDiamondRunningWaterService;
import com.red.circle.wallet.infra.database.rds.service.freight.FreightBalanceRunningWaterService;
import com.red.circle.wallet.infra.database.rds.service.freight.FreightBalanceService;
import com.red.circle.wallet.inner.error.FreightErrorCode;
import com.red.circle.wallet.inner.error.WalletErrorCode;
import com.red.circle.wallet.inner.model.dto.BankBalanceDTO;
import com.red.circle.wallet.inner.model.enums.FreightBalanceOrigin;
@ -46,6 +48,7 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
/**
@ -92,6 +95,14 @@ public class UserBankTransferGoldCmdExe {
// 获得区域兑换比例金币比例
Double goldRatio = getExchangeGoldRatio(cmd);
BigDecimal goldQuantity = BigDecimal.valueOf(goldRatio).multiply(cmd.getAmount()).setScale(0, RoundingMode.DOWN);
FreightBalance freightBalance = freightBalanceService.getFreightBalance(cmd.getAcceptUserId());
ResponseAssert.notNull(FreightErrorCode.NOT_FREIGHT, freightBalance);
long result = goldQuantity.divide(new BigDecimal(10000), RoundingMode.DOWN).setScale(0, RoundingMode.DOWN).longValue();
ResponseAssert.isTrue(FreightErrorCode.NOT_THRESHOLD, result >= Optional.ofNullable(freightBalance.getDeliveryThreshold()).orElse(0));
// 扣钱
BankBalanceDTO decrUserBankBalanceDTO = userBankBalanceService.decr(cmd.requiredReqUserId(),
PennyAmount.ofDollar(cmd.getAmount()));
@ -118,7 +129,6 @@ public class UserBankTransferGoldCmdExe {
.setCreateUserOrigin(OpUserType.APP.getType())
);
BigDecimal goldQuantity = BigDecimal.valueOf(goldRatio).multiply(cmd.getAmount()).setScale(0, RoundingMode.DOWN);
// 发送金额
sendGold(cmd, freight, goldQuantity, bankRunWaterId, "转账金币");

View File

@ -102,12 +102,6 @@ public class SendFreightShipCmdExe {
ResponseAssert.isTrue(WalletErrorCode.INSUFFICIENT_BALANCE,
ArithmeticUtils.gte(cmd.getQuantity(), BigDecimal.ZERO));
FreightBalance freightBalance = freightBalanceService.getFreightBalance(cmd.getReqUserId());
ResponseAssert.notNull(FreightErrorCode.NOT_FREIGHT, freightBalance);
long result = cmd.getQuantity().divide(new BigDecimal(10000), RoundingMode.DOWN).setScale(0, RoundingMode.DOWN).longValue();
ResponseAssert.isTrue(FreightErrorCode.NOT_THRESHOLD, result >= Optional.ofNullable(freightBalance.getDeliveryThreshold()).orElse(0));
// 支付密码效验
checkPayPassword(cmd);

View File

@ -26,9 +26,11 @@ import com.red.circle.wallet.domain.wallet.WalletReceipt;
import com.red.circle.wallet.infra.database.mongo.entity.bank.UserBankRunningWater;
import com.red.circle.wallet.infra.database.mongo.service.bank.UserBankBalanceService;
import com.red.circle.wallet.infra.database.mongo.service.bank.UserBankRunningWaterService;
import com.red.circle.wallet.infra.database.rds.entity.freight.FreightBalance;
import com.red.circle.wallet.infra.database.rds.entity.freight.FreightBalanceRunningWater;
import com.red.circle.wallet.infra.database.rds.service.freight.FreightBalanceRunningWaterService;
import com.red.circle.wallet.infra.database.rds.service.freight.FreightBalanceService;
import com.red.circle.wallet.inner.error.FreightErrorCode;
import com.red.circle.wallet.inner.error.WalletErrorCode;
import com.red.circle.wallet.inner.model.dto.BankBalanceDTO;
import com.red.circle.wallet.inner.model.enums.FreightBalanceOrigin;
@ -41,6 +43,7 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
/**
@ -89,14 +92,20 @@ public class SalaryTransferGoldCmdExe {
Double goldRatio = getExchangeGoldRatio(cmd);
Long bankRunWaterId = IdWorkerUtils.getId();
BigDecimal goldQuantity = BigDecimal.valueOf(goldRatio).multiply(cmd.getAmount()).setScale(0, RoundingMode.DOWN);
FreightBalance freightBalance = freightBalanceService.getFreightBalance(cmd.getAcceptUserId());
ResponseAssert.notNull(FreightErrorCode.NOT_FREIGHT, freightBalance);
long result = goldQuantity.divide(new BigDecimal(10000), RoundingMode.DOWN).setScale(0, RoundingMode.DOWN).longValue();
ResponseAssert.isTrue(FreightErrorCode.NOT_THRESHOLD, result >= Optional.ofNullable(freightBalance.getDeliveryThreshold()).orElse(0));
// 扣钱
cmd.setReqTraceId(String.valueOf(bankRunWaterId));
SalaryReceipt receipt = salaryAccountConvertor.toTransferReceipt(cmd);
SalaryReceiptRes salaryReceiptRes = salaryAccountGateway.changeBalance(receipt);
ResponseAssert.notNull(WalletErrorCode.INSUFFICIENT_BALANCE, salaryReceiptRes);
BigDecimal goldQuantity = BigDecimal.valueOf(goldRatio).multiply(cmd.getAmount()).setScale(0, RoundingMode.DOWN);
// 发送金额
sendGold(cmd, freight, goldQuantity, bankRunWaterId, "转账金币");