system_api_controller.go 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package admin_api_controllers
  2. import (
  3. "XT_Admin_Api/enums"
  4. "XT_Admin_Api/models/admin_models"
  5. "XT_Admin_Api/service"
  6. "time"
  7. )
  8. type SystemApiController struct {
  9. AdminBaseAPIAuthController
  10. }
  11. // func (this *SystemApiController) GetOrgs() {
  12. // list, _ := service.GetAllAdmin()
  13. // this.ServeSuccessJSON(map[string]interface{}{
  14. // "list": list,
  15. // })
  16. //
  17. // }
  18. func (this *SystemApiController) GetAdminUserInfo() {
  19. id, _ := this.GetInt64("id")
  20. admin, _ := service.FindAdminById(id)
  21. this.ServeSuccessJSON(map[string]interface{}{
  22. "admin": admin,
  23. })
  24. }
  25. func (this *SystemApiController) GetUserList() {
  26. list, _ := service.GetAllAdmin()
  27. this.ServeSuccessJSON(map[string]interface{}{
  28. "list": list,
  29. })
  30. }
  31. func (this *SystemApiController) CreateAdminUser() {
  32. name := this.GetString("name")
  33. mobile := this.GetString("mobile")
  34. password := this.GetString("user_password")
  35. role_type, _ := this.GetInt64("type")
  36. remark := this.GetString("remark")
  37. admin := &admin_models.AdminAccount{
  38. Mobile: mobile,
  39. Password: password,
  40. RoleType: role_type,
  41. Name: name,
  42. Status: 1,
  43. Remark: remark,
  44. IsAdmin: 2,
  45. Ctime: time.Now().Unix(),
  46. Mtime: time.Now().Unix(),
  47. }
  48. admins, _ := service.FindUserInfoByAccount(mobile)
  49. if admins.ID > 0 {
  50. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNameException)
  51. return
  52. }
  53. err := service.CreateAdmin(admin)
  54. if err == nil {
  55. this.ServeSuccessJSON(map[string]interface{}{
  56. "admin": admin,
  57. })
  58. }
  59. }
  60. func (this *SystemApiController) ModifyAdminUser() {
  61. id, _ := this.GetInt64("id")
  62. name := this.GetString("name")
  63. mobile := this.GetString("mobile")
  64. password := this.GetString("user_password")
  65. role_type, _ := this.GetInt64("type")
  66. remark := this.GetString("remark")
  67. admins, _ := service.FindAdminById(id)
  68. admin := &admin_models.AdminAccount{
  69. ID: admins.ID,
  70. Mobile: mobile,
  71. Password: password,
  72. Name: name,
  73. Status: 1,
  74. RoleType: role_type,
  75. IsAdmin: 2,
  76. Ctime: admins.Ctime,
  77. Remark: remark,
  78. Mtime: time.Now().Unix(),
  79. }
  80. if admins.Mobile != mobile {
  81. info, _ := service.FindUserInfoByAccount(mobile)
  82. if info.ID > 0 {
  83. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNameException)
  84. return
  85. }
  86. }
  87. err := service.UpdateAdmin(admin)
  88. if err == nil {
  89. this.ServeSuccessJSON(map[string]interface{}{
  90. "admin": admin,
  91. })
  92. }
  93. }
  94. func (this *SystemApiController) DeleteAdminUser() {
  95. id, _ := this.GetInt64("id")
  96. item_type, _ := this.GetInt64("type") //1.删除,2恢复
  97. if item_type == 1 {
  98. err := service.DeleteAdmin(id)
  99. if err == nil {
  100. this.ServeSuccessJSON(map[string]interface{}{
  101. "msg": "删除成功",
  102. })
  103. }
  104. } else {
  105. err := service.UpdateAdminTwo(id)
  106. if err == nil {
  107. this.ServeSuccessJSON(map[string]interface{}{
  108. "msg": "恢复成功",
  109. })
  110. }
  111. }
  112. }
  113. func (this *SystemApiController) GetAdminUserById() {
  114. id, _ := this.GetInt64("id")
  115. account, err := service.FindAdminById(id)
  116. if err == nil {
  117. this.ServeSuccessJSON(map[string]interface{}{
  118. "account": account,
  119. })
  120. }
  121. }