先锋赛季账号汇总数据接口
This commit is contained in:
57
internal/logic/task/pioneer_reward_logic.go
Normal file
57
internal/logic/task/pioneer_reward_logic.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user