nft stake task logic
This commit is contained in:
@@ -37,5 +37,17 @@ func (c *Cron) Run() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stakes, err := c.svcCtx.StakeNftModel.AllStakeNft(c.ctx)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorw("get all stake nft failed", logx.Field("err", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range stakes {
|
||||||
|
if s.State != 1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logx.Debugw("run settle cron task")
|
logx.Debugw("run settle cron task")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,9 @@ import (
|
|||||||
"nova_task/internal/model"
|
"nova_task/internal/model"
|
||||||
"nova_task/internal/pkg/errs"
|
"nova_task/internal/pkg/errs"
|
||||||
"nova_task/internal/pkg/utils"
|
"nova_task/internal/pkg/utils"
|
||||||
"time"
|
|
||||||
|
|
||||||
"nova_task/internal/svc"
|
"nova_task/internal/svc"
|
||||||
"nova_task/internal/types"
|
"nova_task/internal/types"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
@@ -53,7 +52,9 @@ func (l *GetNftListLogic) GetNftList() (*types.UserNftList, error) {
|
|||||||
nft, err := l.svcCtx.StakeNftModel.FindOneByUidTokenId(l.ctx, uid, token)
|
nft, err := l.svcCtx.StakeNftModel.FindOneByUidTokenId(l.ctx, uid, token)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
hasStake = nft.State == 1
|
hasStake = nft.State == 1
|
||||||
stakeAt = nft.UpdatedAt.Format(time.DateOnly)
|
if hasStake {
|
||||||
|
stakeAt = nft.UpdatedAt.Format(time.DateOnly)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
nftList = append(nftList, types.UserNft{
|
nftList = append(nftList, types.UserNft{
|
||||||
TokenId: token,
|
TokenId: token,
|
||||||
|
|||||||
@@ -53,12 +53,35 @@ func (l *GetStakeTaskDetailLogic) GetStakeTaskDetail() (*types.StakeTaskDetail,
|
|||||||
gameBonus = taskConf.OccupyPercent
|
gameBonus = taskConf.OccupyPercent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stakeNfts, err := l.svcCtx.StakeNftModel.FindByUid(l.ctx, uid)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("get user stake nft failed", logx.Field("err", err))
|
||||||
|
return nil, errs.New(errs.ErrDatabaseOperate, err)
|
||||||
|
}
|
||||||
|
var produceTokensToday float64
|
||||||
|
for _, sn := range stakeNfts {
|
||||||
|
if sn.State != 1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if utils.IsBigTarot(sn.TokenId) {
|
||||||
|
produceTokensToday += float64(taskConf.GreatTarot)
|
||||||
|
} else {
|
||||||
|
produceTokensToday += float64(taskConf.LittleTarot)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var canReceiveTokens float64
|
||||||
|
if gameBonus > 0 {
|
||||||
|
canReceiveTokens = produceTokensToday * float64(100+gameBonus) / 100
|
||||||
|
} else {
|
||||||
|
canReceiveTokens = produceTokensToday
|
||||||
|
}
|
||||||
|
|
||||||
return &types.StakeTaskDetail{
|
return &types.StakeTaskDetail{
|
||||||
StartDate: start.Format(time.DateOnly),
|
StartDate: start.Format(time.DateOnly),
|
||||||
EndDate: end.Format(time.DateOnly),
|
EndDate: end.Format(time.DateOnly),
|
||||||
CountDown: utils.TodayRemainSeconds(),
|
CountDown: utils.TodayRemainSeconds(),
|
||||||
ProduceTokensToday: 0,
|
ProduceTokensToday: produceTokensToday,
|
||||||
GameBonus: gameBonus,
|
GameBonus: gameBonus,
|
||||||
CanReceiveTokens: 0,
|
CanReceiveTokens: canReceiveTokens,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
)
|
)
|
||||||
@@ -16,6 +17,8 @@ type (
|
|||||||
withSession(session sqlx.Session) NhTaskNftStakeModel
|
withSession(session sqlx.Session) NhTaskNftStakeModel
|
||||||
StakeNft(ctx context.Context, uid uint, tokens []string) error
|
StakeNft(ctx context.Context, uid uint, tokens []string) error
|
||||||
UnStakeNft(ctx context.Context, uid uint, token string) error
|
UnStakeNft(ctx context.Context, uid uint, token string) error
|
||||||
|
FindByUid(ctx context.Context, uid uint) ([]NhTaskNftStake, error)
|
||||||
|
AllStakeNft(ctx context.Context) ([]NhTaskNftStake, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
customNhTaskNftStakeModel struct {
|
customNhTaskNftStakeModel struct {
|
||||||
@@ -23,6 +26,26 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (m *customNhTaskNftStakeModel) AllStakeNft(ctx context.Context) ([]NhTaskNftStake, error) {
|
||||||
|
query := fmt.Sprintf("SELECT %s FROM %s WHERE `state` = 1", nhTaskNftStakeRows, m.table)
|
||||||
|
var result []NhTaskNftStake
|
||||||
|
err := m.conn.QueryRowsCtx(ctx, &result, query)
|
||||||
|
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *customNhTaskNftStakeModel) FindByUid(ctx context.Context, uid uint) ([]NhTaskNftStake, error) {
|
||||||
|
query := fmt.Sprintf("SELECT %s FROM %s WHERE `uid` = ?", nhTaskNftStakeRows, m.table)
|
||||||
|
var list []NhTaskNftStake
|
||||||
|
err := m.conn.QueryRowsCtx(ctx, &list, query, uid)
|
||||||
|
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return list, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m *customNhTaskNftStakeModel) UnStakeNft(ctx context.Context, uid uint, token string) error {
|
func (m *customNhTaskNftStakeModel) UnStakeNft(ctx context.Context, uid uint, token string) error {
|
||||||
update := fmt.Sprintf("UPDATE %s SET `state` = 0 WHERE `uid` = ? AND `token_id` = ?", m.table)
|
update := fmt.Sprintf("UPDATE %s SET `state` = 0 WHERE `uid` = ? AND `token_id` = ?", m.table)
|
||||||
_, err := m.conn.ExecCtx(ctx, update, uid, token)
|
_, err := m.conn.ExecCtx(ctx, update, uid, token)
|
||||||
|
|||||||
38
internal/pkg/utils/big_tarot.go
Normal file
38
internal/pkg/utils/big_tarot.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
var bitTarot = map[string]bool{
|
||||||
|
"288": true,
|
||||||
|
"297": true,
|
||||||
|
"298": true,
|
||||||
|
"300": true,
|
||||||
|
"308": true,
|
||||||
|
"311": true,
|
||||||
|
"333": true,
|
||||||
|
"336": true,
|
||||||
|
"349": true,
|
||||||
|
"357": true,
|
||||||
|
"366": true,
|
||||||
|
"367": true,
|
||||||
|
"388": true,
|
||||||
|
"396": true,
|
||||||
|
"406": true,
|
||||||
|
"409": true,
|
||||||
|
"418": true,
|
||||||
|
"419": true,
|
||||||
|
"436": true,
|
||||||
|
"456": true,
|
||||||
|
"503": true,
|
||||||
|
"564": true,
|
||||||
|
"58": true,
|
||||||
|
"26": true,
|
||||||
|
"82": true,
|
||||||
|
"152": true,
|
||||||
|
"186": true,
|
||||||
|
"379": true,
|
||||||
|
"500": true,
|
||||||
|
"523": true,
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsBigTarot(tarotId string) bool {
|
||||||
|
return bitTarot[tarotId]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user