fix: Game上报数据通过角色id匹配
This commit is contained in:
@@ -18,18 +18,18 @@ Log:
|
||||
Auth: # js-sdk鉴权相关配置
|
||||
AccessSecret: "Mj2G%szYe&$MP@ytNv8JktQN1n5^cPq%" # 鉴权token密钥
|
||||
|
||||
#MySql: # mysql相关配置
|
||||
# Addr: "192.168.20.101:3306" # mysql地址
|
||||
# User: "huangjie" # mysql用户
|
||||
# Password: "jMDqPQM^a6hsAR" # mysql密码
|
||||
# Database: "nova_home" # 数据库名
|
||||
|
||||
MySql: # mysql相关配置
|
||||
Addr: "127.0.0.1:3306" # mysql地址
|
||||
User: "root" # mysql用户
|
||||
Password: "123456" # mysql密码
|
||||
Addr: "192.168.20.101:3306" # mysql地址
|
||||
User: "huangjie" # mysql用户
|
||||
Password: "jMDqPQM^a6hsAR" # mysql密码
|
||||
Database: "nova_home" # 数据库名
|
||||
|
||||
#MySql: # mysql相关配置
|
||||
# Addr: "127.0.0.1:3306" # mysql地址
|
||||
# User: "root" # mysql用户
|
||||
# Password: "123456" # mysql密码
|
||||
# Database: "nova_home" # 数据库名
|
||||
|
||||
Redis:
|
||||
Host: "127.0.0.1:6379"
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ func (l *UnlockChapterLogic) UnlockChapter(req *types.UnlockChapterReq) *types.C
|
||||
pb, err := l.svcCtx.PromoteBindModel.FindOneByInvitedUid(l.ctx, uid)
|
||||
if err != nil {
|
||||
if !errors.Is(err, model.ErrNotFound) {
|
||||
l.Errorw("find promote bind error", logx.Field("err", err), logx.Field("email", req.Email))
|
||||
return &types.CarvResult{
|
||||
Error: &types.Error{
|
||||
Code: int(errs.ErrDatabaseOperate),
|
||||
@@ -50,16 +51,15 @@ func (l *UnlockChapterLogic) UnlockChapter(req *types.UnlockChapterReq) *types.C
|
||||
}
|
||||
|
||||
shareId := l.svcCtx.ConfigModel.GetInviterId(l.ctx, consts.CarvIoInviterId)
|
||||
|
||||
if pb.ShareUid != shareId {
|
||||
return &types.CarvResult{
|
||||
Result: &types.Result{IsValid: false},
|
||||
}
|
||||
}
|
||||
|
||||
gp, err := l.svcCtx.GameReportModel.FindOneByUid(l.ctx, uid)
|
||||
gp, err := l.svcCtx.GameReportModel.FindMaxByEmail(l.ctx, req.Email)
|
||||
if err != nil {
|
||||
if !errors.Is(err, model.ErrNotFound) {
|
||||
l.Errorw("find game report error", logx.Field("err", err), logx.Field("email", req.Email))
|
||||
return &types.CarvResult{
|
||||
Error: &types.Error{
|
||||
Code: int(errs.ErrDatabaseOperate),
|
||||
@@ -67,8 +67,7 @@ func (l *UnlockChapterLogic) UnlockChapter(req *types.UnlockChapterReq) *types.C
|
||||
},
|
||||
}
|
||||
}
|
||||
return &types.CarvResult{Result: &types.Result{IsValid: false}}
|
||||
}
|
||||
|
||||
if gp.Chapter >= req.Chapter {
|
||||
return &types.CarvResult{Result: &types.Result{IsValid: true}}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ func (l *Game7TaskCheckLogic) Game7TaskCheck(req *types.Game7TaskCheckReq) (*typ
|
||||
return nil, errs.New(errs.ErrDatabaseOperate, err)
|
||||
}
|
||||
case 2, 3, 5, 6:
|
||||
gp, err := l.svcCtx.GameReportModel.FindOneByUid(l.ctx, uid)
|
||||
gp, err := l.svcCtx.GameReportModel.FindMaxByEmail(l.ctx, req.Email)
|
||||
if err != nil {
|
||||
if !errors.Is(err, model.ErrNotFound) {
|
||||
return nil, errs.New(errs.ErrDatabaseOperate, err)
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package model
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ NhGameReportModel = (*customNhGameReportModel)(nil)
|
||||
|
||||
@@ -10,6 +14,15 @@ type (
|
||||
NhGameReportModel interface {
|
||||
nhGameReportModel
|
||||
withSession(session sqlx.Session) NhGameReportModel
|
||||
FindMaxByEmail(ctx context.Context, email string) (*GameReport, error)
|
||||
}
|
||||
|
||||
GameReport struct {
|
||||
Account string `db:"account"` // 账号
|
||||
IsHaveTwoHero int8 `db:"is_have_two_hero"` // 是否拥有两个以上的英雄,1=是
|
||||
IsUsedSummon int8 `db:"is_used_summon"` // 是否已使用了召唤,1=是
|
||||
IsHaveHero31 int `db:"is_have_hero_31"` // 是否拥有31级以上的英雄,1=是
|
||||
Chapter int `db:"chapter"` // 完成的章节
|
||||
}
|
||||
|
||||
customNhGameReportModel struct {
|
||||
@@ -17,6 +30,30 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (m *customNhGameReportModel) FindMaxByEmail(ctx context.Context, email string) (*GameReport, error) {
|
||||
query := `SELECT
|
||||
r.account,
|
||||
MAX(g.is_have_two_hero) AS is_have_two_hero,
|
||||
MAX(g.is_used_summon) AS is_used_summon,
|
||||
MAX(g.is_have_hero_31) AS is_have_hero_31,
|
||||
MAX(g.chapter) AS chapter
|
||||
FROM
|
||||
nh_game_report g
|
||||
JOIN
|
||||
nh_role r ON g.role_id = r.role_id
|
||||
WHERE
|
||||
r.account = ?
|
||||
GROUP BY
|
||||
r.account;
|
||||
`
|
||||
var resp GameReport
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, email)
|
||||
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
// NewNhGameReportModel returns a model for the database table.
|
||||
func NewNhGameReportModel(conn sqlx.SqlConn) NhGameReportModel {
|
||||
return &customNhGameReportModel{
|
||||
|
||||
@@ -27,7 +27,7 @@ type (
|
||||
nhGameReportModel interface {
|
||||
Insert(ctx context.Context, data *NhGameReport) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id uint) (*NhGameReport, error)
|
||||
FindOneByUid(ctx context.Context, uid uint) (*NhGameReport, error)
|
||||
FindOneByRoleId(ctx context.Context, roleId uint64) (*NhGameReport, error)
|
||||
Update(ctx context.Context, data *NhGameReport) error
|
||||
Delete(ctx context.Context, id uint) error
|
||||
}
|
||||
@@ -40,6 +40,7 @@ type (
|
||||
NhGameReport struct {
|
||||
Id uint `db:"id"`
|
||||
Uid uint `db:"uid"` // 用户ID
|
||||
RoleId uint64 `db:"role_id"` // 角色id
|
||||
IsHaveTwoHero int8 `db:"is_have_two_hero"` // 是否拥有两个以上的英雄,1=是
|
||||
IsUsedSummon int8 `db:"is_used_summon"` // 是否已使用了召唤,1=是
|
||||
IsHaveHero31 int `db:"is_have_hero_31"` // 是否拥有31级以上的英雄,1=是
|
||||
@@ -76,10 +77,10 @@ func (m *defaultNhGameReportModel) FindOne(ctx context.Context, id uint) (*NhGam
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultNhGameReportModel) FindOneByUid(ctx context.Context, uid uint) (*NhGameReport, error) {
|
||||
func (m *defaultNhGameReportModel) FindOneByRoleId(ctx context.Context, roleId uint64) (*NhGameReport, error) {
|
||||
var resp NhGameReport
|
||||
query := fmt.Sprintf("select %s from %s where `uid` = ? limit 1", nhGameReportRows, m.table)
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, uid)
|
||||
query := fmt.Sprintf("select %s from %s where `role_id` = ? limit 1", nhGameReportRows, m.table)
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, roleId)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
@@ -91,14 +92,14 @@ func (m *defaultNhGameReportModel) FindOneByUid(ctx context.Context, uid uint) (
|
||||
}
|
||||
|
||||
func (m *defaultNhGameReportModel) Insert(ctx context.Context, data *NhGameReport) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, nhGameReportRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Uid, data.IsHaveTwoHero, data.IsUsedSummon, data.IsHaveHero31, data.Chapter)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?)", m.table, nhGameReportRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Uid, data.RoleId, data.IsHaveTwoHero, data.IsUsedSummon, data.IsHaveHero31, data.Chapter)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultNhGameReportModel) Update(ctx context.Context, newData *NhGameReport) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhGameReportRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, newData.Uid, newData.IsHaveTwoHero, newData.IsUsedSummon, newData.IsHaveHero31, newData.Chapter, newData.Id)
|
||||
_, err := m.conn.ExecCtx(ctx, query, newData.Uid, newData.RoleId, newData.IsHaveTwoHero, newData.IsUsedSummon, newData.IsHaveHero31, newData.Chapter, newData.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user