This commit is contained in:
Mrx
2026-02-04 13:33:21 +08:00
parent e7c2ddbd93
commit e1fbf72437
23 changed files with 190 additions and 65 deletions

View File

@@ -1,8 +1,14 @@
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)
@@ -12,6 +18,8 @@ type (
// and implement the added methods in customUserModel.
UserModel interface {
userModel
// FindDisableByUserId 查用户封禁状态(不走缓存,封禁中间件用)
FindDisableByUserId(ctx context.Context, id int64) (int64, error)
}
customUserModel struct {
@@ -19,6 +27,20 @@ type (
}
)
// 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{