From 95a4337ab3aaf5d76cd8068f9c1d176317821b9c Mon Sep 17 00:00:00 2001 From: yuming88 Date: Mon, 28 Apr 2025 20:03:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8F=90=E5=8F=96castile?= =?UTF-8?q?=E5=88=B0=E6=B8=B8=E6=88=8F=E5=86=85=E7=9A=84=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/api/transfercastile.api | 13 +++++---- doc/swagger/nova.json | 26 ++++++++++++++++-- internal/consts/consts.go | 4 +++ .../transfer_castile_to_game_list_logic.go | 27 ++++++++++++++++--- .../transfer_castile_to_game_logic.go | 9 ++++--- internal/model/nh_castile_token_log_model.go | 20 ++++++++++++++ internal/types/types.go | 13 +++++---- 7 files changed, 93 insertions(+), 19 deletions(-) diff --git a/doc/api/transfercastile.api b/doc/api/transfercastile.api index 97bb630..9efa599 100644 --- a/doc/api/transfercastile.api +++ b/doc/api/transfercastile.api @@ -12,7 +12,7 @@ service novatask { @doc "获取提取castile到游戏的记录" @handler TransferCastileToGameList - post /list (TransferCastileToGameListReq) returns (TransferCastileToGameResp) + post /list (TransferCastileToGameListReq) returns (TransferCastileToGameListResp) } type TransferCastileToGameReq { @@ -22,13 +22,16 @@ type TransferCastileToGameReq { type TransferCastileToGameListReq { RoleID int64 `json:"role_id,optional"` // 角色id + Page int `form:"page,range=[1:],optional,default=1"` // 页码 + Size int `form:"size,range=[10:100],optional,default=10"` // 每页数量 } type TransferCastileToGameResp { - Id int `json:"id"` // id - RoleID int64 `json:"role_id"` // 角色id - Amount int64 `json:"amount"` // 数量 - Status int64 `json:"status"` // 状态 + Id int `json:"id"` // id + RoleID int64 `json:"role_id"` // 角色id + Amount int64 `json:"amount"` // 数量 + Status int64 `json:"status"` // 状态 + CreatedAt string `json:"created_at"` // 创建时间 } type TransferCastileToGameListResp { diff --git a/doc/swagger/nova.json b/doc/swagger/nova.json index 4ee0212..33bad16 100644 --- a/doc/swagger/nova.json +++ b/doc/swagger/nova.json @@ -903,7 +903,7 @@ "200": { "description": "A successful response.", "schema": { - "$ref": "#/definitions/TransferCastileToGameResp" + "$ref": "#/definitions/TransferCastileToGameListResp" } } }, @@ -920,6 +920,9 @@ "tags": [ "transfercastile" ], + "consumes": [ + "multipart/form-data" + ], "security": [ { "apiKey": [] @@ -1930,6 +1933,20 @@ "type": "integer", "format": "int64", "description": " 角色id" + }, + "page": { + "type": "integer", + "format": "int32", + "default": "1", + "description": " 页码" + }, + "size": { + "type": "integer", + "format": "int32", + "default": "10", + "description": " 每页数量", + "maximum": 100, + "minimum": 10 } }, "title": "TransferCastileToGameListReq" @@ -1998,6 +2015,10 @@ "type": "integer", "format": "int64", "description": " 状态" + }, + "created_at": { + "type": "string", + "description": " 创建时间" } }, "title": "TransferCastileToGameResp", @@ -2005,7 +2026,8 @@ "id", "role_id", "amount", - "status" + "status", + "created_at" ] }, "UnStakeNftReq": { diff --git a/internal/consts/consts.go b/internal/consts/consts.go index ac95eaf..d69c015 100644 --- a/internal/consts/consts.go +++ b/internal/consts/consts.go @@ -32,6 +32,10 @@ const ( RewardCastile = 2 // 代币 ) +const ( + FORMATDATETIME = "2006-01-02 15:04:05" // 日期时间 +) + func GetAssetType(rewardType int8) AssetType { switch rewardType { case RewardTypePoints: diff --git a/internal/logic/transfercastile/transfer_castile_to_game_list_logic.go b/internal/logic/transfercastile/transfer_castile_to_game_list_logic.go index a7f91a0..f601f47 100644 --- a/internal/logic/transfercastile/transfer_castile_to_game_list_logic.go +++ b/internal/logic/transfercastile/transfer_castile_to_game_list_logic.go @@ -2,6 +2,9 @@ package transfercastile import ( "context" + "nova_task/internal/consts" + "nova_task/internal/pkg/errs" + "nova_task/internal/pkg/utils" "nova_task/internal/svc" "nova_task/internal/types" @@ -24,8 +27,26 @@ func NewTransferCastileToGameListLogic(ctx context.Context, svcCtx *svc.ServiceC } } -func (l *TransferCastileToGameListLogic) TransferCastileToGameList(req *types.TransferCastileToGameListReq) (resp *types.TransferCastileToGameResp, err error) { - // todo: add your logic here and delete this line +func (l *TransferCastileToGameListLogic) TransferCastileToGameList(req *types.TransferCastileToGameListReq) (resp *types.TransferCastileToGameListResp, err error) { - return + uid := utils.GetUidUint(l.ctx) + ls, err := l.svcCtx.CastileTokenLogModel.List(l.ctx, uid, uint64(req.RoleID), req.Page, req.Size) + if err != nil { + l.Errorw("get castile log list failed", logx.Field("err", err), logx.Field("uid", uid)) + return nil, errs.New(errs.ErrDatabaseOperate, err) + } + var lss []types.TransferCastileToGameResp + for _, ll := range ls { + lss = append(lss, types.TransferCastileToGameResp{ + Id: int(ll.Id), + RoleID: int64(ll.RoleId), + Amount: int64(ll.Amount), + Status: int64(ll.CallbackStatus), + CreatedAt: ll.CreatedAt.Format(consts.FORMATDATETIME), + }) + } + return &types.TransferCastileToGameListResp{ + List: lss, + Total: len(lss), + }, nil } diff --git a/internal/logic/transfercastile/transfer_castile_to_game_logic.go b/internal/logic/transfercastile/transfer_castile_to_game_logic.go index f6b63f2..d12eedd 100644 --- a/internal/logic/transfercastile/transfer_castile_to_game_logic.go +++ b/internal/logic/transfercastile/transfer_castile_to_game_logic.go @@ -138,9 +138,10 @@ func (l *TransferCastileToGameLogic) TransferCastileToGame(req *types.TransferCa } return &types.TransferCastileToGameResp{ - Id: int(res.Id), - RoleID: int64(res.RoleId), - Amount: int64(res.Amount), - Status: int64(res.CallbackStatus), + Id: int(res.Id), + RoleID: int64(res.RoleId), + Amount: int64(res.Amount), + Status: int64(res.CallbackStatus), + CreatedAt: res.CreatedAt.Format(consts.FORMATDATETIME), }, nil } diff --git a/internal/model/nh_castile_token_log_model.go b/internal/model/nh_castile_token_log_model.go index 62c7937..4b4beda 100644 --- a/internal/model/nh_castile_token_log_model.go +++ b/internal/model/nh_castile_token_log_model.go @@ -2,6 +2,7 @@ package model import ( "context" + "errors" "fmt" "github.com/zeromicro/go-zero/core/stores/sqlx" ) @@ -15,6 +16,7 @@ type ( nhCastileTokenLogModel WithSession(session sqlx.Session) NhCastileTokenLogModel UpdateStatus(ctx context.Context, status uint, id uint) error + List(ctx context.Context, uid uint, roleId uint64, page, pageSize int) ([]*NhCastileTokenLog, error) } customNhCastileTokenLogModel struct { @@ -38,3 +40,21 @@ func (m *customNhCastileTokenLogModel) UpdateStatus(ctx context.Context, status _, err := m.conn.ExecCtx(ctx, query, status, id) return err } + +func (m *customNhCastileTokenLogModel) List(ctx context.Context, uid uint, roleId uint64, page, pageSize int) ([]*NhCastileTokenLog, error) { + var query string + var result []*NhCastileTokenLog + var err error + if roleId == 0 { + query = fmt.Sprintf("select %s from %s where uid = ? order by id desc limit ?, ?", nhCastileTokenLogRows, m.table) + err = m.conn.QueryRowsCtx(ctx, &result, query, uid, (page-1)*pageSize, pageSize) + } else { + query = fmt.Sprintf("select %s from %s where uid = ? and role_id = ? order by id desc limit ?, ?", nhCastileTokenLogRows, m.table) + err = m.conn.QueryRowsCtx(ctx, &result, query, uid, roleId, (page-1)*pageSize, pageSize) + } + + if err != nil && !errors.Is(err, sqlx.ErrNotFound) { + return nil, err + } + return result, nil +} diff --git a/internal/types/types.go b/internal/types/types.go index 6b61e08..acd34f5 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -241,7 +241,9 @@ type Task struct { } type TransferCastileToGameListReq struct { - RoleID int64 `json:"role_id,optional"` // 角色id + RoleID int64 `json:"role_id,optional"` // 角色id + Page int `form:"page,range=[1:],optional,default=1"` // 页码 + Size int `form:"size,range=[10:100],optional,default=10"` // 每页数量 } type TransferCastileToGameListResp struct { @@ -255,10 +257,11 @@ type TransferCastileToGameReq struct { } type TransferCastileToGameResp struct { - Id int `json:"id"` // id - RoleID int64 `json:"role_id"` // 角色id - Amount int64 `json:"amount"` // 数量 - Status int64 `json:"status"` // 状态 + Id int `json:"id"` // id + RoleID int64 `json:"role_id"` // 角色id + Amount int64 `json:"amount"` // 数量 + Status int64 `json:"status"` // 状态 + CreatedAt string `json:"created_at"` // 创建时间 } type UnStakeNftReq struct {