user.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. package eta_trial
  2. import (
  3. "eta/eta_bridge/controller/resp"
  4. "eta/eta_bridge/global"
  5. "eta/eta_bridge/models/crm"
  6. etaTrialReq "eta/eta_bridge/models/request/eta_trial"
  7. "eta/eta_bridge/utils"
  8. "github.com/gin-gonic/gin"
  9. "github.com/go-playground/validator/v10"
  10. "time"
  11. )
  12. type EtaTrialController struct{}
  13. // GetUserByMobile
  14. // @Description 手机号获取用户信息
  15. // @Success 200 {string} string "操作成功"
  16. // @Router /eta_trial/user/mobile_fetch [post]
  17. func (a *EtaTrialController) GetUserByMobile(c *gin.Context) {
  18. var req etaTrialReq.GetUserReq
  19. err := c.Bind(&req)
  20. if err != nil {
  21. errs, ok := err.(validator.ValidationErrors)
  22. if !ok {
  23. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  24. return
  25. }
  26. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  27. return
  28. }
  29. if req.Mobile == "" {
  30. resp.FailData("参数有误", "参数有误: Mobile", c)
  31. return
  32. }
  33. item, e := crm.GetEtaTrialByMobile(req.Mobile)
  34. if e != nil && e != utils.ErrNoRow {
  35. resp.FailData("操作失败", "获取试用客户信息失败, Err:"+e.Error(), c)
  36. return
  37. }
  38. resp.OkData("操作成功", item, c)
  39. }
  40. // Disable
  41. // @Description 禁用
  42. // @Success 200 {string} string "操作成功"
  43. // @Router /eta_trial/user/disable [post]
  44. func (a *EtaTrialController) Disable(c *gin.Context) {
  45. var req etaTrialReq.GetUserReq
  46. err := c.Bind(&req)
  47. if err != nil {
  48. errs, ok := err.(validator.ValidationErrors)
  49. if !ok {
  50. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  51. return
  52. }
  53. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  54. return
  55. }
  56. if req.Mobile == "" {
  57. resp.FailData("参数有误", "参数有误: Mobile", c)
  58. return
  59. }
  60. if e := crm.DisableEtaTrailByMobile(req.Mobile); e != nil {
  61. resp.FailData("操作失败", "禁用试用客户失败, Err:"+e.Error(), c)
  62. return
  63. }
  64. resp.OkData("操作成功", true, c)
  65. }
  66. // Edit
  67. // @Description 编辑
  68. // @Success 200 {string} string "操作成功"
  69. // @Router /eta_trial/user/edit [post]
  70. func (a *EtaTrialController) Edit(c *gin.Context) {
  71. var req etaTrialReq.UserEditReq
  72. err := c.Bind(&req)
  73. if err != nil {
  74. errs, ok := err.(validator.ValidationErrors)
  75. if !ok {
  76. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  77. return
  78. }
  79. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  80. return
  81. }
  82. if e := crm.UpdateEtaTrialPositionByMobile(req.RealName, req.Position, req.Mobile, req.Enabled); e != nil {
  83. resp.FailData("操作失败", "更新试用客户失败, Err:"+e.Error(), c)
  84. return
  85. }
  86. resp.OkData("操作成功", true, c)
  87. }
  88. // Remove
  89. // @Description 删除用户
  90. // @Success 200 {string} string "操作成功"
  91. // @Router /eta_trial/user/remove [post]
  92. func (a *EtaTrialController) Remove(c *gin.Context) {
  93. var req etaTrialReq.GetUserReq
  94. err := c.Bind(&req)
  95. if err != nil {
  96. errs, ok := err.(validator.ValidationErrors)
  97. if !ok {
  98. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  99. return
  100. }
  101. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  102. return
  103. }
  104. if req.Mobile == "" {
  105. resp.FailData("参数有误", "参数有误: Mobile", c)
  106. return
  107. }
  108. if e := crm.DeleteEtaTrialByMobile(req.Mobile); e != nil {
  109. resp.FailData("操作失败", "删除试用客户失败, Err:"+e.Error(), c)
  110. return
  111. }
  112. resp.OkData("操作成功", true, c)
  113. }
  114. // UpdateLogin
  115. // @Description 更新登录时间和次数
  116. // @Success 200 {string} string "操作成功"
  117. // @Router /eta_trial/user/update_login [post]
  118. func (a *EtaTrialController) UpdateLogin(c *gin.Context) {
  119. var req etaTrialReq.UpdateUserLoginReq
  120. err := c.Bind(&req)
  121. if err != nil {
  122. errs, ok := err.(validator.ValidationErrors)
  123. if !ok {
  124. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  125. return
  126. }
  127. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  128. return
  129. }
  130. if req.Mobile == "" {
  131. resp.FailData("参数有误", "参数有误: Mobile", c)
  132. return
  133. }
  134. if e := crm.UpdateEtaTrialLoginByMobile(req.Mobile); e != nil {
  135. resp.FailData("操作失败", "更新试用客户登录时间和次数失败, Err:"+e.Error(), c)
  136. return
  137. }
  138. resp.OkData("操作成功", true, c)
  139. }
  140. // UpdateIndexNum
  141. // @Description 更新累计新增指标数
  142. // @Success 200 {string} string "操作成功"
  143. // @Router /eta_trial/user/update_index_num [post]
  144. func (a *EtaTrialController) UpdateIndexNum(c *gin.Context) {
  145. var req etaTrialReq.UpdateUserIndexNumReq
  146. err := c.Bind(&req)
  147. if err != nil {
  148. errs, ok := err.(validator.ValidationErrors)
  149. if !ok {
  150. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  151. return
  152. }
  153. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  154. return
  155. }
  156. if req.Mobile == "" {
  157. resp.FailData("参数有误", "参数有误: Mobile", c)
  158. return
  159. }
  160. if e := crm.UpdateEtaTrialIndexNumByMobile(req.Mobile); e != nil {
  161. resp.FailData("操作失败", "更新试用客户累计新增指标数失败, Err:"+e.Error(), c)
  162. return
  163. }
  164. resp.OkData("操作成功", true, c)
  165. }
  166. // UpdateChartNum
  167. // @Description 更新累计新增图表数
  168. // @Success 200 {string} string "操作成功"
  169. // @Router /eta_trial/user/update_chart_num [post]
  170. func (a *EtaTrialController) UpdateChartNum(c *gin.Context) {
  171. var req etaTrialReq.UpdateUserIndexNumReq
  172. err := c.Bind(&req)
  173. if err != nil {
  174. errs, ok := err.(validator.ValidationErrors)
  175. if !ok {
  176. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  177. return
  178. }
  179. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  180. return
  181. }
  182. if req.Mobile == "" {
  183. resp.FailData("参数有误", "参数有误: Mobile", c)
  184. return
  185. }
  186. if e := crm.UpdateEtaTrialChartNumByMobile(req.Mobile); e != nil {
  187. resp.FailData("操作失败", "更新试用客户累计新增图表数失败, Err:"+e.Error(), c)
  188. return
  189. }
  190. resp.OkData("操作成功", true, c)
  191. }
  192. // UpdateActiveTime
  193. // @Description 更新活跃时间
  194. // @Success 200 {string} string "操作成功"
  195. // @Router /eta_trial/user/update_active_time [post]
  196. func (a *EtaTrialController) UpdateActiveTime(c *gin.Context) {
  197. var req etaTrialReq.UpdateUserActiveTimeReq
  198. err := c.Bind(&req)
  199. if err != nil {
  200. errs, ok := err.(validator.ValidationErrors)
  201. if !ok {
  202. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  203. return
  204. }
  205. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  206. return
  207. }
  208. record := new(crm.EtaTrialActiveRecord)
  209. record.UserName = req.UserName
  210. record.Mobile = req.Mobile
  211. record.ActiveTime = req.ActiveTime
  212. record.Part = req.Part
  213. record.CreateTime = time.Now().Local()
  214. if e := record.Create(); e != nil {
  215. resp.FailData("操作失败", "新增试用客户活跃记录失败, Err:"+e.Error(), c)
  216. return
  217. }
  218. if e := crm.UpdateEtaTrailActiveTime(req.ActiveTime, req.Mobile); e != nil {
  219. resp.FailData("操作失败", "更新试用客户累计活跃时长失败, Err:"+e.Error(), c)
  220. return
  221. }
  222. resp.OkData("操作成功", true, c)
  223. }
  224. // UpdateLoginDuration
  225. // @Description 更新登录时长
  226. // @Success 200 {string} string "操作成功"
  227. // @Router /eta_trial/user/update_login_duration [post]
  228. func (a *EtaTrialController) UpdateLoginDuration(c *gin.Context) {
  229. var req etaTrialReq.UpdateUserLoginDurationReq
  230. err := c.Bind(&req)
  231. if err != nil {
  232. errs, ok := err.(validator.ValidationErrors)
  233. if !ok {
  234. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  235. return
  236. }
  237. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  238. return
  239. }
  240. record := new(crm.EtaTrialLoginDurationRecord)
  241. record.UserName = req.UserName
  242. record.Mobile = req.Mobile
  243. record.Duration = req.ActiveTime
  244. record.CreateTime = time.Now().Local()
  245. if e := record.Create(); e != nil {
  246. resp.FailData("操作失败", "新增试用客户登录时长记录失败, Err:"+e.Error(), c)
  247. return
  248. }
  249. if e := crm.UpdateEtaTrailLastLoginDuration(req.ActiveTime, req.Mobile); e != nil {
  250. resp.FailData("操作失败", "更新试用客户登录时长失败, Err:"+e.Error(), c)
  251. return
  252. }
  253. resp.OkData("操作成功", true, c)
  254. }