nft持有查询定时任务

This commit is contained in:
lianghuanjie
2024-12-23 19:59:48 +08:00
parent bbbc750af2
commit a22f73df20
18 changed files with 544 additions and 53 deletions

View File

@@ -0,0 +1,29 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var _ NhNftHolderChangeLogModel = (*customNhNftHolderChangeLogModel)(nil)
type (
// NhNftHolderChangeLogModel is an interface to be customized, add more methods here,
// and implement the added methods in customNhNftHolderChangeLogModel.
NhNftHolderChangeLogModel interface {
nhNftHolderChangeLogModel
withSession(session sqlx.Session) NhNftHolderChangeLogModel
}
customNhNftHolderChangeLogModel struct {
*defaultNhNftHolderChangeLogModel
}
)
// NewNhNftHolderChangeLogModel returns a model for the database table.
func NewNhNftHolderChangeLogModel(conn sqlx.SqlConn) NhNftHolderChangeLogModel {
return &customNhNftHolderChangeLogModel{
defaultNhNftHolderChangeLogModel: newNhNftHolderChangeLogModel(conn),
}
}
func (m *customNhNftHolderChangeLogModel) withSession(session sqlx.Session) NhNftHolderChangeLogModel {
return NewNhNftHolderChangeLogModel(sqlx.NewSqlConnFromSession(session))
}

View File

@@ -0,0 +1,91 @@
// Code generated by goctl. DO NOT EDIT.
// versions:
// goctl version: 1.7.3
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"
)
var (
nhNftHolderChangeLogFieldNames = builder.RawFieldNames(&NhNftHolderChangeLog{})
nhNftHolderChangeLogRows = strings.Join(nhNftHolderChangeLogFieldNames, ",")
nhNftHolderChangeLogRowsExpectAutoSet = strings.Join(stringx.Remove(nhNftHolderChangeLogFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
nhNftHolderChangeLogRowsWithPlaceHolder = strings.Join(stringx.Remove(nhNftHolderChangeLogFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
nhNftHolderChangeLogModel interface {
Insert(ctx context.Context, data *NhNftHolderChangeLog) (sql.Result, error)
FindOne(ctx context.Context, id int) (*NhNftHolderChangeLog, error)
Update(ctx context.Context, data *NhNftHolderChangeLog) error
Delete(ctx context.Context, id int) error
}
defaultNhNftHolderChangeLogModel struct {
conn sqlx.SqlConn
table string
}
NhNftHolderChangeLog struct {
Id int `db:"id"`
Address string `db:"address"` // 钱包地址
TokenId string `db:"token_id"` // token id
Value int `db:"value"` // 变化数量
Balance int `db:"balance"` // 余额
CreatedAt time.Time `db:"created_at"` // 创建时间
UpdatedAt time.Time `db:"updated_at"` // 修改时间
}
)
func newNhNftHolderChangeLogModel(conn sqlx.SqlConn) *defaultNhNftHolderChangeLogModel {
return &defaultNhNftHolderChangeLogModel{
conn: conn,
table: "`nh_nft_holder_change_log`",
}
}
func (m *defaultNhNftHolderChangeLogModel) Delete(ctx context.Context, id int) error {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, query, id)
return err
}
func (m *defaultNhNftHolderChangeLogModel) FindOne(ctx context.Context, id int) (*NhNftHolderChangeLog, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhNftHolderChangeLogRows, m.table)
var resp NhNftHolderChangeLog
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 *defaultNhNftHolderChangeLogModel) Insert(ctx context.Context, data *NhNftHolderChangeLog) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?)", m.table, nhNftHolderChangeLogRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Address, data.TokenId, data.Value, data.Balance)
return ret, err
}
func (m *defaultNhNftHolderChangeLogModel) Update(ctx context.Context, data *NhNftHolderChangeLog) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhNftHolderChangeLogRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.Address, data.TokenId, data.Value, data.Balance, data.Id)
return err
}
func (m *defaultNhNftHolderChangeLogModel) tableName() string {
return m.table
}

View File

@@ -0,0 +1,52 @@
package model
import (
"context"
"errors"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ NhNftHolderModel = (*customNhNftHolderModel)(nil)
type (
// NhNftHolderModel is an interface to be customized, add more methods here,
// and implement the added methods in customNhNftHolderModel.
NhNftHolderModel interface {
nhNftHolderModel
withSession(session sqlx.Session) NhNftHolderModel
FindOtherUpdateSeq(ctx context.Context, updateSeq int) ([]*NhNftHolder, error)
DeleteOtherUpdateSeq(ctx context.Context, updateSeq int) error
}
customNhNftHolderModel struct {
*defaultNhNftHolderModel
}
)
func (m *customNhNftHolderModel) DeleteOtherUpdateSeq(ctx context.Context, updateSeq int) error {
delSql := fmt.Sprintf("delete from %s where `update_seq` != ?", m.table)
_, err := m.conn.ExecCtx(ctx, delSql, updateSeq)
return err
}
func (m *customNhNftHolderModel) FindOtherUpdateSeq(ctx context.Context, updateSeq int) ([]*NhNftHolder, error) {
query := fmt.Sprintf("select %s from %s where `update_seq` != ?", nhNftHolderRows, m.table)
var resp []*NhNftHolder
err := m.conn.QueryRowsCtx(ctx, &resp, query, updateSeq)
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
return nil, err
}
return resp, nil
}
// NewNhNftHolderModel returns a model for the database table.
func NewNhNftHolderModel(conn sqlx.SqlConn) NhNftHolderModel {
return &customNhNftHolderModel{
defaultNhNftHolderModel: newNhNftHolderModel(conn),
}
}
func (m *customNhNftHolderModel) withSession(session sqlx.Session) NhNftHolderModel {
return NewNhNftHolderModel(sqlx.NewSqlConnFromSession(session))
}

View File

@@ -0,0 +1,106 @@
// Code generated by goctl. DO NOT EDIT.
// versions:
// goctl version: 1.7.3
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"
)
var (
nhNftHolderFieldNames = builder.RawFieldNames(&NhNftHolder{})
nhNftHolderRows = strings.Join(nhNftHolderFieldNames, ",")
nhNftHolderRowsExpectAutoSet = strings.Join(stringx.Remove(nhNftHolderFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
nhNftHolderRowsWithPlaceHolder = strings.Join(stringx.Remove(nhNftHolderFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
nhNftHolderModel interface {
Insert(ctx context.Context, data *NhNftHolder) (sql.Result, error)
FindOne(ctx context.Context, id int) (*NhNftHolder, error)
FindOneByAddressTokenId(ctx context.Context, address string, tokenId string) (*NhNftHolder, error)
Update(ctx context.Context, data *NhNftHolder) error
Delete(ctx context.Context, id int) error
}
defaultNhNftHolderModel struct {
conn sqlx.SqlConn
table string
}
NhNftHolder struct {
Id int `db:"id"`
Address string `db:"address"` // 钱包地址
TokenId string `db:"token_id"` // token id
Balance int `db:"balance"` // 余额
UpdateSeq int `db:"update_seq"` // 更新序列号
CreatedAt time.Time `db:"created_at"` // 创建时间
UpdatedAt time.Time `db:"updated_at"` // 修改时间
}
)
func newNhNftHolderModel(conn sqlx.SqlConn) *defaultNhNftHolderModel {
return &defaultNhNftHolderModel{
conn: conn,
table: "`nh_nft_holder`",
}
}
func (m *defaultNhNftHolderModel) Delete(ctx context.Context, id int) error {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, query, id)
return err
}
func (m *defaultNhNftHolderModel) FindOne(ctx context.Context, id int) (*NhNftHolder, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhNftHolderRows, m.table)
var resp NhNftHolder
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 *defaultNhNftHolderModel) FindOneByAddressTokenId(ctx context.Context, address string, tokenId string) (*NhNftHolder, error) {
var resp NhNftHolder
query := fmt.Sprintf("select %s from %s where `address` = ? and `token_id` = ? limit 1", nhNftHolderRows, m.table)
err := m.conn.QueryRowCtx(ctx, &resp, query, address, tokenId)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultNhNftHolderModel) Insert(ctx context.Context, data *NhNftHolder) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?)", m.table, nhNftHolderRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Address, data.TokenId, data.Balance, data.UpdateSeq)
return ret, err
}
func (m *defaultNhNftHolderModel) Update(ctx context.Context, newData *NhNftHolder) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhNftHolderRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, newData.Address, newData.TokenId, newData.Balance, newData.UpdateSeq, newData.Id)
return err
}
func (m *defaultNhNftHolderModel) tableName() string {
return m.table
}

View File

@@ -53,15 +53,35 @@ func (m *customNhPromoteBindModel) FindRequirePushUser(ctx context.Context, shar
}
func (m *customNhPromoteBindModel) UpdatePushUser(ctx context.Context, id uint) error {
update := fmt.Sprintf("update %s set `is_push_user` = 1 where `id` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, update, id)
return err
update := fmt.Sprintf("update %s set `is_push_user` = 1 where `id` = ? and `is_push_user` = 0", m.table)
result, err := m.conn.ExecCtx(ctx, update, id)
if err != nil {
return err
}
row, err := result.RowsAffected()
if err != nil {
return err
}
if row == 0 {
return ErrNoRowUpdate
}
return nil
}
func (m *customNhPromoteBindModel) UpdatePushRole(ctx context.Context, id uint) error {
update := fmt.Sprintf("update %s set `is_push_role` = 1 where `id` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, update, id)
return err
update := fmt.Sprintf("update %s set `is_push_role` = 1 where `id` = ? and `is_push_role` = 0", m.table)
result, err := m.conn.ExecCtx(ctx, update, id)
if err != nil {
return err
}
row, err := result.RowsAffected()
if err != nil {
return err
}
if row == 0 {
return ErrNoRowUpdate
}
return nil
}
func (m *customNhPromoteBindModel) UserInviteCount(ctx context.Context, uid uint) (int64, error) {

View File

@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"nova_task/internal/pkg/aptos"
)
var _ NhWalletModel = (*customNhWalletModel)(nil)
@@ -14,7 +15,7 @@ type (
NhWalletModel interface {
nhWalletModel
withSession(session sqlx.Session) NhWalletModel
FindWalletByAddress(ctx context.Context, address ...string) (uint, error)
FindWalletByAddress(ctx context.Context, address string) (uint, error)
}
customNhWalletModel struct {
@@ -22,10 +23,10 @@ type (
}
)
func (m *customNhWalletModel) FindWalletByAddress(ctx context.Context, address ...string) (uint, error) {
query := fmt.Sprintf("select `uid` from %s where `address` in ? limit 1", m.table)
func (m *customNhWalletModel) FindWalletByAddress(ctx context.Context, address string) (uint, error) {
query := fmt.Sprintf("select `uid` from %s where `address` = ? or `address` = ? limit 1", m.table)
var uid uint
err := m.conn.QueryRowCtx(ctx, &uid, query, address)
err := m.conn.QueryRowCtx(ctx, &uid, query, address, aptos.StrPadAptosAddress(address))
return uid, err
}

View File

@@ -1,5 +1,9 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
import (
"errors"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var ErrNotFound = sqlx.ErrNotFound
var ErrNoRowUpdate = errors.New("no row was updated")