71 lines
2.0 KiB
Go
Executable File
71 lines
2.0 KiB
Go
Executable File
package model
|
||
|
||
import (
|
||
"context"
|
||
"errors"
|
||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||
)
|
||
|
||
var _ NhGameReportModel = (*customNhGameReportModel)(nil)
|
||
|
||
type (
|
||
// NhGameReportModel is an interface to be customized, add more methods here,
|
||
// and implement the added methods in customNhGameReportModel.
|
||
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 {
|
||
*defaultNhGameReportModel
|
||
}
|
||
)
|
||
|
||
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)
|
||
switch {
|
||
case err == nil:
|
||
return &resp, nil
|
||
case errors.Is(err, sqlx.ErrNotFound):
|
||
return nil, ErrNotFound
|
||
default:
|
||
return nil, err
|
||
}
|
||
}
|
||
|
||
// NewNhGameReportModel returns a model for the database table.
|
||
func NewNhGameReportModel(conn sqlx.SqlConn) NhGameReportModel {
|
||
return &customNhGameReportModel{
|
||
defaultNhGameReportModel: newNhGameReportModel(conn),
|
||
}
|
||
}
|
||
|
||
func (m *customNhGameReportModel) withSession(session sqlx.Session) NhGameReportModel {
|
||
return NewNhGameReportModel(sqlx.NewSqlConnFromSession(session))
|
||
}
|