fix: Game上报数据通过角色id匹配
This commit is contained in:
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user