Game7 去掉上级邀请id限制

This commit is contained in:
lianghuanjie
2025-01-15 16:23:49 +08:00
parent c089a495c6
commit a0000fd343
4 changed files with 180 additions and 17 deletions

45
internal/model/nh_role_model.go Executable file
View File

@@ -0,0 +1,45 @@
package model
import (
"context"
"errors"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ NhRoleModel = (*customNhRoleModel)(nil)
type (
// NhRoleModel is an interface to be customized, add more methods here,
// and implement the added methods in customNhRoleModel.
NhRoleModel interface {
nhRoleModel
withSession(session sqlx.Session) NhRoleModel
AccountExist(ctx context.Context, account string) (bool, error)
}
customNhRoleModel struct {
*defaultNhRoleModel
}
)
func (m *customNhRoleModel) AccountExist(ctx context.Context, account string) (bool, error) {
query := fmt.Sprintf("select count(*) as `count` from %s where `account` = ?", m.table)
var count int64
err := m.conn.QueryRowCtx(ctx, &count, query, account)
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
return false, err
}
return count > 0, nil
}
// NewNhRoleModel returns a model for the database table.
func NewNhRoleModel(conn sqlx.SqlConn) NhRoleModel {
return &customNhRoleModel{
defaultNhRoleModel: newNhRoleModel(conn),
}
}
func (m *customNhRoleModel) withSession(session sqlx.Session) NhRoleModel {
return NewNhRoleModel(sqlx.NewSqlConnFromSession(session))
}

View File

@@ -0,0 +1,105 @@
// 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 (
nhRoleFieldNames = builder.RawFieldNames(&NhRole{})
nhRoleRows = strings.Join(nhRoleFieldNames, ",")
nhRoleRowsExpectAutoSet = strings.Join(stringx.Remove(nhRoleFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
nhRoleRowsWithPlaceHolder = strings.Join(stringx.Remove(nhRoleFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
nhRoleModel interface {
Insert(ctx context.Context, data *NhRole) (sql.Result, error)
FindOne(ctx context.Context, id int) (*NhRole, error)
FindOneByRoleId(ctx context.Context, roleId int64) (*NhRole, error)
Update(ctx context.Context, data *NhRole) error
Delete(ctx context.Context, id int) error
}
defaultNhRoleModel struct {
conn sqlx.SqlConn
table string
}
NhRole struct {
Id int `db:"id"`
RoleId int64 `db:"role_id"` // 角色id
NickName string `db:"nick_name"` // 角色昵称
ServerId int `db:"server_id"` // 服务器id
Account string `db:"account"` // 账号
CreateTime int `db:"create_time"` // 创角时间
Uid uint `db:"uid"` // 用户ID
}
)
func newNhRoleModel(conn sqlx.SqlConn) *defaultNhRoleModel {
return &defaultNhRoleModel{
conn: conn,
table: "`nh_role`",
}
}
func (m *defaultNhRoleModel) 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 *defaultNhRoleModel) FindOne(ctx context.Context, id int) (*NhRole, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhRoleRows, m.table)
var resp NhRole
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 *defaultNhRoleModel) FindOneByRoleId(ctx context.Context, roleId int64) (*NhRole, error) {
var resp NhRole
query := fmt.Sprintf("select %s from %s where `role_id` = ? limit 1", nhRoleRows, m.table)
err := m.conn.QueryRowCtx(ctx, &resp, query, roleId)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultNhRoleModel) Insert(ctx context.Context, data *NhRole) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, nhRoleRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.RoleId, data.NickName, data.ServerId, data.Account, data.Uid)
return ret, err
}
func (m *defaultNhRoleModel) Update(ctx context.Context, newData *NhRole) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhRoleRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, newData.RoleId, newData.NickName, newData.ServerId, newData.Account, newData.Uid, newData.Id)
return err
}
func (m *defaultNhRoleModel) tableName() string {
return m.table
}