user_feedback.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "hongze/hz_crm_api/controllers"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/company"
  7. "hongze/hz_crm_api/models/cygx"
  8. "hongze/hz_crm_api/services"
  9. "time"
  10. )
  11. // 联系人列表,交流反馈
  12. type UserFeedbackController struct {
  13. controllers.BaseAuthController
  14. }
  15. // @Title 添加交流反馈接口
  16. // @Description 添加交流反馈接口
  17. // @Param request body cygx.AddCygxUserFeedbackReq true "type json string"
  18. // @Success 200 操作成功
  19. // @router /user_feedback/add [post]
  20. func (this *UserFeedbackController) UserFeedbackAdd() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. this.Data["json"] = br
  24. this.ServeJSON()
  25. }()
  26. sysUser := this.SysUser
  27. if sysUser == nil {
  28. br.Msg = "请登录"
  29. br.ErrMsg = "请登录,SysUser Is Empty"
  30. br.Ret = 408
  31. return
  32. }
  33. var req cygx.AddCygxUserFeedbackReq
  34. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  35. if err != nil {
  36. br.Msg = "参数解析异常!"
  37. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  38. return
  39. }
  40. userId := req.UserId
  41. content := req.Content
  42. if content == "" {
  43. br.Msg = "内容不能为空!"
  44. return
  45. }
  46. wxUser, err := models.GetWxUserItemByUserId(userId)
  47. if err != nil {
  48. br.Msg = "获取失败"
  49. br.ErrMsg = "获取失败, GetWxUserItemByUserId Err:" + err.Error()
  50. return
  51. }
  52. item := new(cygx.CygxUserFeedback)
  53. item.Content = content
  54. item.UserId = wxUser.UserId
  55. item.Mobile = wxUser.Mobile
  56. item.Email = wxUser.Email
  57. item.CompanyId = wxUser.CompanyId
  58. item.CompanyName = wxUser.CompanyName
  59. item.RealName = wxUser.RealName
  60. item.AdminId = sysUser.AdminId
  61. item.CreateTime = time.Now()
  62. var newId int64
  63. newId, err = cygx.AddCygxUserFeedback(item)
  64. if err != nil {
  65. br.Msg = "新增失败."
  66. br.ErrMsg = "新增失败,Err:" + err.Error()
  67. return
  68. }
  69. //权益客户新增历史备注总表
  70. itemRecord := new(company.CompanyHistoryRemark)
  71. itemRecord.CompanyId = wxUser.CompanyId
  72. itemRecord.Content = req.Content
  73. itemRecord.SysAdminId = sysUser.AdminId
  74. itemRecord.SysAdminName = sysUser.RealName
  75. itemRecord.CreateTime = time.Now().Local()
  76. itemRecord.ModifyTime = time.Now().Local()
  77. itemRecord.ShowTime = time.Now().Local()
  78. itemRecord.ProductId = 2
  79. itemRecord.UserId = wxUser.UserId
  80. itemRecord.Mobile = wxUser.Mobile
  81. itemRecord.Email = wxUser.Email
  82. itemRecord.RealName = wxUser.RealName
  83. itemRecord.TableName = "cygx_user_feedback"
  84. itemRecord.TableId = int(newId)
  85. go services.AddCompanyHistoryRemark(itemRecord)
  86. br.Ret = 200
  87. br.Success = true
  88. br.Msg = "操作成功"
  89. }
  90. // @Title 交流反馈列表接口
  91. // @Description 交流反馈列表接口
  92. // @Param UserId query int false "用户ID"
  93. // @Success 200 {object} cygx.CygxCygxUserFeedbackResp
  94. // @router /user_feedback/list [get]
  95. func (this *RaiServeCoAntroller) UserFeedbackList() {
  96. br := new(models.BaseResponse).Init()
  97. defer func() {
  98. this.Data["json"] = br
  99. this.ServeJSON()
  100. }()
  101. sysUser := this.SysUser
  102. if sysUser == nil {
  103. br.Msg = "请登录"
  104. br.ErrMsg = "请登录,SysUser Is Empty"
  105. br.Ret = 408
  106. return
  107. }
  108. userId, _ := this.GetInt("UserId")
  109. if userId < 1 {
  110. br.Msg = "请输入用户ID"
  111. return
  112. }
  113. resp := new(cygx.CygxCygxUserFeedbackResp)
  114. list, err := cygx.GetCygxUserFeedbackListByUserId(userId)
  115. if err != nil {
  116. br.Msg = "获取失败"
  117. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  118. return
  119. }
  120. resp.List = list
  121. br.Ret = 200
  122. br.Success = true
  123. br.Msg = "获取成功"
  124. br.Data = resp
  125. }
  126. // @Title 删除交流反馈接口
  127. // @Description 删除交流反馈接口
  128. // @Param request body cygx.CygxUserFeedbackIdReq true "type json string"
  129. // @Success 200 操作成功
  130. // @router /user_feedback/del [post]
  131. func (this *UserFeedbackController) UserFeedbackDel() {
  132. br := new(models.BaseResponse).Init()
  133. defer func() {
  134. this.Data["json"] = br
  135. this.ServeJSON()
  136. }()
  137. sysUser := this.SysUser
  138. if sysUser == nil {
  139. br.Msg = "请登录"
  140. br.ErrMsg = "请登录,SysUser Is Empty"
  141. br.Ret = 408
  142. return
  143. }
  144. var req cygx.CygxUserFeedbackIdReq
  145. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  146. if err != nil {
  147. br.Msg = "参数解析异常!"
  148. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  149. return
  150. }
  151. userFeedbackId := req.UserFeedbackId
  152. if userFeedbackId < 0 {
  153. br.Msg = "参数错误!"
  154. return
  155. }
  156. err = cygx.DeleteCygxUserFeedback(userFeedbackId)
  157. if err != nil {
  158. br.Msg = "删除失败"
  159. br.ErrMsg = "删除失败,Err:" + err.Error()
  160. return
  161. }
  162. go services.DelCompanyHistoryRemark("cygx_user_feedback", userFeedbackId) // 删除
  163. br.Ret = 200
  164. br.Success = true
  165. br.Msg = "删除成功"
  166. }