refactor wallet domain management

This commit is contained in:
david
2026-07-28 09:25:49 +08:00
parent 8d71a1fc08
commit 8c6d52cf8c
20 changed files with 606 additions and 68 deletions

View File

@@ -1,15 +0,0 @@
package models
import "git.apinb.com/bsm-sdk/core/database"
// Wallet 对应 wallet保存余额账户。
type Wallet struct {
Entity // 公共实体字段
OwnerType string `gorm:"column:owner_type;type:varchar(32);not null" json:"owner_type"` // owner_type 业务字段
OwnerID uint64 `gorm:"column:owner_id;not null;index" json:"owner_id"` // owner_id 业务字段
BalanceAmount int64 `gorm:"column:balance_amount;not null;default:0" json:"balance_amount"` // balance_amount 业务字段
FrozenAmount int64 `gorm:"column:frozen_amount;not null;default:0" json:"frozen_amount"` // frozen_amount 业务字段
}
func init() { database.AppendMigrate(&Wallet{}) }
func (table *Wallet) TableName() string { return "wallet" }

View File

@@ -0,0 +1,30 @@
package models
import (
"time"
"git.apinb.com/bsm-sdk/core/database"
)
// WalletApplyCash 对应 wallet_apply_cash保存提现申请及审核结果。
type WalletApplyCash struct {
Entity // 公共实体字段
WalletBasicID uint64 `gorm:"column:wallet_basic_id;not null;index" json:"wallet_basic_id"` // 钱包自增主键
WalletBankID uint64 `gorm:"column:wallet_bank_id;not null;default:0;index" json:"wallet_bank_id"` // 银行卡自增主键
CashNo string `gorm:"column:cash_no;type:varchar(64);not null;uniqueIndex" json:"cash_no"` // 内部提现单号
RequestNo string `gorm:"column:request_no;type:varchar(128);not null;uniqueIndex" json:"request_no"` // 申请幂等号
Amount int64 `gorm:"column:amount;not null;check:amount > 0" json:"amount"` // 提现金额,单位分
Fee int64 `gorm:"column:fee;not null;default:0;check:fee >= 0" json:"fee"` // 提现手续费,单位分
Channel string `gorm:"column:channel;type:varchar(32);not null" json:"channel"` // 提现渠道
TradeNo string `gorm:"column:trade_no;type:varchar(128);not null;default:'';index" json:"trade_no"` // 第三方提现流水号
Remark string `gorm:"column:remark;type:text;not null;default:''" json:"remark"` // 申请备注
CallbackMsg string `gorm:"column:callback_msg;type:text;not null;default:''" json:"callback_msg"` // 提现回调信息
ReviewerIdentity string `gorm:"column:reviewer_identity;type:varchar(36);not null;default:'';index" json:"reviewer_identity"` // 审核人业务标识
ReviewerName string `gorm:"column:reviewer_name;type:varchar(64);not null;default:''" json:"reviewer_name"` // 审核人姓名快照
ReviewedAt *time.Time `gorm:"column:reviewed_at;type:timestamptz" json:"reviewed_at"` // 审核时间
ReviewReason string `gorm:"column:review_reason;type:text;not null;default:''" json:"review_reason"` // 审核原因
CompletedAt *time.Time `gorm:"column:completed_at;type:timestamptz" json:"completed_at"` // 完成时间
}
func init() { database.AppendMigrate(&WalletApplyCash{}) }
func (table *WalletApplyCash) TableName() string { return "wallet_apply_cash" }

View File

