34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
|
package model
|
||
|
|
||
|
type SystemUserRole struct {
|
||
|
UserRoleId int64 `xorm:"not null pk autoincr INT(11)" json:"userRoleId"` //用户编号
|
||
|
UserId int64 `xorm:"INT(11)" json:"userId"` //用户ID
|
||
|
RoleId int64 `xorm:"INT(11)" json:"roleId"` //角色ID
|
||
|
Status int `xorm:"SMALLINT default 0" json:"status"` //状态 0禁用 1启用
|
||
|
CreateAt int64 `xorm:"created" json:"createAt"` //创建时间
|
||
|
UpdateAt int64 `xorm:"updated" json:"updateAt"` //更新时间
|
||
|
}
|
||
|
|
||
|
func GetRolesByUserId(userId int64) []SystemRole {
|
||
|
us := new(SystemUser)
|
||
|
h, err := DB.ID(userId).Get(us)
|
||
|
if err != nil || !h {
|
||
|
return nil
|
||
|
}
|
||
|
roleList := make([]SystemUserRole, 0)
|
||
|
err = DB.Where("user_id = ? and status = 1", us.UserId).Find(&roleList)
|
||
|
if err != nil {
|
||
|
return nil
|
||
|
}
|
||
|
roleIdList := make([]int64, len(roleList))
|
||
|
for k, v := range roleList {
|
||
|
roleIdList[k] = v.RoleId
|
||
|
}
|
||
|
list := make([]SystemRole, 0)
|
||
|
err = DB.In("role_id", roleIdList).Find(&list)
|
||
|
if err != nil {
|
||
|
return nil
|
||
|
}
|
||
|
return list
|
||
|
}
|