sys_menu_button.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package controllers
  2. import (
  3. "hongze/hz_crm_api/models"
  4. "hongze/hz_crm_api/models/system"
  5. "hongze/hz_crm_api/utils"
  6. )
  7. type SysMenuButtonController struct {
  8. BaseAuthController
  9. }
  10. // @Title 获取菜单全部按钮
  11. // @Description 获取菜单全部按钮接口
  12. // @Param RoleId query int true "角色ID"
  13. // @Success 200 {object} system.MenuButtonsResp
  14. // @router /menu/buttons [get]
  15. func (this *SysRoleController) SysMenuButtons() {
  16. br := new(models.BaseResponse).Init()
  17. defer func() {
  18. this.Data["json"] = br
  19. this.ServeJSON()
  20. }()
  21. list, err := system.GetButtonMenu()
  22. if err != nil {
  23. br.Msg = "获取失败"
  24. br.ErrMsg = "获取失败,Err:" + err.Error()
  25. return
  26. }
  27. listLen := len(list)
  28. for i := 0; i < listLen; i++ {
  29. item := list[i]
  30. menus, err := system.GetSysMenuButtonItems(item.MenuId)
  31. if err != nil {
  32. br.Msg = "获取失败"
  33. br.ErrMsg = "获取失败,Err:" + err.Error()
  34. return
  35. }
  36. list[i].List = menus
  37. }
  38. roleId, _ := this.GetInt("RoleId")
  39. checkList := make([]*int, 0)
  40. cl, err := system.GetRoleButtonCheck(roleId)
  41. if err != nil && err.Error() != utils.ErrNoRow() {
  42. br.Msg = "获取失败"
  43. br.ErrMsg = "获取失败,Err:" + err.Error()
  44. return
  45. }
  46. for _, v := range cl {
  47. checkList = append(checkList, &v.MenuButtonId)
  48. }
  49. resp := new(system.MenuButtonsResp)
  50. resp.List = list
  51. resp.CheckList = checkList
  52. br.Ret = 200
  53. br.Success = true
  54. br.Msg = "获取成功"
  55. br.Data = resp
  56. }