@@ -0,0 +1,22 @@
package models
import "git.apinb.com/bsm-sdk/core/database"
// WalletBank 对应 wallet_bank保存钱包绑定的银行卡密文档案。
type WalletBank struct {
Entity // 公共实体字段
WalletBasicID uint64 `gorm:"column:wallet_basic_id;not null;index;uniqueIndex:idx_wallet_card" json:"wallet_basic_id"` // 钱包自增主键
CardNoCiphertext string `gorm:"column:card_no_ciphertext;type:text;not null" json:"-"` // 加密银行卡号
CardFingerprint string `gorm:"column:card_fingerprint;type:varchar(64);not null;uniqueIndex:idx_wallet_card" json:"-"` // 银行卡号不可逆指纹
CardNoLast4 string `gorm:"column:card_no_last4;type:varchar(4);not null;index" json:"card_no_last4"` // 银行卡号末四位
BankName string `gorm:"column:bank_name;type:varchar(128);not null" json:"bank_name"` // 银行名称
CardOwner string `gorm:"column:card_owner;type:varchar(128);not null" json:"card_owner"` // 持卡人姓名
IDCardCiphertext string `gorm:"column:id_card_ciphertext;type:text;not null" json:"-"` // 加密身份证号
PhoneCiphertext string `gorm:"column:phone_ciphertext;type:text;not null" json:"-"` // 加密银行预留手机号
BindID string `gorm:"column:bind_id;type:varchar(128);not null;default:'';uniqueIndex:,where:bind_id <> ''" json:"bind_id"` // 支付渠道绑定标识
BankType string `gorm:"column:bank_type;type:varchar(20);not null;default:''" json:"bank_type"` // 银行卡类型
Bank string `gorm:"column:bank;type:varchar(64);not null;default:''" json:"bank"` // 所属银行编码
}
func init() { database.AppendMigrate(&WalletBank{}) }
func (table *WalletBank) TableName() string { return "wallet_bank" }

View File

@@ -0,0 +1,21 @@
package models
import "git.apinb.com/bsm-sdk/core/database"
// WalletBasic 对应 wallet_basic保存多主体统一钱包账户。
type WalletBasic struct {
Entity // 公共实体字段
OwnerType string `gorm:"column:owner_type;type:varchar(32);not null;uniqueIndex:idx_wallet_owner" json:"owner_type"` // 归属主体类型
OwnerID uint64 `gorm:"column:owner_id;not null;default:0;index" json:"owner_id"` // 归属主体自增主键
OwnerIdentity string `gorm:"column:owner_identity;type:varchar(36);not null;uniqueIndex:idx_wallet_owner" json:"owner_identity"` // 归属主体业务标识
AlipayID string `gorm:"column:alipay_id;type:varchar(128);not null;default:''" json:"alipay_id"` // 支付宝账号
AlipayName string `gorm:"column:alipay_name;type:varchar(128);not null;default:''" json:"alipay_name"` // 支付宝账户名
WxpayID string `gorm:"column:wxpay_id;type:varchar(128);not null;default:''" json:"wxpay_id"` // 微信支付账号
WxpayName string `gorm:"column:wxpay_name;type:varchar(128);not null;default:''" json:"wxpay_name"` // 微信支付账户名
PayPasswordHash string `gorm:"column:pay_password_hash;type:varchar(255);not null;default:''" json:"-"` // 支付密码哈希
Balance int64 `gorm:"column:balance;not null;default:0;check:balance >= 0" json:"balance"` // 钱包余额,单位分
WithdrawalBalance int64 `gorm:"column:withdrawal_balance;not null;default:0;check:withdrawal_balance >= 0" json:"withdrawal_balance"` // 可提现余额,单位分
}
func init() { database.AppendMigrate(&WalletBasic{}) }
func (table *WalletBasic) TableName() string { return "wallet_basic" }

View File

@@ -1,16 +0,0 @@
package models
import "git.apinb.com/bsm-sdk/core/database"
// WalletLedger 对应 wallet_ledger保存不可变资金流水。
type WalletLedger struct {
Entity // 公共实体字段
WalletID uint64 `gorm:"column:wallet_id;not null;index" json:"wallet_id"` // wallet_id 业务字段
Amount int64 `gorm:"column:amount;not null" json:"amount"` // amount 业务字段
Direction string `gorm:"column:direction;type:varchar(16);not null" json:"direction"` // direction 业务字段
BalanceAfter int64 `gorm:"column:balance_after;not null" json:"balance_after"` // balance_after 业务字段
ReferenceIdentity string `gorm:"column:reference_identity;type:varchar(36);not null;default:'';index" json:"reference_identity"` // reference_identity 业务字段
}
func init() { database.AppendMigrate(&WalletLedger{}) }
func (table *WalletLedger) TableName() string { return "wallet_ledger" }

