base_api_controller.go 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package controllers
  2. import (
  3. "XT_Admin_Api/enums"
  4. )
  5. type BaseAPIController struct {
  6. BaseController
  7. }
  8. // func (this *BaseAPIController) Prepare() {
  9. // this.BaseController.Prepare()
  10. // beego.Trace("============================================================")
  11. // beego.Trace("session ID: %v", this.Ctx.Input.Cookie("beegosessionID"))
  12. // beego.Trace("session : %v", this.GetSession("info"))
  13. // this.SetSession("info", time.Now().Format("2006/01/02 15:04:05"))
  14. // beego.Trace("============================================================")
  15. // }
  16. // 输出数据格式化
  17. /*
  18. success json:
  19. {
  20. "state": 1,
  21. "code": 0,
  22. "data": json,
  23. }
  24. fail json:
  25. {
  26. "state": 0,
  27. "code": int,
  28. "msg": string,
  29. }
  30. */
  31. func (this *BaseAPIController) ServeSuccessJSON(data map[string]interface{}) {
  32. this.Data["json"] = enums.MakeSuccessResponseJSON(data)
  33. this.ServeJSON()
  34. }
  35. func (this *BaseAPIController) ServeFailJSONWithSGJErrorCode(code int) {
  36. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(code)
  37. this.ServeJSON()
  38. }
  39. func (this *BaseAPIController) ServeFailJSONWithSGJError(err *enums.SGJError) {
  40. this.Data["json"] = enums.MakeFailResponseJSONWithSGJError(err)
  41. this.ServeJSON()
  42. }
  43. func (this *BaseAPIController) ServeFailJsonSend(code int, msg string) {
  44. this.Data["json"] = enums.MakeFailResponseJSON(msg, code)
  45. this.ServeJSON()
  46. }
  47. type BaseAuthAPIController struct {
  48. BaseAPIController
  49. }
  50. func (this *BaseAuthAPIController) Prepare() {
  51. this.BaseAPIController.Prepare()
  52. if this.GetAdminUserInfo() == nil {
  53. //var userAdmin models.AdminUser
  54. //userAdmin.Id = 380
  55. //userAdmin.Mobile = "13532250447"
  56. //userAdmin.IsSuperAdmin = true
  57. //userAdmin.Status = 1
  58. //userAdmin.CreateTime = 1530786071
  59. //userAdmin.ModifyTime = 1530786071
  60. //var subscibe models.ServeSubscibe
  61. //subscibe.ID = 1
  62. //subscibe.OrgId = 4
  63. //subscibe.PeriodStart = 1538035409
  64. //subscibe.PeriodEnd = 1569571409
  65. //subscibe.State = 1
  66. //subscibe.Status = 1
  67. //subscibe.CreatedTime = 1538035409
  68. //subscibe.UpdatedTime = 1538035409
  69. //subscibes := make(map[int64]*models.ServeSubscibe, 0)
  70. //subscibes[4] = &subscibe
  71. //
  72. //var template models.GobalTemplate
  73. //template.TemplateId = 2
  74. //
  75. //
  76. //var adminUserInfo service.AdminUserInfo
  77. //adminUserInfo.CurrentOrgId = 4
  78. //adminUserInfo.CurrentAppId = 5
  79. //adminUserInfo.AdminUser = &userAdmin
  80. //adminUserInfo.Subscibes = subscibes
  81. //this.SetSession("admin_user_info", &adminUserInfo)
  82. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
  83. this.StopRun()
  84. }
  85. }
  86. type BaseServeAPIController struct {
  87. BaseAPIController
  88. }
  89. func (this *BaseServeAPIController) Prepare() {
  90. this.BaseAPIController.Prepare()
  91. if this.GetAdminUserInfo() == nil {
  92. //var userAdmin models.AdminUser
  93. //userAdmin.Id = 380
  94. //userAdmin.Mobile = "13532250447"
  95. //userAdmin.IsSuperAdmin = true
  96. //userAdmin.Status = 1
  97. //userAdmin.CreateTime = 1530786071
  98. //userAdmin.ModifyTime = 1530786071
  99. //var subscibe models.ServeSubscibe
  100. //subscibe.ID = 1
  101. //subscibe.OrgId = 4
  102. //subscibe.PeriodStart = 1538035409
  103. //subscibe.PeriodEnd = 1569571409
  104. //subscibe.State = 1
  105. //subscibe.Status = 1
  106. //subscibe.CreatedTime = 1538035409
  107. //subscibe.UpdatedTime = 1538035409
  108. //subscibes := make(map[int64]*models.ServeSubscibe, 0)
  109. //subscibes[4] = &subscibe
  110. //var adminUserInfo service.AdminUserInfo
  111. //adminUserInfo.CurrentOrgId = 4
  112. //adminUserInfo.CurrentAppId = 5
  113. //adminUserInfo.AdminUser = &userAdmin
  114. //adminUserInfo.Subscibes = subscibes
  115. //this.SetSession("admin_user_info", &adminUserInfo)
  116. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
  117. this.StopRun()
  118. }
  119. }