admin.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package controllers
  2. import (
  3. "eta/eta_forum_admin/models"
  4. "eta/eta_forum_admin/models/system"
  5. "strconv"
  6. )
  7. type AdminController struct {
  8. BaseAuthController
  9. }
  10. // GetBusinessAdmin
  11. // @Title 获取机构用户
  12. // @Description 获取机构用户
  13. // @Success 200 {object} models.ChartInfoDetailResp
  14. // @router /business/admin [get]
  15. func (this *AdminController) GetBusinessAdmin() {
  16. br := new(models.BaseResponse).Init()
  17. defer func() {
  18. this.Data["json"] = br
  19. this.ServeJSON()
  20. }()
  21. sysUser := this.SysUser
  22. if sysUser == nil {
  23. br.Msg = "请登录"
  24. br.ErrMsg = "请登录,SysUser Is Empty"
  25. br.Ret = 408
  26. return
  27. }
  28. // 查询所有机构
  29. ob := new(system.EtaBusiness)
  30. companyList, err := ob.GetItemsByCondition("", make([]interface{}, 0), []string{}, "")
  31. if err != nil {
  32. br.Msg = "获取机构信息失败"
  33. br.ErrMsg = err.Error()
  34. return
  35. }
  36. list := make([]*system.BusinessAdmin, 0)
  37. //查询机构下的用户
  38. admin := new(system.Admin)
  39. adminList, err := admin.GetItemsByCondition("", make([]interface{}, 0), []string{}, "")
  40. if err != nil {
  41. br.Msg = "获取机构用户失败"
  42. br.ErrMsg = err.Error()
  43. return
  44. }
  45. companyMap := make(map[string][]*system.BusinessAdmin)
  46. if len(adminList) > 0 {
  47. for _, v := range adminList {
  48. tmp := &system.BusinessAdmin{
  49. AdminId: strconv.Itoa(v.AdminId),
  50. RealName: v.RealName,
  51. }
  52. companyMap[v.BusinessCode] = append(companyMap[v.BusinessCode], tmp)
  53. }
  54. }
  55. if len(companyList) > 0 {
  56. for _, v := range companyList {
  57. tmp := &system.BusinessAdmin{
  58. AdminId: v.BusinessCode,
  59. RealName: v.BusinessName,
  60. }
  61. l, ok := companyMap[v.BusinessCode]
  62. if ok {
  63. tmp.ChildrenList = l
  64. list = append(list, tmp)
  65. }
  66. }
  67. }
  68. var resp system.BusinessAdminResp
  69. resp.List = list
  70. br.Ret = 200
  71. br.Success = true
  72. br.Msg = "获取成功"
  73. br.Data = resp
  74. }