50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package model
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
|
|
"tydata-server/common/globalkey"
|
|
)
|
|
|
|
var _ UserModel = (*customUserModel)(nil)
|
|
|
|
type (
|
|
// UserModel is an interface to be customized, add more methods here,
|
|
// and implement the added methods in customUserModel.
|
|
UserModel interface {
|
|
userModel
|
|
// FindDisableByUserId 查用户封禁状态(不走缓存,封禁中间件用)
|
|
FindDisableByUserId(ctx context.Context, id int64) (int64, error)
|
|
}
|
|
|
|
customUserModel struct {
|
|
*defaultUserModel
|
|
}
|
|
)
|
|
|
|
// FindDisableByUserId 查用户 disable 字段,不走缓存,确保封禁后立即生效
|
|
func (m *customUserModel) FindDisableByUserId(ctx context.Context, id int64) (int64, error) {
|
|
var disable int64
|
|
query := fmt.Sprintf("SELECT `disable` FROM %s WHERE `id` = ? and del_state = ? limit 1", m.table)
|
|
err := m.QueryRowNoCacheCtx(ctx, &disable, query, id, globalkey.DelStateNo)
|
|
if err != nil {
|
|
if err == sqlc.ErrNotFound {
|
|
return 0, ErrNotFound
|
|
}
|
|
return 0, err
|
|
}
|
|
return disable, nil
|
|
}
|
|
|
|
// NewUserModel returns a model for the database table.
|
|
func NewUserModel(conn sqlx.SqlConn, c cache.CacheConf) UserModel {
|
|
return &customUserModel{
|
|
defaultUserModel: newUserModel(conn, c),
|
|
}
|
|
}
|