feat: 拉取积分质押操作记录的接口
This commit is contained in:
@@ -13,6 +13,10 @@ service novatask {
|
||||
@doc "质押积分操作"
|
||||
@handler StakePoint
|
||||
post /stake (StakePointReq)
|
||||
|
||||
@doc "积分质押日志列表"
|
||||
@handler GetStakeLogList
|
||||
get /log (GetStakeLogListReq) returns (GetStakeLogListResp)
|
||||
}
|
||||
|
||||
type GetStakeLevelListReq {
|
||||
@@ -53,3 +57,24 @@ type StakePointReq {
|
||||
Action int `json:"action"` // 操作类型:1表示质押,2表示升级质押, 3表示续约
|
||||
}
|
||||
|
||||
type GetStakeLogListReq {
|
||||
RoleID uint64 `form:"role_id,optional"` // 角色id
|
||||
Page int `form:"page"` // 页码
|
||||
Size int `form:"size"` // 每页数量
|
||||
}
|
||||
|
||||
type StakeLog {
|
||||
Id uint `json:"id"` // id
|
||||
RoleID uint64 `json:"role_id"` // 角色id
|
||||
LevelId uint `json:"level_id"` // 档位id
|
||||
Level uint `json:"level"` // 精灵等级
|
||||
Points int `json:"points"` // 积分数量
|
||||
Action uint8 `json:"action"` // 操作类型:1=质押,2=升级,3=续约,4=解除
|
||||
CreatedAt int64 `json:"created_at"` // 创建时间
|
||||
}
|
||||
|
||||
type GetStakeLogListResp {
|
||||
Total int `json:"total"` // 总数
|
||||
List []StakeLog `json:"list"` // 列表
|
||||
}
|
||||
|
||||
|
||||
@@ -121,4 +121,18 @@ CREATE TABLE `nh_stake_points`
|
||||
`status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '状态:1=质押中,2=已升级,3=已续约,4=已过期',
|
||||
PRIMARY KEY (`id`),
|
||||
INDEX (`uid`, `role_id`, `level_id`, `status`)
|
||||
) COMMENT ='积分质押表';
|
||||
|
||||
CREATE TABLE `nh_stake_points_log`
|
||||
(
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`uid` int unsigned NOT NULL COMMENT '用户id',
|
||||
`role_id` bigint unsigned NOT NULL COMMENT '角色id',
|
||||
`level_id` int(11) unsigned NOT NULL COMMENT '档位id',
|
||||
`level` int unsigned NOT NULL COMMENT '档位',
|
||||
`points` int(11) NOT NULL DEFAULT 0 COMMENT '积分数量',
|
||||
`action` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '操作类型:1=质押,2=升级,3=续约,4=解除',
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`),
|
||||
INDEX (`uid`, `role_id`)
|
||||
) COMMENT ='积分质押表';
|
||||
@@ -499,6 +499,57 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/gapi/stakepoint/v1/log": {
|
||||
"get": {
|
||||
"summary": "积分质押日志列表",
|
||||
"operationId": "GetStakeLogList",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/GetStakeLogListResp"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "role_id",
|
||||
"description": " 角色id",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
{
|
||||
"name": "page",
|
||||
"description": " 页码",
|
||||
"in": "query",
|
||||
"required": true,
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
{
|
||||
"name": "size",
|
||||
"description": " 每页数量",
|
||||
"in": "query",
|
||||
"required": true,
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"stakepoint"
|
||||
],
|
||||
"consumes": [
|
||||
"multipart/form-data"
|
||||
],
|
||||
"security": [
|
||||
{
|
||||
"apiKey": []
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/gapi/stakepoint/v1/stake": {
|
||||
"post": {
|
||||
"summary": "质押积分操作",
|
||||
@@ -1148,6 +1199,53 @@
|
||||
"levels"
|
||||
]
|
||||
},
|
||||
"GetStakeLogListReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"role_id": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": " 角色id"
|
||||
},
|
||||
"page": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"description": " 页码"
|
||||
},
|
||||
"size": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"description": " 每页数量"
|
||||
}
|
||||
},
|
||||
"title": "GetStakeLogListReq",
|
||||
"required": [
|
||||
"page",
|
||||
"size"
|
||||
]
|
||||
},
|
||||
"GetStakeLogListResp": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"total": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"description": " 总数"
|
||||
},
|
||||
"list": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/StakeLog"
|
||||
},
|
||||
"description": " 列表"
|
||||
}
|
||||
},
|
||||
"title": "GetStakeLogListResp",
|
||||
"required": [
|
||||
"total",
|
||||
"list"
|
||||
]
|
||||
},
|
||||
"GetTaskListReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -1444,6 +1542,56 @@
|
||||
"can_renew"
|
||||
]
|
||||
},
|
||||
"StakeLog": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "uint32",
|
||||
"description": " id"
|
||||
},
|
||||
"role_id": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": " 角色id"
|
||||
},
|
||||
"level_id": {
|
||||
"type": "integer",
|
||||
"format": "uint32",
|
||||
"description": " 档位id"
|
||||
},
|
||||
"level": {
|
||||
"type": "integer",
|
||||
"format": "uint32",
|
||||
"description": " 精灵等级"
|
||||
},
|
||||
"points": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"description": " 积分数量"
|
||||
},
|
||||
"action": {
|
||||
"type": "integer",
|
||||
"format": "uint8",
|
||||
"description": " 操作类型:1=质押,2=升级,3=续约,4=解除"
|
||||
},
|
||||
"created_at": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": " 创建时间"
|
||||
}
|
||||
},
|
||||
"title": "StakeLog",
|
||||
"required": [
|
||||
"id",
|
||||
"role_id",
|
||||
"level_id",
|
||||
"level",
|
||||
"points",
|
||||
"action",
|
||||
"created_at"
|
||||
]
|
||||
},
|
||||
"StakeNftList": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -140,6 +140,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/level",
|
||||
Handler: stakepoint.GetStakeLevelListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 积分质押日志列表
|
||||
Method: http.MethodGet,
|
||||
Path: "/log",
|
||||
Handler: stakepoint.GetStakeLogListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
// 质押积分操作
|
||||
Method: http.MethodPost,
|
||||
|
||||
29
internal/handler/stakepoint/get_stake_log_list_handler.go
Normal file
29
internal/handler/stakepoint/get_stake_log_list_handler.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package stakepoint
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"nova_task/internal/logic/stakepoint"
|
||||
"nova_task/internal/svc"
|
||||
"nova_task/internal/types"
|
||||
)
|
||||
|
||||
// 积分质押日志列表
|
||||
func GetStakeLogListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.GetStakeLogListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := stakepoint.NewGetStakeLogListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetStakeLogList(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"nova_task/internal/consts"
|
||||
"nova_task/internal/model"
|
||||
"nova_task/internal/pkg/errs"
|
||||
"nova_task/internal/svc"
|
||||
"time"
|
||||
@@ -49,6 +50,18 @@ func (c *Cron) Run() {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = c.svcCtx.StakePointsLogModel.WithSession(session).Insert(ctx, &model.NhStakePointsLog{
|
||||
Uid: n.Uid,
|
||||
RoleId: n.RoleId,
|
||||
LevelId: n.LevelId,
|
||||
Level: n.Level,
|
||||
Points: -int(n.Points),
|
||||
Action: 4,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Errorw("stake points log error", logx.Field("err", err), logx.Field("role_id", n.RoleId), logx.Field("uid", n.Uid), logx.Field("level_id", n.LevelId), logx.Field("action", 4))
|
||||
return errs.New(errs.ErrDatabaseOperate, err)
|
||||
}
|
||||
_, err = c.svcCtx.GameAction(c.ctx, int64(n.RoleId), consts.GameActionStakePoints, map[string]any{
|
||||
"level": n.Level,
|
||||
"operation": 4,
|
||||
|
||||
52
internal/logic/stakepoint/get_stake_log_list_logic.go
Normal file
52
internal/logic/stakepoint/get_stake_log_list_logic.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package stakepoint
|
||||
|
||||
import (
|
||||
"context"
|
||||
"nova_task/internal/pkg/errs"
|
||||
"nova_task/internal/pkg/utils"
|
||||
|
||||
"nova_task/internal/svc"
|
||||
"nova_task/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetStakeLogListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// NewGetStakeLogListLogic 积分质押日志列表
|
||||
func NewGetStakeLogListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetStakeLogListLogic {
|
||||
return &GetStakeLogListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetStakeLogListLogic) GetStakeLogList(req *types.GetStakeLogListReq) (resp *types.GetStakeLogListResp, err error) {
|
||||
uid := utils.GetUidUint(l.ctx)
|
||||
ls, err := l.svcCtx.StakePointsLogModel.List(l.ctx, uid, req.RoleID, req.Page, req.Size)
|
||||
if err != nil {
|
||||
l.Errorw("get stake log list failed", logx.Field("err", err), logx.Field("uid", uid))
|
||||
return nil, errs.New(errs.ErrDatabaseOperate, err)
|
||||
}
|
||||
var lss []types.StakeLog
|
||||
for _, ll := range ls {
|
||||
lss = append(lss, types.StakeLog{
|
||||
Id: ll.Id,
|
||||
RoleID: ll.RoleId,
|
||||
LevelId: ll.LevelId,
|
||||
Level: ll.Level,
|
||||
Points: ll.Points,
|
||||
Action: ll.Action,
|
||||
CreatedAt: ll.CreatedAt.Unix(),
|
||||
})
|
||||
}
|
||||
return &types.GetStakeLogListResp{
|
||||
List: lss,
|
||||
Total: len(lss),
|
||||
}, nil
|
||||
}
|
||||
@@ -33,7 +33,7 @@ func NewStakePointLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StakeP
|
||||
}
|
||||
|
||||
func (l *StakePointLogic) StakePoint(req *types.StakePointReq) error {
|
||||
uid := utils.GetUid(l.ctx)
|
||||
uid := utils.GetUidUint(l.ctx)
|
||||
r, err := l.svcCtx.RoleModel.FindOneByRoleId(l.ctx, req.RoleID)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
@@ -50,7 +50,7 @@ func (l *StakePointLogic) StakePoint(req *types.StakePointReq) error {
|
||||
l.Errorw("find user error", logx.Field("err", err), logx.Field("role_id", req.RoleID), logx.Field("uid", uid), logx.Field("level_id", req.LevelId), logx.Field("action", req.Action))
|
||||
return errs.New(errs.ErrDatabaseOperate, err)
|
||||
}
|
||||
if u.Id != uint(uid) {
|
||||
if u.Id != uid {
|
||||
return errs.New(errs.ErrRoleNotFound, "role not exist")
|
||||
}
|
||||
lv, err := l.svcCtx.StakePointConfigModel.FindOne(l.ctx, uint(req.LevelId))
|
||||
@@ -73,12 +73,12 @@ func (l *StakePointLogic) StakePoint(req *types.StakePointReq) error {
|
||||
return errs.New(errs.ErrPointsStakeExist, "stake points exist")
|
||||
}
|
||||
err = l.svcCtx.DBConn.TransactCtx(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
err = l.svcCtx.AddUserAssetWithSession(ctx, session, uint(uid), req.RoleID, consts.AssetType_Points, "", decimal.NewFromInt(int64(-lv.Points)), "stake points", 0, 0, false)
|
||||
err = l.svcCtx.AddUserAssetWithSession(ctx, session, uid, req.RoleID, consts.AssetType_Points, "", decimal.NewFromInt(int64(-lv.Points)), "stake points", 0, 0, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = l.svcCtx.StakePointsModel.WithSession(session).Insert(l.ctx, &model.NhStakePoints{
|
||||
Uid: uint(uid),
|
||||
_, err = l.svcCtx.StakePointsModel.WithSession(session).Insert(ctx, &model.NhStakePoints{
|
||||
Uid: uid,
|
||||
RoleId: uint64(req.RoleID),
|
||||
LevelId: lv.Id,
|
||||
Level: lv.Level,
|
||||
@@ -90,6 +90,18 @@ func (l *StakePointLogic) StakePoint(req *types.StakePointReq) error {
|
||||
if err != nil {
|
||||
return errs.New(errs.ErrDatabaseOperate, err)
|
||||
}
|
||||
_, err = l.svcCtx.StakePointsLogModel.WithSession(session).Insert(ctx, &model.NhStakePointsLog{
|
||||
Uid: uid,
|
||||
RoleId: uint64(req.RoleID),
|
||||
LevelId: lv.Id,
|
||||
Level: lv.Level,
|
||||
Points: int(lv.Points),
|
||||
Action: 1,
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("stake points log error", logx.Field("err", err), logx.Field("role_id", req.RoleID), logx.Field("uid", uid), logx.Field("level_id", req.LevelId), logx.Field("action", req.Action))
|
||||
return errs.New(errs.ErrDatabaseOperate, err)
|
||||
}
|
||||
_, err := l.svcCtx.GameAction(ctx, req.RoleID, consts.GameActionStakePoints, map[string]any{
|
||||
"level": lv.Level,
|
||||
"operation": req.Action,
|
||||
@@ -125,7 +137,7 @@ func (l *StakePointLogic) StakePoint(req *types.StakePointReq) error {
|
||||
}
|
||||
err = l.svcCtx.DBConn.TransactCtx(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
points := lv.Points - clvConfig.Points
|
||||
err = l.svcCtx.AddUserAssetWithSession(ctx, session, uint(uid), req.RoleID, consts.AssetType_Points, "", decimal.NewFromInt(int64(-points)), "stake points", 0, 0, false)
|
||||
err = l.svcCtx.AddUserAssetWithSession(ctx, session, uid, req.RoleID, consts.AssetType_Points, "", decimal.NewFromInt(int64(-points)), "stake points", 0, 0, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -137,8 +149,8 @@ func (l *StakePointLogic) StakePoint(req *types.StakePointReq) error {
|
||||
return errs.New(errs.ErrDatabaseOperate, err)
|
||||
}
|
||||
end = start.Add(time.Duration(lv.Days.Mul(decimal.NewFromInt(int64(time.Hour*24))).IntPart()) - start.Sub(clv.StartTime))
|
||||
_, err = spm.Insert(l.ctx, &model.NhStakePoints{
|
||||
Uid: uint(uid),
|
||||
_, err = spm.Insert(ctx, &model.NhStakePoints{
|
||||
Uid: uid,
|
||||
RoleId: uint64(req.RoleID),
|
||||
LevelId: lv.Id,
|
||||
Level: lv.Level,
|
||||
@@ -150,6 +162,19 @@ func (l *StakePointLogic) StakePoint(req *types.StakePointReq) error {
|
||||
if err != nil {
|
||||
return errs.New(errs.ErrDatabaseOperate, err)
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.StakePointsLogModel.WithSession(session).Insert(ctx, &model.NhStakePointsLog{
|
||||
Uid: uid,
|
||||
RoleId: uint64(req.RoleID),
|
||||
LevelId: lv.Id,
|
||||
Level: lv.Level,
|
||||
Points: int(points),
|
||||
Action: 2,
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("stake points log error", logx.Field("err", err), logx.Field("role_id", req.RoleID), logx.Field("uid", uid), logx.Field("level_id", req.LevelId), logx.Field("action", req.Action))
|
||||
return errs.New(errs.ErrDatabaseOperate, err)
|
||||
}
|
||||
_, err = l.svcCtx.GameAction(ctx, req.RoleID, consts.GameActionStakePoints, map[string]any{
|
||||
"level": lv.Level,
|
||||
"operation": req.Action,
|
||||
@@ -191,7 +216,7 @@ func (l *StakePointLogic) StakePoint(req *types.StakePointReq) error {
|
||||
err = l.svcCtx.DBConn.TransactCtx(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
points := lv.Points - clvConfig.Points
|
||||
if points > 0 {
|
||||
err = l.svcCtx.AddUserAssetWithSession(ctx, session, uint(uid), req.RoleID, consts.AssetType_Points, "", decimal.NewFromInt(int64(-points)), "stake points", 0, 0, false)
|
||||
err = l.svcCtx.AddUserAssetWithSession(ctx, session, uid, req.RoleID, consts.AssetType_Points, "", decimal.NewFromInt(int64(-points)), "stake points", 0, 0, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -204,8 +229,8 @@ func (l *StakePointLogic) StakePoint(req *types.StakePointReq) error {
|
||||
return errs.New(errs.ErrDatabaseOperate, err)
|
||||
}
|
||||
end = clv.EndTime.Add(time.Duration(lv.Days.Mul(decimal.NewFromInt(int64(time.Hour * 24))).IntPart()))
|
||||
_, err = spm.Insert(l.ctx, &model.NhStakePoints{
|
||||
Uid: uint(uid),
|
||||
_, err = spm.Insert(ctx, &model.NhStakePoints{
|
||||
Uid: uid,
|
||||
RoleId: uint64(req.RoleID),
|
||||
LevelId: lv.Id,
|
||||
Level: lv.Level,
|
||||
@@ -217,6 +242,18 @@ func (l *StakePointLogic) StakePoint(req *types.StakePointReq) error {
|
||||
if err != nil {
|
||||
return errs.New(errs.ErrDatabaseOperate, err)
|
||||
}
|
||||
_, err = l.svcCtx.StakePointsLogModel.WithSession(session).Insert(ctx, &model.NhStakePointsLog{
|
||||
Uid: uid,
|
||||
RoleId: uint64(req.RoleID),
|
||||
LevelId: lv.Id,
|
||||
Level: lv.Level,
|
||||
Points: int(points),
|
||||
Action: 3,
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("stake points log error", logx.Field("err", err), logx.Field("role_id", req.RoleID), logx.Field("uid", uid), logx.Field("level_id", req.LevelId), logx.Field("action", req.Action))
|
||||
return errs.New(errs.ErrDatabaseOperate, err)
|
||||
}
|
||||
_, err = l.svcCtx.GameAction(ctx, req.RoleID, consts.GameActionStakePoints, map[string]any{
|
||||
"level": lv.Level,
|
||||
"operation": req.Action,
|
||||
|
||||
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
|
||||
}
|
||||
@@ -43,6 +43,7 @@ type dbModel struct {
|
||||
|
||||
StakePointConfigModel model.NhStakeHomePointConfigModel
|
||||
StakePointsModel model.NhStakePointsModel
|
||||
StakePointsLogModel model.NhStakePointsLogModel
|
||||
}
|
||||
|
||||
func newDBModel(dbConn, gameConn sqlx.SqlConn, configModel model.NhSystemConfigModel) *dbModel {
|
||||
@@ -74,6 +75,7 @@ func newDBModel(dbConn, gameConn sqlx.SqlConn, configModel model.NhSystemConfigM
|
||||
PioneerRewardsModel: model.NewNhPioneerRewardsModel(dbConn),
|
||||
StakePointConfigModel: model.NewNhStakeHomePointConfigModel(dbConn),
|
||||
StakePointsModel: model.NewNhStakePointsModel(dbConn),
|
||||
StakePointsLogModel: model.NewNhStakePointsLogModel(dbConn),
|
||||
GameServerNotifyModel: model.NewNhGameServerNotifyModel(dbConn),
|
||||
RequestServerLogModel: model.NewNhRequestServerLogModel(dbConn),
|
||||
|
||||
|
||||
@@ -85,6 +85,17 @@ type GetStakeLevelListResp struct {
|
||||
Levels []PointStakeLevel `json:"levels"` // 档位列表
|
||||
}
|
||||
|
||||
type GetStakeLogListReq struct {
|
||||
RoleID uint64 `form:"role_id,optional"` // 角色id
|
||||
Page int `form:"page"` // 页码
|
||||
Size int `form:"size"` // 每页数量
|
||||
}
|
||||
|
||||
type GetStakeLogListResp struct {
|
||||
Total int `json:"total"` // 总数
|
||||
List []StakeLog `json:"list"` // 列表
|
||||
}
|
||||
|
||||
type GetTaskListReq struct {
|
||||
CommunityId uint `form:"community_id,optional"` // 所属社区ID
|
||||
}
|
||||
@@ -159,6 +170,16 @@ type StakeLevel struct {
|
||||
CanRenew bool `json:"can_renew"` // 是否可续约
|
||||
}
|
||||
|
||||
type StakeLog struct {
|
||||
Id uint `json:"id"` // id
|
||||
RoleID uint64 `json:"role_id"` // 角色id
|
||||
LevelId uint `json:"level_id"` // 档位id
|
||||
Level uint `json:"level"` // 精灵等级
|
||||
Points int `json:"points"` // 积分数量
|
||||
Action uint8 `json:"action"` // 操作类型:1=质押,2=升级,3=续约,4=解除
|
||||
CreatedAt int64 `json:"created_at"` // 创建时间
|
||||
}
|
||||
|
||||
type StakeNftList struct {
|
||||
RoleId uint64 `json:"role_id,optional"` // 角色id
|
||||
TokenIds []string `json:"token_ids"` // nft列表
|
||||
|
||||
Reference in New Issue
Block a user