go-wxhelper/service/role/select.go

32 lines
856 B
Go
Raw Normal View History

2024-01-19 12:06:30 +08:00
package role
import (
"slices"
"wechat-robot/internal/database"
)
// CheckIsSuperAdminUser
// @description: 检查是否是超级管理员用户
// @param userId string 用户Id
// @return flag bool 是否是超级管理员用户
func CheckIsSuperAdminUser(userId string) (flag bool) {
// 获取用户角色代码
codes := GetCodesByUserId(userId)
return slices.Contains(codes, "admin")
}
// GetCodesByUserId
// @description: 根据用户Id获取用户的角色代码
// @param userId string 用户Id
// @return codes []string 角色代码
func GetCodesByUserId(userId string) (codes []string) {
2024-01-19 12:06:30 +08:00
// 获取用户角色代码
database.Client.Table("t_role AS tr").
Joins("LEFT JOIN t_admin_user_role AS tur ON tur.role_id = tr.id").
Select("tr.code").
Where("tur.user_id = ?", userId).
Where("tr.is_del IS FALSE").
Take(&codes)
return
2024-01-19 12:06:30 +08:00
}