暂存一下,防止丢失

This commit is contained in:
2026-07-24 16:07:18 +08:00
parent 5d6e23f1a5
commit a18ed8bc8d
180 changed files with 13597 additions and 1986 deletions

View File

@@ -7,6 +7,7 @@ import (
"strings"
"time"
domainwallet "github.com/break/junhong_cmp_fiber/internal/domain/wallet"
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
assetSvc "github.com/break/junhong_cmp_fiber/internal/service/asset"
@@ -267,12 +268,39 @@ func (s *Service) GetWalletBalance(ctx context.Context) (*dto.AgentOpenAPIWallet
}
return nil, errors.Wrap(errors.CodeInternalError, err, "查询主钱包余额失败")
}
aggregate := domainwallet.AgentWallet{
ID: wallet.ID, ShopID: wallet.ShopID, WalletType: wallet.WalletType,
Balance: wallet.Balance, FrozenBalance: wallet.FrozenBalance,
CreditEnabled: wallet.CreditEnabled, CreditLimit: wallet.CreditLimit,
Status: wallet.Status, Version: wallet.Version,
}
if err := aggregate.Validate(); err != nil {
return nil, errors.Wrap(errors.CodeInternalError, err, "代理主钱包资金状态异常")
}
cashAvailable, err := aggregate.CashAvailableBalance()
if err != nil {
return nil, errors.Wrap(errors.CodeInternalError, err, "计算主钱包现金可用金额失败")
}
available, err := aggregate.AvailableBalance()
if err != nil {
return nil, errors.Wrap(errors.CodeInternalError, err, "计算主钱包总可用金额失败")
}
debtAmount, err := aggregate.DebtAmount()
if err != nil {
return nil, errors.Wrap(errors.CodeInternalError, err, "计算主钱包欠款金额失败")
}
return &dto.AgentOpenAPIWalletBalanceResponse{
Balance: wallet.Balance,
FrozenBalance: wallet.FrozenBalance,
AvailableBalance: wallet.GetAvailableBalance(),
Currency: walletCurrency(wallet.Currency),
Balance: wallet.Balance,
FrozenBalance: wallet.FrozenBalance,
CashAvailableBalance: cashAvailable,
CreditEnabled: wallet.CreditEnabled,
CreditLimit: wallet.CreditLimit,
AvailableBalance: available,
IsInDebt: aggregate.IsInDebt(),
DebtAmount: debtAmount,
Version: wallet.Version,
Currency: walletCurrency(wallet.Currency),
}, nil
}