feat: 拉取积分质押操作记录的接口
This commit is contained in:
50
internal/model/nh_stake_points_log_model.go
Executable file
50
internal/model/nh_stake_points_log_model.go
Executable file
@@ -0,0 +1,50 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ NhStakePointsLogModel = (*customNhStakePointsLogModel)(nil)
|
||||
|
||||
type (
|
||||
// NhStakePointsLogModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customNhStakePointsLogModel.
|
||||
NhStakePointsLogModel interface {
|
||||
nhStakePointsLogModel
|
||||
WithSession(session sqlx.Session) NhStakePointsLogModel
|
||||
List(ctx context.Context, uid uint, roleId uint64, page, pageSize int) ([]*NhStakePointsLog, error)
|
||||
}
|
||||
|
||||
customNhStakePointsLogModel struct {
|
||||
*defaultNhStakePointsLogModel
|
||||
}
|
||||
)
|
||||
|
||||
func (m *customNhStakePointsLogModel) List(ctx context.Context, uid uint, roleId uint64, page, pageSize int) ([]*NhStakePointsLog, error) {
|
||||
var query string
|
||||
if roleId == 0 {
|
||||
query = fmt.Sprintf("select %s from %s where uid = ? order by id desc limit ?, ?", nhStakePointsLogRows, m.table)
|
||||
} else {
|
||||
query = fmt.Sprintf("select %s from %s where uid = ? and role_id = ? order by id desc limit ?, ?", nhStakePointsLogRows, m.table)
|
||||
}
|
||||
var result []*NhStakePointsLog
|
||||
err := m.conn.QueryRowsCtx(ctx, &result, query, uid, (page-1)*pageSize, pageSize)
|
||||
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// NewNhStakePointsLogModel returns a model for the database table.
|
||||
func NewNhStakePointsLogModel(conn sqlx.SqlConn) NhStakePointsLogModel {
|
||||
return &customNhStakePointsLogModel{
|
||||
defaultNhStakePointsLogModel: newNhStakePointsLogModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customNhStakePointsLogModel) WithSession(session sqlx.Session) NhStakePointsLogModel {
|
||||
return NewNhStakePointsLogModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
||||
Reference in New Issue
Block a user