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

View File

@@ -3,7 +3,6 @@ package game7
import (
"context"
"errors"
"nova_task/internal/consts"
"nova_task/internal/model"
"nova_task/internal/pkg/errs"
@@ -33,29 +32,41 @@ func (l *Game7TaskCheckLogic) Game7TaskCheck(req *types.Game7TaskCheckReq) (*typ
return nil, errs.New(errs.Reason(resultErr.Error.Code), resultErr.Error.Message)
}
pb, err := l.svcCtx.PromoteBindModel.FindOneByInvitedUid(l.ctx, uid)
if err != nil {
if !errors.Is(err, model.ErrNotFound) {
return nil, errs.New(errs.ErrDatabaseOperate, err)
}
return &types.Game7ResultData{
IsValid: false,
}, nil
}
//pb, err := l.svcCtx.PromoteBindModel.FindOneByInvitedUid(l.ctx, uid)
//if err != nil {
// if !errors.Is(err, model.ErrNotFound) {
// return nil, errs.New(errs.ErrDatabaseOperate, err)
// }
// return &types.Game7ResultData{
// IsValid: false,
// }, nil
//}
shareId := l.svcCtx.ConfigModel.GetInviterId(l.ctx, consts.Game7IoInviterId)
if pb.ShareUid != shareId {
return nil, errs.New(errs.ErrUserNotFound, "user not found")
}
//shareId := l.svcCtx.ConfigModel.GetInviterId(l.ctx, consts.Game7IoInviterId)
//
//if pb.ShareUid != shareId {
// return nil, errs.New(errs.ErrUserNotFound, "user not found")
//}
var isValid bool
// 1.是否在官网注册并链接钱包(是/否) 2.是否有超过两个以上的英雄(是/否) 3.是否消耗召唤券召唤了新英雄(是/否) 4. 是否在游戏内绑定了官网账号(是/否) 5. 是否有一个31级以上的英雄是/否) 6. 是否完成了主线第一章(是/否)
switch req.Type {
case 1:
isValid = pb.IsBindWallet == 1
address, err := l.svcCtx.WalletModel.FindAddressByUid(l.ctx, uid)
if err != nil {
if !errors.Is(err, model.ErrNotFound) {
return nil, errs.New(errs.ErrDatabaseOperate, err)
}
isValid = false
} else {
isValid = address != ""
}
case 4:
isValid = pb.IsCreateRole == 1
var err error
isValid, err = l.svcCtx.RoleModel.AccountExist(l.ctx, req.Email)
if err != nil {
return nil, errs.New(errs.ErrDatabaseOperate, err)
}
case 2, 3, 5, 6:
gp, err := l.svcCtx.GameReportModel.FindOneByUid(l.ctx, uid)
if err != nil {

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
}

View File

@@ -44,6 +44,7 @@ type ServiceContext struct {
EmailRewardModel model.NhEmailRewardModel
AmbassadorModel model.NhTaskAmbassadorModel
GameReportModel model.NhGameReportModel
RoleModel model.NhRoleModel
ApiKeyCheck rest.Middleware
AdminSecretCheck rest.Middleware
@@ -82,6 +83,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
EmailRewardModel: model.NewNhEmailRewardModel(dbConn),
AmbassadorModel: model.NewNhTaskAmbassadorModel(dbConn),
GameReportModel: model.NewNhGameReportModel(dbConn),
RoleModel: model.NewNhRoleModel(dbConn),
ApiKeyCheck: middleware.NewApiKeyCheckMiddleware(configModel).Handle,
AdminSecretCheck: middleware.NewAdminSecretCheckMiddleware(configModel).Handle,