user.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package eta_trial
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/eta_trial"
  7. etaTrialService "eta/eta_api/services/eta_trial"
  8. "eta/eta_api/utils"
  9. )
  10. // EtaTrialController ETA试用
  11. type EtaTrialController struct {
  12. controllers.BaseAuthController
  13. }
  14. // UpdateActiveTime
  15. // @Title 累计活跃时长
  16. // @Description 累计活跃时长
  17. // @Param ActiveTime query int true "活跃时长"
  18. // @Param Part query string true "活跃板块"
  19. // @Success 200 {object} models.ETATrialAddReq
  20. // @router /user/active [post]
  21. func (this *EtaTrialController) UpdateActiveTime() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. if br.ErrMsg == "" {
  25. br.IsSendEmail = false
  26. }
  27. this.Data["json"] = br
  28. this.ServeJSON()
  29. }()
  30. sysUser := this.SysUser
  31. if sysUser == nil {
  32. br.Msg = "请登录"
  33. br.ErrMsg = "请登录,SysUser Is Empty"
  34. br.Ret = 408
  35. return
  36. }
  37. // 仅试用平台用
  38. if utils.BusinessCode != utils.BusinessCodeSandbox {
  39. br.Ret = 200
  40. br.Success = true
  41. br.Msg = "操作成功"
  42. return
  43. }
  44. var req eta_trial.UpdateUserActiveTimeReq
  45. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  46. if err != nil {
  47. br.Msg = "参数解析异常!"
  48. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  49. return
  50. }
  51. if req.Part == "" {
  52. br.Ret = 200
  53. br.Success = true
  54. br.Msg = "操作成功"
  55. return
  56. }
  57. params := etaTrialService.UpdateEtaTrialUserActiveTimeReq{
  58. UserName: sysUser.RealName,
  59. Mobile: sysUser.Mobile,
  60. ActiveTime: req.ActiveTime,
  61. Part: req.Part,
  62. }
  63. res, e := etaTrialService.UpdateEtaTrialUserActiveTime(params)
  64. if e != nil {
  65. br.Msg = "操作失败"
  66. br.ErrMsg = "更新ETA试用用户活跃时长失败, Err: " + e.Error()
  67. return
  68. }
  69. if !res {
  70. br.Msg = "操作失败"
  71. return
  72. }
  73. br.Ret = 200
  74. br.Success = true
  75. br.Msg = "新增成功"
  76. }
  77. // UpdateLoginDuration
  78. // @Title 更新用户登录时长
  79. // @Description 更新用户登录时长
  80. // @Param ActiveTime query int true "活跃时长"
  81. // @Success 200 {object} models.ETATrialAddReq
  82. // @router /user/login_duration [post]
  83. func (this *EtaTrialController) UpdateLoginDuration() {
  84. br := new(models.BaseResponse).Init()
  85. defer func() {
  86. if br.ErrMsg == "" {
  87. br.IsSendEmail = false
  88. }
  89. this.Data["json"] = br
  90. this.ServeJSON()
  91. }()
  92. sysUser := this.SysUser
  93. if sysUser == nil {
  94. br.Msg = "请登录"
  95. br.ErrMsg = "请登录,SysUser Is Empty"
  96. br.Ret = 408
  97. return
  98. }
  99. // 仅试用平台用
  100. if utils.BusinessCode != utils.BusinessCodeSandbox {
  101. br.Ret = 200
  102. br.Success = true
  103. br.Msg = "操作成功"
  104. return
  105. }
  106. var req eta_trial.UpdateUserLoginDurationReq
  107. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  108. if err != nil {
  109. br.Msg = "参数解析异常!"
  110. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  111. return
  112. }
  113. params := etaTrialService.UpdateEtaTrialUserLoginDurationReq{
  114. UserName: sysUser.RealName,
  115. Mobile: sysUser.Mobile,
  116. ActiveTime: req.ActiveTime,
  117. }
  118. res, e := etaTrialService.UpdateEtaTrialUserLoginDuration(params)
  119. if e != nil {
  120. br.Msg = "操作失败"
  121. br.ErrMsg = "更新ETA试用用户登录时长失败, Err: " + e.Error()
  122. return
  123. }
  124. if !res {
  125. br.Msg = "操作失败"
  126. return
  127. }
  128. br.Ret = 200
  129. br.Success = true
  130. br.Msg = "新增成功"
  131. }