分销商城(微商城)接口项目

base_api_controller.go 3.8KB

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