完善数据上报,每日支付任务认证

This commit is contained in:
lianghuanjie
2024-12-20 17:50:24 +08:00
parent a3c4adfa25
commit bbbc750af2
17 changed files with 505 additions and 13 deletions

View File

@@ -0,0 +1,27 @@
package model
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ NhSystemConfigModel = (*customNhSystemConfigModel)(nil)
type (
// NhSystemConfigModel is an interface to be customized, add more methods here,
// and implement the added methods in customNhSystemConfigModel.
NhSystemConfigModel interface {
nhSystemConfigModel
}
customNhSystemConfigModel struct {
*defaultNhSystemConfigModel
}
)
// NewNhSystemConfigModel returns a model for the database table.
func NewNhSystemConfigModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) NhSystemConfigModel {
return &customNhSystemConfigModel{
defaultNhSystemConfigModel: newNhSystemConfigModel(conn, c, opts...),
}
}

View File

@@ -0,0 +1,155 @@
// 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/cache"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
nhSystemConfigFieldNames = builder.RawFieldNames(&NhSystemConfig{})
nhSystemConfigRows = strings.Join(nhSystemConfigFieldNames, ",")
nhSystemConfigRowsExpectAutoSet = strings.Join(stringx.Remove(nhSystemConfigFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
nhSystemConfigRowsWithPlaceHolder = strings.Join(stringx.Remove(nhSystemConfigFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
cacheNovaHomeNhSystemConfigIdPrefix = "cache:novaHome:nhSystemConfig:id:"
cacheNovaHomeNhSystemConfigNamePrefix = "cache:novaHome:nhSystemConfig:name:"
)
type (
nhSystemConfigModel interface {
Insert(ctx context.Context, data *NhSystemConfig) (sql.Result, error)
FindOne(ctx context.Context, id uint64) (*NhSystemConfig, error)
FindOneByName(ctx context.Context, name string) (*NhSystemConfig, error)
Update(ctx context.Context, data *NhSystemConfig) error
Delete(ctx context.Context, id uint64) error
}
defaultNhSystemConfigModel struct {
sqlc.CachedConn
table string
}
NhSystemConfig struct {
Id uint64 `db:"id"`
Module string `db:"module"` // 模块
Name string `db:"name"` // 变量名
Type string `db:"type"` // 类型text,radio,checkbox,select,input,array等等
Value string `db:"value"` // 变量值
Remark string `db:"remark"` // 变量注释
Sort uint64 `db:"sort"` // 排序
CreatedId uint `db:"created_id"` // 创建人ID
UpdatedId uint `db:"updated_id"` // 修改人ID
CreatedAt time.Time `db:"created_at"` // 创建时间
UpdatedAt time.Time `db:"updated_at"` // 修改时间
}
)
func newNhSystemConfigModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultNhSystemConfigModel {
return &defaultNhSystemConfigModel{
CachedConn: sqlc.NewConn(conn, c, opts...),
table: "`nh_system_config`",
}
}
func (m *defaultNhSystemConfigModel) Delete(ctx context.Context, id uint64) error {
data, err := m.FindOne(ctx, id)
if err != nil {
return err
}
novaHomeNhSystemConfigIdKey := fmt.Sprintf("%s%v", cacheNovaHomeNhSystemConfigIdPrefix, id)
novaHomeNhSystemConfigNameKey := fmt.Sprintf("%s%v", cacheNovaHomeNhSystemConfigNamePrefix, data.Name)
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
return conn.ExecCtx(ctx, query, id)
}, novaHomeNhSystemConfigIdKey, novaHomeNhSystemConfigNameKey)
return err
}
func (m *defaultNhSystemConfigModel) FindOne(ctx context.Context, id uint64) (*NhSystemConfig, error) {
novaHomeNhSystemConfigIdKey := fmt.Sprintf("%s%v", cacheNovaHomeNhSystemConfigIdPrefix, id)
var resp NhSystemConfig
err := m.QueryRowCtx(ctx, &resp, novaHomeNhSystemConfigIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhSystemConfigRows, m.table)
return conn.QueryRowCtx(ctx, v, query, id)
})
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultNhSystemConfigModel) FindOneByName(ctx context.Context, name string) (*NhSystemConfig, error) {
novaHomeNhSystemConfigNameKey := fmt.Sprintf("%s%v", cacheNovaHomeNhSystemConfigNamePrefix, name)
var resp NhSystemConfig
err := m.QueryRowIndexCtx(ctx, &resp, novaHomeNhSystemConfigNameKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where `name` = ? limit 1", nhSystemConfigRows, m.table)
if err := conn.QueryRowCtx(ctx, &resp, query, name); err != nil {
return nil, err
}
return resp.Id, nil
}, m.queryPrimary)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultNhSystemConfigModel) Insert(ctx context.Context, data *NhSystemConfig) (sql.Result, error) {
novaHomeNhSystemConfigIdKey := fmt.Sprintf("%s%v", cacheNovaHomeNhSystemConfigIdPrefix, data.Id)
novaHomeNhSystemConfigNameKey := fmt.Sprintf("%s%v", cacheNovaHomeNhSystemConfigNamePrefix, data.Name)
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, nhSystemConfigRowsExpectAutoSet)
return conn.ExecCtx(ctx, query, data.Module, data.Name, data.Type, data.Value, data.Remark, data.Sort, data.CreatedId, data.UpdatedId)
}, novaHomeNhSystemConfigIdKey, novaHomeNhSystemConfigNameKey)
return ret, err
}
func (m *defaultNhSystemConfigModel) Update(ctx context.Context, newData *NhSystemConfig) error {
data, err := m.FindOne(ctx, newData.Id)
if err != nil {
return err
}
novaHomeNhSystemConfigIdKey := fmt.Sprintf("%s%v", cacheNovaHomeNhSystemConfigIdPrefix, data.Id)
novaHomeNhSystemConfigNameKey := fmt.Sprintf("%s%v", cacheNovaHomeNhSystemConfigNamePrefix, data.Name)
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhSystemConfigRowsWithPlaceHolder)
return conn.ExecCtx(ctx, query, newData.Module, newData.Name, newData.Type, newData.Value, newData.Remark, newData.Sort, newData.CreatedId, newData.UpdatedId, newData.Id)
}, novaHomeNhSystemConfigIdKey, novaHomeNhSystemConfigNameKey)
return err
}
func (m *defaultNhSystemConfigModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cacheNovaHomeNhSystemConfigIdPrefix, primary)
}
func (m *defaultNhSystemConfigModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhSystemConfigRows, m.table)
return conn.QueryRowCtx(ctx, v, query, primary)
}
func (m *defaultNhSystemConfigModel) tableName() string {
return m.table
}

