diff --git a/doc/api/task.api b/doc/api/task.api index 5957e86..abdc7a0 100644 --- a/doc/api/task.api +++ b/doc/api/task.api @@ -47,6 +47,10 @@ service novatask { @doc "质押奖励发放列表" @handler StakeRewardList get /nft/stake_reward returns (StakeRewardList) + + @doc "赛季奖励数据" + @handler PioneerReward + get /pioneer_reward returns (PioneerReward) } type GetTaskListReq { @@ -156,3 +160,11 @@ type StakeRewardList { RewardList []StakeReward `json:"reward_list"` } +type PioneerReward { + InGame float64 `json:"in_game"` // 游戏代币 + Stake float64 `json:"stake"` // 挖矿代币 + Ambassador float64 `json:"ambassador"` // 大使额外代币 + NftBonus float64 `json:"nft_bonus"` // nft 加成 + Total float64 `json:"total"` // 总额 +} + diff --git a/doc/swagger/nova.json b/doc/swagger/nova.json index fe2ee10..05906ba 100644 --- a/doc/swagger/nova.json +++ b/doc/swagger/nova.json @@ -571,6 +571,28 @@ ] } }, + "/gapi/task/v1/pioneer_reward": { + "get": { + "summary": "赛季奖励数据", + "operationId": "PioneerReward", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/PioneerReward" + } + } + }, + "tags": [ + "task" + ], + "security": [ + { + "apiKey": [] + } + ] + } + }, "/gapi/task/v1/reward": { "get": { "summary": "领取任务奖励", @@ -1046,6 +1068,44 @@ "type" ] }, + "PioneerReward": { + "type": "object", + "properties": { + "in_game": { + "type": "number", + "format": "double", + "description": " 游戏代币" + }, + "stake": { + "type": "number", + "format": "double", + "description": " 挖矿代币" + }, + "ambassador": { + "type": "number", + "format": "double", + "description": " 大使额外代币" + }, + "nft_bonus": { + "type": "number", + "format": "double", + "description": " nft 加成" + }, + "total": { + "type": "number", + "format": "double", + "description": " 总额" + } + }, + "title": "PioneerReward", + "required": [ + "in_game", + "stake", + "ambassador", + "nft_bonus", + "total" + ] + }, "Result": { "type": "object", "properties": { diff --git a/internal/handler/routes.go b/internal/handler/routes.go index 4f6b06a..279074b 100644 --- a/internal/handler/routes.go +++ b/internal/handler/routes.go @@ -1,5 +1,5 @@ // Code generated by goctl. DO NOT EDIT. -// goctl 1.7.3 +// goctl 1.7.6 package handler @@ -169,6 +169,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/nfts", Handler: task.GetNftListHandler(serverCtx), }, + { + // 赛季奖励数据 + Method: http.MethodGet, + Path: "/pioneer_reward", + Handler: task.PioneerRewardHandler(serverCtx), + }, { // 领取任务奖励 Method: http.MethodGet, diff --git a/internal/handler/task/pioneer_reward_handler.go b/internal/handler/task/pioneer_reward_handler.go new file mode 100644 index 0000000..fca9fb1 --- /dev/null +++ b/internal/handler/task/pioneer_reward_handler.go @@ -0,0 +1,22 @@ +package task + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "nova_task/internal/logic/task" + "nova_task/internal/svc" +) + +// 赛季奖励数据 +func PioneerRewardHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + l := task.NewPioneerRewardLogic(r.Context(), svcCtx) + resp, err := l.PioneerReward() + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/internal/logic/task/pioneer_reward_logic.go b/internal/logic/task/pioneer_reward_logic.go new file mode 100644 index 0000000..a0baa17 --- /dev/null +++ b/internal/logic/task/pioneer_reward_logic.go @@ -0,0 +1,57 @@ +package task + +import ( + "context" + "errors" + "nova_task/internal/model" + "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 PioneerRewardLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// 赛季奖励数据 +func NewPioneerRewardLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PioneerRewardLogic { + return &PioneerRewardLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *PioneerRewardLogic) PioneerReward() (resp *types.PioneerReward, err error) { + uid := utils.GetUidUint(l.ctx) + u, err := l.svcCtx.UserModel.FindOne(l.ctx, uid) + if err != nil { + if errors.Is(err, model.ErrNotFound) { + return &types.PioneerReward{}, nil + } + l.Errorw("find user failed", logx.Field("err", err), logx.Field("uid", uid)) + return nil, errs.New(errs.ErrDatabaseOperate, err) + } + rw, err := l.svcCtx.PioneerRewardsModel.FindOneByEmail(l.ctx, u.Email) + if err != nil { + if errors.Is(err, model.ErrNotFound) { + return &types.PioneerReward{}, nil + } + l.Errorw("find season reward failed", logx.Field("err", err), logx.Field("uid", uid)) + return nil, errs.New(errs.ErrDatabaseOperate, err) + } + + return &types.PioneerReward{ + InGame: float64(rw.Amount1), + Stake: float64(rw.Amount2), + Ambassador: float64(rw.Amount4), + NftBonus: rw.Amount3.InexactFloat64(), + Total: float64(rw.Amount5), + }, nil +} diff --git a/internal/model/nh_pioneer_rewards_model.go b/internal/model/nh_pioneer_rewards_model.go new file mode 100755 index 0000000..0d3492c --- /dev/null +++ b/internal/model/nh_pioneer_rewards_model.go @@ -0,0 +1,29 @@ +package model + +import "github.com/zeromicro/go-zero/core/stores/sqlx" + +var _ NhPioneerRewardsModel = (*customNhPioneerRewardsModel)(nil) + +type ( + // NhPioneerRewardsModel is an interface to be customized, add more methods here, + // and implement the added methods in customNhPioneerRewardsModel. + NhPioneerRewardsModel interface { + nhPioneerRewardsModel + withSession(session sqlx.Session) NhPioneerRewardsModel + } + + customNhPioneerRewardsModel struct { + *defaultNhPioneerRewardsModel + } +) + +// NewNhPioneerRewardsModel returns a model for the database table. +func NewNhPioneerRewardsModel(conn sqlx.SqlConn) NhPioneerRewardsModel { + return &customNhPioneerRewardsModel{ + defaultNhPioneerRewardsModel: newNhPioneerRewardsModel(conn), + } +} + +func (m *customNhPioneerRewardsModel) withSession(session sqlx.Session) NhPioneerRewardsModel { + return NewNhPioneerRewardsModel(sqlx.NewSqlConnFromSession(session)) +} diff --git a/internal/model/nh_pioneer_rewards_model_gen.go b/internal/model/nh_pioneer_rewards_model_gen.go new file mode 100755 index 0000000..fdabde4 --- /dev/null +++ b/internal/model/nh_pioneer_rewards_model_gen.go @@ -0,0 +1,110 @@ +// 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" + + "github.com/shopspring/decimal" +) + +var ( + nhPioneerRewardsFieldNames = builder.RawFieldNames(&NhPioneerRewards{}) + nhPioneerRewardsRows = strings.Join(nhPioneerRewardsFieldNames, ",") + nhPioneerRewardsRowsExpectAutoSet = strings.Join(stringx.Remove(nhPioneerRewardsFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") + nhPioneerRewardsRowsWithPlaceHolder = strings.Join(stringx.Remove(nhPioneerRewardsFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" +) + +type ( + nhPioneerRewardsModel interface { + Insert(ctx context.Context, data *NhPioneerRewards) (sql.Result, error) + FindOne(ctx context.Context, id uint) (*NhPioneerRewards, error) + FindOneByEmail(ctx context.Context, email string) (*NhPioneerRewards, error) + Update(ctx context.Context, data *NhPioneerRewards) error + Delete(ctx context.Context, id uint) error + } + + defaultNhPioneerRewardsModel struct { + conn sqlx.SqlConn + table string + } + + NhPioneerRewards struct { + Id uint `db:"id"` + Email string `db:"email"` + Amount1 uint `db:"amount1"` // 游戏代币 + Amount2 uint `db:"amount2"` // 挖矿代币 + Amount3 decimal.Decimal `db:"amount3"` // NFT加成 + Amount4 uint `db:"amount4"` // 大使额外代币 + Amount5 uint `db:"amount5"` // 总代币 + CreatedAt time.Time `db:"created_at"` // 创建时间 + UpdatedAt time.Time `db:"updated_at"` // 修改时间 + } +) + +func newNhPioneerRewardsModel(conn sqlx.SqlConn) *defaultNhPioneerRewardsModel { + return &defaultNhPioneerRewardsModel{ + conn: conn, + table: "`nh_pioneer_rewards`", + } +} + +func (m *defaultNhPioneerRewardsModel) 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 *defaultNhPioneerRewardsModel) FindOne(ctx context.Context, id uint) (*NhPioneerRewards, error) { + query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhPioneerRewardsRows, m.table) + var resp NhPioneerRewards + 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 *defaultNhPioneerRewardsModel) FindOneByEmail(ctx context.Context, email string) (*NhPioneerRewards, error) { + var resp NhPioneerRewards + query := fmt.Sprintf("select %s from %s where `email` = ? limit 1", nhPioneerRewardsRows, m.table) + err := m.conn.QueryRowCtx(ctx, &resp, query, email) + switch err { + case nil: + return &resp, nil + case sqlx.ErrNotFound: + return nil, ErrNotFound + default: + return nil, err + } +} + +func (m *defaultNhPioneerRewardsModel) Insert(ctx context.Context, data *NhPioneerRewards) (sql.Result, error) { + query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?)", m.table, nhPioneerRewardsRowsExpectAutoSet) + ret, err := m.conn.ExecCtx(ctx, query, data.Email, data.Amount1, data.Amount2, data.Amount3, data.Amount4, data.Amount5) + return ret, err +} + +func (m *defaultNhPioneerRewardsModel) Update(ctx context.Context, newData *NhPioneerRewards) error { + query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhPioneerRewardsRowsWithPlaceHolder) + _, err := m.conn.ExecCtx(ctx, query, newData.Email, newData.Amount1, newData.Amount2, newData.Amount3, newData.Amount4, newData.Amount5, newData.Id) + return err +} + +func (m *defaultNhPioneerRewardsModel) tableName() string { + return m.table +} diff --git a/internal/svc/service_context.go b/internal/svc/service_context.go index f8e6e1f..59c72ab 100644 --- a/internal/svc/service_context.go +++ b/internal/svc/service_context.go @@ -47,6 +47,7 @@ type ServiceContext struct { RoleModel model.NhRoleModel GamesPropertyModel model.NhGamesPropertyLogsModel AirdropModel model.NhAirdropLogModel + PioneerRewardsModel model.NhPioneerRewardsModel ApiKeyCheck rest.Middleware AdminSecretCheck rest.Middleware @@ -88,6 +89,7 @@ func NewServiceContext(c config.Config) *ServiceContext { RoleModel: model.NewNhRoleModel(dbConn), GamesPropertyModel: model.NewNhGamesPropertyLogsModel(dbConn), AirdropModel: model.NewNhAirdropLogModel(dbConn), + PioneerRewardsModel: model.NewNhPioneerRewardsModel(dbConn), ApiKeyCheck: middleware.NewApiKeyCheckMiddleware(configModel).Handle, AdminSecretCheck: middleware.NewAdminSecretCheckMiddleware(configModel).Handle, diff --git a/internal/types/types.go b/internal/types/types.go index fb31e5b..9363982 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -1,5 +1,5 @@ // Code generated by goctl. DO NOT EDIT. -// goctl 1.7.3 +// goctl 1.7.6 package types @@ -96,6 +96,14 @@ type KGeNTaskCheckReq struct { Type int8 `form:"type"` // 1.在官网注册(是否) 2.链接钱包(是否) 3.下载并绑定游戏账号(是否) } +type PioneerReward struct { + InGame float64 `json:"in_game"` // 游戏代币 + Stake float64 `json:"stake"` // 挖矿代币 + Ambassador float64 `json:"ambassador"` // 大使额外代币 + NftBonus float64 `json:"nft_bonus"` // nft 加成 + Total float64 `json:"total"` // 总额 +} + type Result struct { IsValid bool `json:"isValid"` }