company_service_record.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/company"
  7. "hongze/hz_crm_api/services"
  8. "hongze/hz_crm_api/utils"
  9. "strings"
  10. "time"
  11. )
  12. // CompanyServiceRecordController 客户-沟通记录
  13. type CompanyServiceRecordController struct {
  14. BaseAuthController
  15. }
  16. // ServiceRecordList
  17. // @Title 沟通记录列表
  18. // @Description 沟通记录列表
  19. // @Param CompanyId query int true "客户ID"
  20. // @Param CompanyType query int true "客户类型,0:中文客户,1:英文客户"
  21. // @Success Ret=200 获取成功
  22. // @router /service_record/list [get]
  23. func (this *CompanyServiceRecordController) ServiceRecordList() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. if br.ErrMsg == "" {
  27. br.IsSendEmail = false
  28. }
  29. this.Data["json"] = br
  30. this.ServeJSON()
  31. }()
  32. sysUser := this.SysUser
  33. if sysUser == nil {
  34. br.Msg = "请登录"
  35. br.ErrMsg = "请登录, SysUser Is Empty"
  36. br.Ret = 408
  37. return
  38. }
  39. companyId, _ := this.GetInt("CompanyId", 0)
  40. if companyId <= 0 {
  41. br.Msg = "参数有误"
  42. return
  43. }
  44. companyType, _ := this.GetInt("CompanyType", 2)
  45. recordOB := new(company.CompanyServiceRecord)
  46. recordCond := fmt.Sprintf(` AND %s = ? AND company_type = ? `, company.CompanyServiceRecordColumns.CompanyId)
  47. recordPars := make([]interface{}, 0)
  48. recordPars = append(recordPars, companyId, companyType)
  49. records, e := recordOB.GetItemsByCondition(recordCond, recordPars, []string{}, "")
  50. if e != nil {
  51. br.Msg = "获取失败"
  52. br.ErrMsg = "获取客户沟通记录失败, Err: " + e.Error()
  53. return
  54. }
  55. respList := make([]*company.CompanyServiceRecordItem, 0)
  56. for _, r := range records {
  57. respList = append(respList, &company.CompanyServiceRecordItem{
  58. CompanyServiceRecordId: r.CompanyServiceRecordId,
  59. Content: r.Content,
  60. SysAdminId: r.SysAdminId,
  61. SysAdminName: r.SysAdminName,
  62. CreateTime: r.CreateTime.Format(utils.FormatDateTime),
  63. Mark: r.Mark,
  64. })
  65. }
  66. br.Data = respList
  67. br.Ret = 200
  68. br.Success = true
  69. br.Msg = "获取成功"
  70. }
  71. // ServiceRecordAdd
  72. // @Title 新增沟通记录
  73. // @Description 新增沟通记录
  74. // @Param request body company.CompanyServiceRecordAddReq true "type json string"
  75. // @Success Ret=200 操作成功
  76. // @router /service_record/add [post]
  77. func (this *CompanyServiceRecordController) ServiceRecordAdd() {
  78. br := new(models.BaseResponse).Init()
  79. defer func() {
  80. if br.ErrMsg == "" {
  81. br.IsSendEmail = false
  82. }
  83. this.Data["json"] = br
  84. this.ServeJSON()
  85. }()
  86. sysUser := this.SysUser
  87. if sysUser == nil {
  88. br.Msg = "请登录"
  89. br.ErrMsg = "请登录, SysUser Is Empty"
  90. br.Ret = 408
  91. return
  92. }
  93. var req company.CompanyServiceRecordAddReq
  94. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  95. br.Msg = "参数解析异常!"
  96. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  97. return
  98. }
  99. if req.CompanyId <= 0 {
  100. br.Msg = "参数有误"
  101. return
  102. }
  103. req.Content = strings.TrimSpace(req.Content)
  104. if req.Content == "" {
  105. br.Msg = "请输入沟通描述"
  106. return
  107. }
  108. //if len([]rune(req.Content)) > 100 {
  109. // br.Msg = "沟通描述不可超过100个字符"
  110. // return
  111. //}
  112. // 默认中文客户
  113. if req.CompanyType == 0 {
  114. req.CompanyType = 2
  115. }
  116. item := new(company.CompanyServiceRecord)
  117. item.CompanyType = req.CompanyType
  118. item.CompanyId = req.CompanyId
  119. item.Content = req.Content
  120. item.SysAdminId = sysUser.AdminId
  121. item.SysAdminName = sysUser.RealName
  122. item.CreateTime = time.Now().Local()
  123. item.ModifyTime = time.Now().Local()
  124. newId, e := item.Create()
  125. if e != nil {
  126. br.Msg = "操作失败"
  127. br.ErrMsg = "新增沟通记录失败, Err: " + e.Error()
  128. return
  129. }
  130. //权益客户新增历史备注总表
  131. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  132. itemRecord := new(company.CompanyHistoryRemark)
  133. itemRecord.CompanyId = req.CompanyId
  134. itemRecord.Content = req.Content
  135. itemRecord.SysAdminId = sysUser.AdminId
  136. itemRecord.SysAdminName = sysUser.RealName
  137. itemRecord.CreateTime = time.Now().Local()
  138. itemRecord.ModifyTime = time.Now().Local()
  139. itemRecord.ShowTime = time.Now().Local()
  140. itemRecord.ProductId = 2
  141. itemRecord.TableName = "company_service_record"
  142. itemRecord.TableId = newId
  143. go services.AddCompanyHistoryRemark(itemRecord)
  144. }
  145. br.Ret = 200
  146. br.Success = true
  147. br.Msg = "操作成功"
  148. }
  149. // ServiceRecordDel
  150. // @Title 删除沟通记录
  151. // @Description 删除沟通记录
  152. // @Param request body company.CompanyServiceRecordDelReq true "type json string"
  153. // @Success Ret=200 操作成功
  154. // @router /service_record/del [post]
  155. func (this *CompanyServiceRecordController) ServiceRecordDel() {
  156. br := new(models.BaseResponse).Init()
  157. defer func() {
  158. if br.ErrMsg == "" {
  159. br.IsSendEmail = false
  160. }
  161. this.Data["json"] = br
  162. this.ServeJSON()
  163. }()
  164. sysUser := this.SysUser
  165. if sysUser == nil {
  166. br.Msg = "请登录"
  167. br.ErrMsg = "请登录, SysUser Is Empty"
  168. br.Ret = 408
  169. return
  170. }
  171. var req company.CompanyServiceRecordDelReq
  172. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  173. br.Msg = "参数解析异常!"
  174. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  175. return
  176. }
  177. if req.CompanyServiceRecordId <= 0 {
  178. br.Msg = "参数有误"
  179. return
  180. }
  181. item := new(company.CompanyServiceRecord)
  182. if e := item.GetItemById(req.CompanyServiceRecordId); e != nil {
  183. if e.Error() == utils.ErrNoRow() {
  184. br.Msg = "沟通记录已被删除, 请刷新页面"
  185. return
  186. }
  187. br.Msg = "操作失败"
  188. br.ErrMsg = "获取沟通记录失败, Err: " + e.Error()
  189. return
  190. }
  191. if e := item.Del(); e != nil {
  192. br.Msg = "操作失败"
  193. br.ErrMsg = "删除沟通记录失败, Err: " + e.Error()
  194. return
  195. }
  196. br.Ret = 200
  197. br.Success = true
  198. br.Msg = "操作成功"
  199. }