Files
Znc_V2/app/main/model/userModel.go

50 lines
1.3 KiB
Go
Raw Normal View History

2026-01-12 18:14:32 +08:00
package model
import (
2026-02-04 13:33:21 +08:00
"context"
"fmt"
2026-01-12 18:14:32 +08:00
"github.com/zeromicro/go-zero/core/stores/cache"
2026-02-04 13:33:21 +08:00
"github.com/zeromicro/go-zero/core/stores/sqlc"
2026-01-12 18:14:32 +08:00
"github.com/zeromicro/go-zero/core/stores/sqlx"
2026-02-04 13:33:21 +08:00
"tydata-server/common/globalkey"
2026-01-12 18:14:32 +08:00
)
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
2026-02-04 13:33:21 +08:00
// FindDisableByUserId 查用户封禁状态(不走缓存,封禁中间件用)
FindDisableByUserId(ctx context.Context, id int64) (int64, error)
2026-01-12 18:14:32 +08:00
}
customUserModel struct {
*defaultUserModel
}
)
2026-02-04 13:33:21 +08:00
// 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
}
2026-01-12 18:14:32 +08:00
// NewUserModel returns a model for the database table.
func NewUserModel(conn sqlx.SqlConn, c cache.CacheConf) UserModel {
return &customUserModel{
defaultUserModel: newUserModel(conn, c),
}
}