admin_api_base_controller.go 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package admin_api_controllers
  2. import (
  3. "XT_Admin_Api/controllers"
  4. "XT_Admin_Api/enums"
  5. "XT_Admin_Api/models/admin_models"
  6. "XT_Admin_Api/service"
  7. "fmt"
  8. )
  9. type AdminBaseAPIController struct {
  10. controllers.BaseAPIController
  11. }
  12. func (this *AdminBaseAPIController) ErrorLog(format string, a ...interface{}) {
  13. //beego.Error(fmt.Sprintf("[管理员后台] %v", fmt.Sprintf(format, a...)))
  14. }
  15. func (this *AdminBaseAPIController) WarnLog(format string, a ...interface{}) {
  16. //beego.Warn(fmt.Sprintf("[管理员后台] %v", fmt.Sprintf(format, a...)))
  17. }
  18. func (this *AdminBaseAPIController) InfoLog(format string, a ...interface{}) {
  19. //beego.Info(fmt.Sprintf("[管理员后台] %v", fmt.Sprintf(format, a...)))
  20. }
  21. func (this *AdminBaseAPIController) DebugLog(format string, a ...interface{}) {
  22. //beego.Debug(fmt.Sprintf("[管理员后台] %v", fmt.Sprintf(format, a...)))
  23. }
  24. func (this *AdminBaseAPIController) TraceLog(format string, a ...interface{}) {
  25. //beego.Trace(fmt.Sprintf("[管理员后台] %v", fmt.Sprintf(format, a...)))
  26. }
  27. func (this *AdminBaseAPIAuthController) GetAdminInfo() *admin_models.AdminAccount {
  28. mobile := this.GetString("account")
  29. password := this.GetString("password")
  30. //adminInfo :=GetAdminInfo(mobile,password)
  31. admin, getAdminErr := service.GetAdminAccount(mobile, password)
  32. if getAdminErr != nil {
  33. this.ErrorLog("获取管理员信息失败:%v", getAdminErr)
  34. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. return nil
  36. } else if admin == nil {
  37. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
  38. //this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
  39. return nil
  40. }
  41. var ads AdminInfo
  42. ads.Admin = admin
  43. return admin
  44. }
  45. type AdminInfo struct {
  46. Admin *admin_models.AdminAccount
  47. }
  48. type AdminBaseAPIAuthController struct {
  49. AdminBaseAPIController
  50. }
  51. func (this *AdminBaseAPIAuthController) Prepare() {
  52. this.AdminBaseAPIController.Prepare()
  53. //name := this.GetString("name")
  54. adminInfo := this.GetAdminInfo()
  55. fmt.Println(adminInfo)
  56. if adminInfo == nil {
  57. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
  58. this.StopRun()
  59. }
  60. }