2024-10-29 08:17:31 +00:00
|
|
|
|
package usecase
|
|
|
|
|
|
2024-10-29 14:49:47 +00:00
|
|
|
|
import (
|
|
|
|
|
"app-cloudep-trade-service/internal/domain"
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"github.com/shopspring/decimal"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// WalletQueryUseCase 定義所有查詢行為(餘額查詢、檢查、歷史記錄)的行為
|
|
|
|
|
type WalletQueryUseCase interface {
|
|
|
|
|
// Balance 用戶餘額
|
|
|
|
|
Balance(ctx context.Context, req BalanceReq) ([]Balance, error)
|
|
|
|
|
// CheckBalance 根據tx檢查用戶餘額是否足夠
|
|
|
|
|
CheckBalance(ctx context.Context, tx Transaction) error
|
|
|
|
|
// HistoryBalance 歷史餘額變化
|
|
|
|
|
HistoryBalance(ctx context.Context, req BalanceReq) ([]Balance, error)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WalletOperationUseCase 定義所有錢包操作(提款、充值、凍結等)的行為
|
|
|
|
|
type WalletOperationUseCase interface {
|
|
|
|
|
// Withdraw 提款
|
|
|
|
|
Withdraw(ctx context.Context, tx Transaction) error
|
|
|
|
|
// Deposit 充值
|
|
|
|
|
Deposit(ctx context.Context, tx Transaction) error
|
|
|
|
|
// DepositUnconfirmed 增加限制餘額
|
|
|
|
|
DepositUnconfirmed(ctx context.Context, tx Transaction) error
|
|
|
|
|
// Freeze 凍結
|
|
|
|
|
Freeze(ctx context.Context, tx Transaction) error
|
|
|
|
|
// AppendFreeze 追加凍結金額
|
|
|
|
|
AppendFreeze(ctx context.Context, tx Transaction) error
|
|
|
|
|
// UnFreeze 解凍
|
|
|
|
|
UnFreeze(ctx context.Context, tx Transaction) error
|
|
|
|
|
// RollbackFreeze Rollback 凍結,不可指定金額(剩餘order凍結金額)
|
|
|
|
|
RollbackFreeze(ctx context.Context, tx Transaction) error
|
|
|
|
|
// RollbackFreezeAddAvailable Rollback剩餘凍結,可指定金額(剩餘order凍結金額)
|
|
|
|
|
RollbackFreezeAddAvailable(ctx context.Context, tx Transaction) error
|
|
|
|
|
// CancelFreeze 取消凍結,可指定金額
|
|
|
|
|
CancelFreeze(ctx context.Context, tx Transaction) error
|
|
|
|
|
// Unconfirmed 增加限制
|
|
|
|
|
Unconfirmed(ctx context.Context, tx Transaction) error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WalletUseCase 基礎操作類別
|
2024-10-29 08:17:31 +00:00
|
|
|
|
type WalletUseCase interface {
|
2024-10-29 14:49:47 +00:00
|
|
|
|
WalletOperationUseCase
|
|
|
|
|
WalletQueryUseCase
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Transaction 交易
|
|
|
|
|
type Transaction struct {
|
|
|
|
|
OrderID string // 交易訂單
|
|
|
|
|
UID string // 交易發起人
|
|
|
|
|
ToUID string // 交易接收人
|
|
|
|
|
Currency string // 幣別
|
|
|
|
|
Amount decimal.Decimal // 交易金額
|
|
|
|
|
BeforeBalance decimal.Decimal // 交易前餘額
|
|
|
|
|
Type domain.TxType // 交易種類
|
|
|
|
|
BusinessType domain.BusinessName // 商業種類
|
|
|
|
|
Brand string // 轉帳平台
|
|
|
|
|
From domain.WalletType // 從哪種錢包類型
|
|
|
|
|
To domain.WalletType // 到哪種錢包類型
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type BalanceReq struct {
|
|
|
|
|
UID string // 用戶 UID
|
|
|
|
|
Currency string // 幣值
|
|
|
|
|
BeforeHour int // 在某個時段之前
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Balance struct {
|
|
|
|
|
Currency string `json:"currency"`
|
|
|
|
|
Available decimal.Decimal `json:"available"`
|
|
|
|
|
Unavailable UnavailableBalance `json:"unavailable"`
|
|
|
|
|
UpdateTime int64 `json:"update_time"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type UnavailableBalance struct {
|
|
|
|
|
Freeze decimal.Decimal `json:"freeze"`
|
|
|
|
|
Unconfirmed decimal.Decimal `json:"unconfirmed"`
|
2024-10-29 08:17:31 +00:00
|
|
|
|
}
|