View File

@@ -0,0 +1,22 @@
package models
import "git.apinb.com/bsm-sdk/core/database"
// WalletPayment 对应 wallet_payment保存第三方或余额支付单。
type WalletPayment struct {
Entity // 公共实体字段
WalletBasicID uint64 `gorm:"column:wallet_basic_id;not null;index" json:"wallet_basic_id"` // 钱包自增主键
PaymentNo string `gorm:"column:payment_no;type:varchar(64);not null;uniqueIndex" json:"payment_no"` // 内部支付单号
OrderNo string `gorm:"column:order_no;type:varchar(128);not null;index" json:"order_no"` // 业务订单号
TradeNo string `gorm:"column:trade_no;type:varchar(128);not null;default:'';uniqueIndex:idx_wallet_payment_trade,where:trade_no <> ''" json:"trade_no"` // 第三方交易流水号
PaymentType string `gorm:"column:payment_type;type:varchar(32);not null" json:"payment_type"` // 支付业务类型
PayChannel string `gorm:"column:pay_channel;type:varchar(32);not null;uniqueIndex:idx_wallet_payment_trade,where:trade_no <> ''" json:"pay_channel"` // 支付渠道
PayType string `gorm:"column:pay_type;type:varchar(64);not null;default:''" json:"pay_type"` // 渠道支付类型
Amount int64 `gorm:"column:amount;not null;check:amount > 0" json:"amount"` // 支付金额,单位分
Args string `gorm:"column:args;type:text;not null;default:''" json:"args"` // 支付参数
Remark string `gorm:"column:remark;type:text;not null;default:''" json:"remark"` // 备注
CallbackMsg string `gorm:"column:callback_msg;type:text;not null;default:''" json:"callback_msg"` // 支付回调信息
}
func init() { database.AppendMigrate(&WalletPayment{}) }
func (table *WalletPayment) TableName() string { return "wallet_payment" }

View File

@@ -1,14 +0,0 @@
package models
import "git.apinb.com/bsm-sdk/core/database"
// WalletRecharge 对应 wallet_recharge保存充值记录。
type WalletRecharge struct {
Entity // 公共实体字段
WalletID uint64 `gorm:"column:wallet_id;not null;index" json:"wallet_id"` // wallet_id 业务字段
Amount int64 `gorm:"column:amount;not null" json:"amount"` // amount 业务字段
Channel string `gorm:"column:channel;type:varchar(32);not null" json:"channel"` // channel 业务字段
}
func init() { database.AppendMigrate(&WalletRecharge{}) }
func (table *WalletRecharge) TableName() string { return "wallet_recharge" }

View File

