sys_admin.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_mobile/models"
  5. "eta/eta_mobile/models/system"
  6. "eta/eta_mobile/utils"
  7. "time"
  8. )
  9. // 系统用户
  10. type SysAdminController struct {
  11. BaseAuthController
  12. }
  13. // SetConfig
  14. // @Title 用户信息配置接口
  15. // @Description 用户信息配置接口
  16. // @Success 200 {object} system.SetAdminConfigReq
  17. // @router /sysuser/config/set [post]
  18. func (this *SysAdminController) SetConfig() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. sysUser := this.SysUser
  25. if sysUser == nil {
  26. br.Msg = "请登录"
  27. br.ErrMsg = "请登录,SysUser Is Empty"
  28. br.Ret = 408
  29. return
  30. }
  31. var req system.SetAdminConfigReq
  32. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  33. if err != nil {
  34. br.Msg = "参数解析异常!"
  35. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  36. return
  37. }
  38. item, err := system.GetConfigDetailByCode(this.SysUser.AdminId, req.ConfigCode)
  39. if err != nil {
  40. if err.Error() != utils.ErrNoRow() {
  41. br.Msg = "设置失败"
  42. br.ErrMsg = "设置失败,Err:" + err.Error()
  43. return
  44. }
  45. // 获取默认配置
  46. defaultConfig, err := system.GetDefaultConfigDetailByCode(req.ConfigCode)
  47. if err != nil {
  48. br.Msg = "设置失败"
  49. br.ErrMsg = "获取默认配置失败,Err:" + err.Error()
  50. return
  51. }
  52. adminConfigItem := &system.AdminConfig{
  53. //ConfigId: 0,
  54. AdminId: this.SysUser.AdminId,
  55. ConfigCode: req.ConfigCode,
  56. ConfigValue: req.ConfigValue,
  57. Remark: defaultConfig.Remark,
  58. CreateTime: time.Now(),
  59. }
  60. err = adminConfigItem.Create()
  61. if err != nil {
  62. br.Msg = "设置失败"
  63. br.ErrMsg = "设置失败,Err:" + err.Error()
  64. return
  65. }
  66. } else {
  67. // 存在配置,那么就修改
  68. item.ConfigValue = req.ConfigValue
  69. err = item.Update([]string{"ConfigValue"})
  70. if err != nil {
  71. br.Msg = "设置失败"
  72. br.ErrMsg = "设置失败,Err:" + err.Error()
  73. return
  74. }
  75. }
  76. br.Ret = 200
  77. br.Success = true
  78. br.Msg = "设置成功"
  79. }
  80. // ConfigLanguage
  81. // @Title 用户语言配置
  82. // @Description 用户语言配置
  83. // @Success 200 string "获取成功"
  84. // @router /config/language [get]
  85. func (this *SysAdminController) ConfigLanguage() {
  86. br := new(models.BaseResponse).Init()
  87. defer func() {
  88. if br.ErrMsg == "" {
  89. br.IsSendEmail = false
  90. }
  91. this.Data["json"] = br
  92. this.ServeJSON()
  93. }()
  94. sysUser := this.SysUser
  95. if sysUser == nil {
  96. br.Msg = "请登录"
  97. br.ErrMsg = "请登录,SysUser Is Empty"
  98. br.Ret = 408
  99. return
  100. }
  101. sourceKey := this.GetString("SourceKey")
  102. language := `CN`
  103. confDetail, _ := system.GetConfigDetailByCode(sysUser.AdminId, sourceKey)
  104. if confDetail != nil {
  105. language = confDetail.ConfigValue
  106. }
  107. br.Data = language
  108. br.Ret = 200
  109. br.Success = true
  110. br.Msg = "获取成功"
  111. }
  112. // Detail
  113. // @Title 用户详情信息
  114. // @Description 用户详情信息
  115. // @Param request body system.SysuserAddReq true "type json string"
  116. // @Success 200 新增成功
  117. // @router /sysuser/detail [get]
  118. func (this *SysAdminController) Detail() {
  119. br := new(models.BaseResponse).Init()
  120. defer func() {
  121. this.Data["json"] = br
  122. this.ServeJSON()
  123. }()
  124. br.Data = this.SysUser
  125. br.Ret = 200
  126. br.Success = true
  127. br.Msg = "获取成功"
  128. }