1 Star 1 Fork 1

xiaoyutab / xgotool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
get_user_parent.go 651 Bytes
一键复制 编辑 原始数据 按行查看 历史
xiaoyutab 提交于 2024-01-17 15:14 . 代码优化
package xauth
// 获取我的上级用户
//
// uid 用户ID
// typ 授权来源ID
func GetUserParent(uid, typ uint) uint {
if uid == 0 || uid == 1 {
return 0
}
_cache.Lock()
defer _cache.Unlock()
if v, ok := _cache.UserParent[key(uid, typ)]; ok {
return v
}
var mod uint
if _default.DB == nil {
return 0
}
// 从数据库中读取上级ID
err := _default.DB.Table(_default.UserChildName).
Where("user_id", uid).
Where("type", typ).
Order("id ASC").
Limit(1).
Select("superior_id").
Find(&mod).
Error
if err != nil {
errFun("用户上级ID获取失败", err)
}
_cache.UserParent[key(uid, typ)] = mod
return mod
}
Go
1
https://gitee.com/xiaoyutab/xgotool.git
git@gitee.com:xiaoyutab/xgotool.git
xiaoyutab
xgotool
xgotool
v0.3.9

搜索帮助