app-cloudep-trade-service/internal/domain/usecase/wallet.go

82 lines
2.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package usecase
import (
"app-cloudep-trade-service/internal/domain/wallet"
"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 基礎操作類別
type WalletUseCase interface {
WalletOperationUseCase
WalletQueryUseCase
}
// Transaction 交易
type Transaction struct {
OrderID string // 交易訂單
UID string // 交易發起人
ToUID string // 交易接收人
Currency string // 幣別
Amount decimal.Decimal // 交易金額
BeforeBalance decimal.Decimal // 交易前餘額
Type wallet.TransactionType // 交易種類
BusinessType wallet.BusinessLogic // 商業種類
Brand string // 轉帳平台
From wallet.BalanceType // 從哪種錢包類型
To wallet.BalanceType // 到哪種錢包類型
}
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"`
}