app-cloudep-wallet-service/pkg/domain/entity/transaction.go

38 lines
2.4 KiB
Go
Raw Normal View History

2025-04-11 09:10:34 +00:00
package entity
import (
"code.30cm.net/digimon/app-cloudep-wallet-service/pkg/domain/wallet"
"github.com/shopspring/decimal"
)
//graph TD
// A[使用者下單/轉帳/出金等行為] --> B[建立 Transaction 主交易紀錄]
// B --> C1[WalletTransaction可用餘額 -100]
// B --> C2[WalletTransaction凍結餘額 +100]
// C1 --> D1[錢包資料庫:更新可用餘額]
// C2 --> D2[錢包資料庫:更新凍結餘額]
// Transaction 表示一次錢包資金交易的紀錄
type Transaction struct {
ID int64 `gorm:"column:id"` // 資料表主鍵 ID
OrderID string `gorm:"column:order_id"` // 外部訂單編號(例如交易訂單編號)
TransactionID string `gorm:"column:transaction_id"` // 此筆資金交易的唯一識別碼
Brand string `gorm:"column:brand"` // 品牌或平台識別(用於多租戶區分)
UID string `gorm:"column:uid"` // 發起交易的用戶 UID
ToUID string `gorm:"column:to_uid"` // 接收方用戶 UID如為轉帳類型
Type wallet.TransactionType `gorm:"column:type"` // 資金異動類型(如充值、提領、轉帳等)
BusinessType int8 `gorm:"column:business_type"` // 業務類型(對應平台不同業務,例如系統轉帳、合約轉帳等)
Asset string `gorm:"column:asset"` // 幣種(或平台定義的資產名稱)
Amount decimal.Decimal `gorm:"column:amount"` // 異動金額(正負表示收入或支出)
Balance decimal.Decimal `gorm:"column:balance"` // 異動後錢包餘額
BeforeBalance decimal.Decimal `gorm:"column:before_balance"` // 異動前錢包餘額
Status bool `gorm:"column:status"` // 狀態true 表示成功false 表示失敗或未確認)
CreateAt int64 `gorm:"column:create_at;autoCreateTime"` // 建立時間Unix timestamp
DueTime int64 `gorm:"column:due_time"` // 到期時間(可用於未完成交易的失效邏輯)
}
// TableName 回傳對應的資料表名稱
func (t *Transaction) TableName() string {
return "transaction"
}