View File

@@ -1,6 +1,11 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
import (
"context"
"errors"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ NhTouristBindModel = (*customNhTouristBindModel)(nil)
@@ -10,13 +15,29 @@ type (
NhTouristBindModel interface {
nhTouristBindModel
withSession(session sqlx.Session) NhTouristBindModel
FindRequirePushUser(ctx context.Context, shareUid uint) ([]NhTouristBindUser, error)
}
customNhTouristBindModel struct {
*defaultNhTouristBindModel
}
NhTouristBindUser struct {
Id uint `db:"id"`
Uid uint `db:"uid"`
}
)
func (m *customNhTouristBindModel) FindRequirePushUser(ctx context.Context, shareUid uint) ([]NhTouristBindUser, error) {
query := fmt.Sprintf("SELECT t2.id, t1.uid FROM nh_tourist_bind t1 JOIN nh_promote_bind t2 ON t1.uid = t2.invited_uid WHERE t2.share_uid = ? AND t2.is_push_role = 0;")
var resp []NhTouristBindUser
err := m.conn.QueryRowsCtx(ctx, &resp, query, shareUid)
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
return nil, err
}
return resp, nil
}
// NewNhTouristBindModel returns a model for the database table.
func NewNhTouristBindModel(conn sqlx.SqlConn) NhTouristBindModel {
return &customNhTouristBindModel{

View File

@@ -40,6 +40,7 @@ type (
TouristAccount string `db:"tourist_account"` // 游客账号
FormalAccount string `db:"formal_account"` // 正式账号
CreateTime int `db:"create_time"` // 创建时间
Uid uint `db:"uid"` // 用户ID
}
)
@@ -71,14 +72,14 @@ func (m *defaultNhTouristBindModel) FindOne(ctx context.Context, id int) (*NhTou
}
func (m *defaultNhTouristBindModel) Insert(ctx context.Context, data *NhTouristBind) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?)", m.table, nhTouristBindRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.TouristAccount, data.FormalAccount)
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?)", m.table, nhTouristBindRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.TouristAccount, data.FormalAccount, data.Uid)
return ret, err
}
func (m *defaultNhTouristBindModel) Update(ctx context.Context, data *NhTouristBind) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhTouristBindRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.TouristAccount, data.FormalAccount, data.Id)
_, err := m.conn.ExecCtx(ctx, query, data.TouristAccount, data.FormalAccount, data.Uid, data.Id)
return err
}

