nft stake task logic
This commit is contained in:
@@ -2,6 +2,7 @@ package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
@@ -16,6 +17,8 @@ type (
|
||||
withSession(session sqlx.Session) NhTaskNftStakeModel
|
||||
StakeNft(ctx context.Context, uid uint, tokens []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 {
|
||||
@@ -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 {
|
||||
update := fmt.Sprintf("UPDATE %s SET `state` = 0 WHERE `uid` = ? AND `token_id` = ?", m.table)
|
||||
_, err := m.conn.ExecCtx(ctx, update, uid, token)
|
||||
|
||||
Reference in New Issue
Block a user