package controllers import ( "eta/eta_forum_admin/models" "eta/eta_forum_admin/models/system" "strconv" ) type SysMenuController struct { BaseAuthController } // @Title 获取用户权限菜单 // @Description 获取用户权限菜单接口 // @Success 200 {object} system.MenuListResp // @router /menu/list [get] func (this *SysRoleController) SysMenuList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" return } roleId := sysUser.RoleId //roleId=1 if roleId <= 0 { br.Msg = "参数错误" return } roleIds := strconv.Itoa(roleId) //查询账号绑定的其他角色 otherRoles, err := system.GetRoleIdsByAdminId(sysUser.AdminId) if err != nil { br.Msg = "获取其他角色失败" br.ErrMsg = "获取其他角色失败,Err:" + err.Error() return } if len(otherRoles) > 0 { for _, v := range otherRoles { roleIds += "," + strconv.Itoa(v.RoleId) } } list, err := system.GetMenuListByRoleIds(roleIds) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } lenList := len(list) for i := 0; i < lenList; i++ { item := list[i] child, err := system.GetMenuByParentIdRoleIds(roleIds, item.MenuId) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取子菜单数据失败,Err:" + err.Error() return } list[i].Children = child } resp := new(system.MenuListResp) resp.List = list br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp }