先锋赛季账号汇总数据接口

This commit is contained in:
2025-02-26 11:43:04 +08:00
parent 92fbd8dfd0
commit 2ca1138fbb
9 changed files with 308 additions and 2 deletions

View File

@@ -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,

View File

@@ -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)
}
}
}

View File

@@ -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
}

View File

@@ -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))
}

View File

@@ -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
}

View File

@@ -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,

View File

@@ -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"`
}