fix(tenantbalance): 修正提现校验逻辑为可提现金额
This commit is contained in:
@@ -243,18 +243,18 @@ public class TenantBalanceServiceImpl implements TenantBalanceService {
|
||||
throw exception(TENANT_BALANCE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 3. 校验可用余额是否充足(可用余额 = 余额 - 冻结金额)
|
||||
// 3. 校验可提现金额是否充足
|
||||
BigDecimal withdrawAmount = withdrawReqVO.getAmount();
|
||||
BigDecimal frozenAmt = balance.getFrozenAmt() != null ? balance.getFrozenAmt() : BigDecimal.ZERO;
|
||||
BigDecimal availableBalance = balance.getBalance().subtract(frozenAmt);
|
||||
if (availableBalance.compareTo(withdrawAmount) < 0) {
|
||||
BigDecimal withdrawableBalance = balance.getWithdrawableBalance() != null ? balance.getWithdrawableBalance() : BigDecimal.ZERO;
|
||||
if (withdrawableBalance.compareTo(withdrawAmount) < 0) {
|
||||
throw exception(TENANT_BALANCE_WITHDRAW_INSUFFICIENT);
|
||||
}
|
||||
|
||||
// 4. 扣减余额并增加冻结金额
|
||||
BigDecimal newBalance = balance.getBalance().subtract(withdrawAmount);
|
||||
// 4. 从可提现金额中扣减并增加冻结金额
|
||||
BigDecimal frozenAmt = balance.getFrozenAmt() != null ? balance.getFrozenAmt() : BigDecimal.ZERO;
|
||||
BigDecimal newWithdrawableBalance = withdrawableBalance.subtract(withdrawAmount);
|
||||
BigDecimal newFrozenAmt = frozenAmt.add(withdrawAmount);
|
||||
balance.setBalance(newBalance);
|
||||
balance.setWithdrawableBalance(newWithdrawableBalance);
|
||||
balance.setFrozenAmt(newFrozenAmt);
|
||||
int updateCount = tenantBalanceMapper.updateById(balance);
|
||||
if (updateCount == 0) {
|
||||
@@ -269,7 +269,7 @@ public class TenantBalanceServiceImpl implements TenantBalanceService {
|
||||
TenantBalanceTransactionDO transaction = TenantBalanceTransactionDO.builder()
|
||||
.bizNo(bizNo)
|
||||
.points(withdrawAmount.negate()) // 冻结金额(负数表示冻结扣减)
|
||||
.balance(newBalance) // 扣减后的余额
|
||||
.balance(newWithdrawableBalance) // 扣减后的可提现余额
|
||||
.tenantId(tenantId)
|
||||
.type("FREEZE")
|
||||
.description("提现冻结")
|
||||
|
||||
Reference in New Issue
Block a user