103 lines
4.2 KiB
Go
Executable File
103 lines
4.2 KiB
Go
Executable File
// Code generated by goctl. DO NOT EDIT.
|
||
|
||
package model
|
||
|
||
import (
|
||
"context"
|
||
"database/sql"
|
||
"fmt"
|
||
"strings"
|
||
|
||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||
"github.com/zeromicro/go-zero/core/stringx"
|
||
)
|
||
|
||
var (
|
||
walletJournalFieldNames = builder.RawFieldNames(&WalletJournal{})
|
||
walletJournalRows = strings.Join(walletJournalFieldNames, ",")
|
||
walletJournalRowsExpectAutoSet = strings.Join(stringx.Remove(walletJournalFieldNames, "`id`"), ",")
|
||
walletJournalRowsWithPlaceHolder = strings.Join(stringx.Remove(walletJournalFieldNames, "`id`"), "=?,") + "=?"
|
||
)
|
||
|
||
type (
|
||
walletJournalModel interface {
|
||
Insert(ctx context.Context, data *WalletJournal) (sql.Result, error)
|
||
FindOne(ctx context.Context, id int64) (*WalletJournal, error)
|
||
Update(ctx context.Context, data *WalletJournal) error
|
||
Delete(ctx context.Context, id int64) error
|
||
}
|
||
|
||
defaultWalletJournalModel struct {
|
||
conn sqlx.SqlConn
|
||
table string
|
||
}
|
||
|
||
WalletJournal struct {
|
||
Id int64 `db:"id"` // 錢包賬本流水號
|
||
TransactionId int64 `db:"transaction_id"` // 交易 ID,對應 transaction 表
|
||
OrderId string `db:"order_id"` // 訂單 ID,對應 order 表
|
||
Brand string `db:"brand"` // 品牌名稱
|
||
Uid string `db:"uid"` // 用戶 ID
|
||
WalletType int64 `db:"wallet_type"` // 餘額種類: 1=可用, 2=凍結, 3=限制(僅出金)
|
||
Currency string `db:"currency"` // 幣種或平台點數
|
||
TransactionAmount float64 `db:"transaction_amount"` // 交易金額
|
||
PostTransactionBalance float64 `db:"post_transaction_balance"` // 交易後餘額
|
||
BusinessType int64 `db:"business_type"` // 業務類型
|
||
Status int64 `db:"status"` // 狀態
|
||
DueTime int64 `db:"due_time"` // T+N 執行時間
|
||
CreatedAt int64 `db:"created_at"` // 創建時間(Unix 時間戳,毫秒)
|
||
}
|
||
)
|
||
|
||
func newWalletJournalModel(conn sqlx.SqlConn) *defaultWalletJournalModel {
|
||
return &defaultWalletJournalModel{
|
||
conn: conn,
|
||
table: "`wallet_journal`",
|
||
}
|
||
}
|
||
|
||
func (m *defaultWalletJournalModel) withSession(session sqlx.Session) *defaultWalletJournalModel {
|
||
return &defaultWalletJournalModel{
|
||
conn: sqlx.NewSqlConnFromSession(session),
|
||
table: "`wallet_journal`",
|
||
}
|
||
}
|
||
|
||
func (m *defaultWalletJournalModel) Delete(ctx context.Context, id int64) error {
|
||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||
_, err := m.conn.ExecCtx(ctx, query, id)
|
||
return err
|
||
}
|
||
|
||
func (m *defaultWalletJournalModel) FindOne(ctx context.Context, id int64) (*WalletJournal, error) {
|
||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", walletJournalRows, m.table)
|
||
var resp WalletJournal
|
||
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
||
switch err {
|
||
case nil:
|
||
return &resp, nil
|
||
case sqlc.ErrNotFound:
|
||
return nil, ErrNotFound
|
||
default:
|
||
return nil, err
|
||
}
|
||
}
|
||
|
||
func (m *defaultWalletJournalModel) Insert(ctx context.Context, data *WalletJournal) (sql.Result, error) {
|
||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, walletJournalRowsExpectAutoSet)
|
||
ret, err := m.conn.ExecCtx(ctx, query, data.TransactionId, data.OrderId, data.Brand, data.Uid, data.WalletType, data.Currency, data.TransactionAmount, data.PostTransactionBalance, data.BusinessType, data.Status, data.DueTime, data.CreatedAt)
|
||
return ret, err
|
||
}
|
||
|
||
func (m *defaultWalletJournalModel) Update(ctx context.Context, data *WalletJournal) error {
|
||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, walletJournalRowsWithPlaceHolder)
|
||
_, err := m.conn.ExecCtx(ctx, query, data.TransactionId, data.OrderId, data.Brand, data.Uid, data.WalletType, data.Currency, data.TransactionAmount, data.PostTransactionBalance, data.BusinessType, data.Status, data.DueTime, data.CreatedAt, data.Id)
|
||
return err
|
||
}
|
||
|
||
func (m *defaultWalletJournalModel) tableName() string {
|
||
return m.table
|
||
}
|