system_api_controller.go 3.0KB

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