@@ -0,0 +1,30 @@
package models
import "git.apinb.com/bsm-sdk/core/database"
// WalletRecord 对应 wallet_record保存不可变资金流水。
type WalletRecord struct {
Entity // 公共实体字段
WalletBasicID uint64 `gorm:"column:wallet_basic_id;not null;index" json:"wallet_basic_id"` // 钱包自增主键
RecordNo string `gorm:"column:record_no;type:varchar(64);not null;uniqueIndex" json:"record_no"` // 内部流水号
RequestNo string `gorm:"column:request_no;type:varchar(128);not null;uniqueIndex" json:"request_no"` // 业务幂等号
Direction string `gorm:"column:direction;type:varchar(16);not null" json:"direction"` // 收支方向
TradeType string `gorm:"column:trade_type;type:varchar(32);not null;index" json:"trade_type"` // 交易类型
Amount int64 `gorm:"column:amount;not null;check:amount > 0" json:"amount"` // 交易金额,单位分
Fee int64 `gorm:"column:fee;not null;default:0;check:fee >= 0" json:"fee"` // 手续费,单位分
BalanceAfter int64 `gorm:"column:balance_after;not null;check:balance_after >= 0" json:"balance_after"` // 交易后余额
WithdrawalBalanceAfter int64 `gorm:"column:withdrawal_balance_after;not null;check:withdrawal_balance_after >= 0" json:"withdrawal_balance_after"` // 交易后可提现余额
InTradeNo string `gorm:"column:in_trade_no;type:varchar(128);not null;default:'';index" json:"in_trade_no"` // 内部业务流水号
OutTradeNo string `gorm:"column:out_trade_no;type:varchar(128);not null;default:'';index" json:"out_trade_no"` // 外部渠道流水号
PayChannel string `gorm:"column:pay_channel;type:varchar(32);not null;default:''" json:"pay_channel"` // 支付渠道
PayType string `gorm:"column:pay_type;type:varchar(64);not null;default:''" json:"pay_type"` // 渠道支付类型
RelatedRecordID uint64 `gorm:"column:related_record_id;not null;default:0;index" json:"related_record_id"` // 冲正关联原流水自增主键
OperatorIdentity string `gorm:"column:operator_identity;type:varchar(36);not null;default:'';index" json:"operator_identity"` // 操作者业务标识
OperatorName string `gorm:"column:operator_name;type:varchar(64);not null;default:''" json:"operator_name"` // 操作者姓名快照
Ymd int32 `gorm:"column:ymd;not null;index" json:"ymd"` // 年月日索引
Ym int32 `gorm:"column:ym;not null;index" json:"ym"` // 年月索引
Remark string `gorm:"column:remark;type:text;not null;default:''" json:"remark"` // 交易备注
}
func init() { database.AppendMigrate(&WalletRecord{}) }
func (table *WalletRecord) TableName() string { return "wallet_record" }

View File

@@ -0,0 +1,26 @@
package models
import (
"time"
"git.apinb.com/bsm-sdk/core/database"
)
// WalletRefund 对应 wallet_refund保存支付退款结果。
type WalletRefund struct {
Entity // 公共实体字段
WalletBasicID uint64 `gorm:"column:wallet_basic_id;not null;index" json:"wallet_basic_id"` // 钱包自增主键
WalletPaymentID uint64 `gorm:"column:wallet_payment_id;not null;index" json:"wallet_payment_id"` // 原支付记录自增主键
RefundNo string `gorm:"column:refund_no;type:varchar(64);not null;uniqueIndex" json:"refund_no"` // 内部退款单号
OrderIdentity string `gorm:"column:order_identity;type:varchar(64);not null;index" json:"order_identity"` // 订单业务标识
Amount int64 `gorm:"column:amount;not null;check:amount > 0" json:"amount"` // 退款金额,单位分
Fee int64 `gorm:"column:fee;not null;default:0;check:fee >= 0" json:"fee"` // 退款手续费,单位分
Reason string `gorm:"column:reason;type:text;not null;default:''" json:"reason"` // 退款原因
OrderInfo string `gorm:"column:order_info;type:text;not null;default:''" json:"order_info"` // 订单信息快照
Result string `gorm:"column:result;type:text;not null;default:''" json:"result"` // 第三方处理结果
TradeNo string `gorm:"column:trade_no;type:varchar(128);not null;default:'';index" json:"trade_no"` // 第三方退款流水号
CompletedAt *time.Time `gorm:"column:completed_at;type:timestamptz" json:"completed_at"` // 完成时间
}
func init() { database.AppendMigrate(&WalletRefund{}) }
func (table *WalletRefund) TableName() string { return "wallet_refund" }

View File

@@ -1,14 +0,0 @@
package models
import "git.apinb.com/bsm-sdk/core/database"
// WalletWithdrawal 对应 wallet_withdrawal保存提现记录。
type WalletWithdrawal struct {
Entity // 公共实体字段
WalletID uint64 `gorm:"column:wallet_id;not null;index" json:"wallet_id"` // wallet_id 业务字段
Amount int64 `gorm:"column:amount;not null" json:"amount"` // amount 业务字段
BankAccountMasked string `gorm:"column:bank_account_masked;type:varchar(128);not null;default:''" json:"bank_account_masked"` // bank_account_masked 业务字段
}
func init() { database.AppendMigrate(&WalletWithdrawal{}) }
func (table *WalletWithdrawal) TableName() string { return "wallet_withdrawal" }