package model import ( "context" "fmt" "github.com/zeromicro/go-zero/core/stores/sqlx" "time" ) var _ NhGamePitModel = (*customNhGamePitModel)(nil) type ( // NhGamePitModel is an interface to be customized, add more methods here, // and implement the added methods in customNhGamePitModel. NhGamePitModel interface { nhGamePitModel withSession(session sqlx.Session) NhGamePitModel UserExist(ctx context.Context, uid uint) bool } customNhGamePitModel struct { *defaultNhGamePitModel } ) func (m *customNhGamePitModel) UserExist(ctx context.Context, uid uint) bool { query := fmt.Sprintf("SELECT `id` FROM %s WHERE `uid` = ? AND `created_at` > ? LIMIT 1", m.table) var id int t := time.Now().Add(-time.Hour * 24) err := m.conn.QueryRowCtx(ctx, &id, query, uid, t) if err != nil { return false } return id > 0 } // NewNhGamePitModel returns a model for the database table. func NewNhGamePitModel(conn sqlx.SqlConn) NhGamePitModel { return &customNhGamePitModel{ defaultNhGamePitModel: newNhGamePitModel(conn), } } func (m *customNhGamePitModel) withSession(session sqlx.Session) NhGamePitModel { return NewNhGamePitModel(sqlx.NewSqlConnFromSession(session)) }