View File

@@ -0,0 +1,41 @@
package model
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ NhWalletModel = (*customNhWalletModel)(nil)
type (
// NhWalletModel is an interface to be customized, add more methods here,
// and implement the added methods in customNhWalletModel.
NhWalletModel interface {
nhWalletModel
withSession(session sqlx.Session) NhWalletModel
FindWalletByAddress(ctx context.Context, address ...string) (uint, error)
}
customNhWalletModel struct {
*defaultNhWalletModel
}
)
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)
var uid uint
err := m.conn.QueryRowCtx(ctx, &uid, query, address)
return uid, err
}
// NewNhWalletModel returns a model for the database table.
func NewNhWalletModel(conn sqlx.SqlConn) NhWalletModel {
return &customNhWalletModel{
defaultNhWalletModel: newNhWalletModel(conn),
}
}
func (m *customNhWalletModel) withSession(session sqlx.Session) NhWalletModel {
return NewNhWalletModel(sqlx.NewSqlConnFromSession(session))
}

View File

@@ -0,0 +1,90 @@
// Code generated by goctl. DO NOT EDIT.
// versions:
// goctl version: 1.7.3
package model
import (
"context"
"database/sql"
"fmt"
"strings"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
nhWalletFieldNames = builder.RawFieldNames(&NhWallet{})
nhWalletRows = strings.Join(nhWalletFieldNames, ",")
nhWalletRowsExpectAutoSet = strings.Join(stringx.Remove(nhWalletFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
nhWalletRowsWithPlaceHolder = strings.Join(stringx.Remove(nhWalletFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
nhWalletModel interface {
Insert(ctx context.Context, data *NhWallet) (sql.Result, error)
FindOne(ctx context.Context, id int) (*NhWallet, error)
Update(ctx context.Context, data *NhWallet) error
Delete(ctx context.Context, id int) error
}
defaultNhWalletModel struct {
conn sqlx.SqlConn
table string
}
NhWallet struct {
Id int `db:"id"`
Uid sql.NullInt64 `db:"uid"`
Address sql.NullString `db:"address"`
Type string `db:"type"` // 区块连钱包类型
Iid sql.NullInt64 `db:"iid"` // nh_invite_code表的ID钱包在检查持有NFT的情况下会分配一个邀请码/测试码给它
CreateTime sql.NullInt64 `db:"create_time"`
Status int8 `db:"status"` // 0:正常1:删除
}
)
func newNhWalletModel(conn sqlx.SqlConn) *defaultNhWalletModel {
return &defaultNhWalletModel{
conn: conn,
table: "`nh_wallet`",
}
}
func (m *defaultNhWalletModel) 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 *defaultNhWalletModel) FindOne(ctx context.Context, id int) (*NhWallet, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhWalletRows, m.table)
var resp NhWallet
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 *defaultNhWalletModel) Insert(ctx context.Context, data *NhWallet) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, nhWalletRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Uid, data.Address, data.Type, data.Iid, data.Status)
return ret, err
}
func (m *defaultNhWalletModel) Update(ctx context.Context, data *NhWallet) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhWalletRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.Uid, data.Address, data.Type, data.Iid, data.Status, data.Id)
return err
}
func (m *defaultNhWalletModel) tableName() string {
return m.table
}