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))
|
||||
}
|
||||
92
internal/model/nh_stake_points_log_model_gen.go
Executable file
92
internal/model/nh_stake_points_log_model_gen.go
Executable file
@@ -0,0 +1,92 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// versions:
|
||||
// goctl version: 1.7.6
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
nhStakePointsLogFieldNames = builder.RawFieldNames(&NhStakePointsLog{})
|
||||
nhStakePointsLogRows = strings.Join(nhStakePointsLogFieldNames, ",")
|
||||
nhStakePointsLogRowsExpectAutoSet = strings.Join(stringx.Remove(nhStakePointsLogFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
nhStakePointsLogRowsWithPlaceHolder = strings.Join(stringx.Remove(nhStakePointsLogFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
nhStakePointsLogModel interface {
|
||||
Insert(ctx context.Context, data *NhStakePointsLog) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id uint) (*NhStakePointsLog, error)
|
||||
Update(ctx context.Context, data *NhStakePointsLog) error
|
||||
Delete(ctx context.Context, id uint) error
|
||||
}
|
||||
|
||||
defaultNhStakePointsLogModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
NhStakePointsLog struct {
|
||||
Id uint `db:"id"`
|
||||
Uid uint `db:"uid"` // 用户id
|
||||
RoleId uint64 `db:"role_id"` // 角色id
|
||||
LevelId uint `db:"level_id"` // 档位id
|
||||
Level uint `db:"level"` // 档位
|
||||
Points int `db:"points"` // 积分数量
|
||||
Action uint8 `db:"action"` // 操作类型:1=质押,2=升级,3=续约,4=解除
|
||||
CreatedAt time.Time `db:"created_at"` // 创建时间
|
||||
}
|
||||
)
|
||||
|
||||
func newNhStakePointsLogModel(conn sqlx.SqlConn) *defaultNhStakePointsLogModel {
|
||||
return &defaultNhStakePointsLogModel{
|
||||
conn: conn,
|
||||
table: "`nh_stake_points_log`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultNhStakePointsLogModel) Delete(ctx context.Context, id uint) error {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
_, err := m.conn.ExecCtx(ctx, query, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultNhStakePointsLogModel) FindOne(ctx context.Context, id uint) (*NhStakePointsLog, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhStakePointsLogRows, m.table)
|
||||
var resp NhStakePointsLog
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultNhStakePointsLogModel) Insert(ctx context.Context, data *NhStakePointsLog) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?)", m.table, nhStakePointsLogRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Uid, data.RoleId, data.LevelId, data.Level, data.Points, data.Action)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultNhStakePointsLogModel) Update(ctx context.Context, data *NhStakePointsLog) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhStakePointsLogRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, data.Uid, data.RoleId, data.LevelId, data.Level, data.Points, data.Action, data.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultNhStakePointsLogModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
Reference in New Issue
Block a user