custom.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package overseas_custom
  2. import (
  3. "fmt"
  4. "hongze/hz_crm_api/models"
  5. "hongze/hz_crm_api/models/overseas_custom"
  6. "hongze/hz_crm_api/utils"
  7. )
  8. // @Title 海外客户统计数据
  9. // @Description 海外客户统计数据
  10. // @Param Keywords query string false "关键词:客户名称/社会信用码/联系人手机号/邮箱"
  11. // @Param SellerId query int false "销售ID"
  12. // @Success 200 {object} models.EnglishCompanyPageListResp
  13. // @router /custom/statistics [get]
  14. func (this *OverseasCustomController) CustomStatistics() {
  15. br := new(models.BaseResponse).Init()
  16. br.IsSendEmail = false
  17. defer func() {
  18. this.Data["json"] = br
  19. this.ServeJSON()
  20. }()
  21. sysUser := this.SysUser
  22. if sysUser == nil {
  23. br.Msg = "请登录"
  24. br.ErrMsg = "请登录,SysUser Is Empty"
  25. br.Ret = 408
  26. return
  27. }
  28. keywords := this.GetString("Keywords", "")
  29. sellerId, _ := this.GetInt("SellerId", 0)
  30. obj := new(overseas_custom.Custom)
  31. var cond string
  32. var pars []interface{}
  33. if keywords != "" {
  34. k := "%" + keywords + "%"
  35. enCompanyIds, e := models.GetEnCompanyIdsByKeyword(k)
  36. if e != nil {
  37. br.Msg = "获取失败"
  38. br.ErrMsg = "关键词获取英文客户IDs失败, Err: " + e.Error()
  39. return
  40. }
  41. //获取中文客户
  42. companyIds, err := obj.GetCompanyIdsByKeyword(k)
  43. if err != nil {
  44. br.Msg = "获取失败"
  45. br.ErrMsg = "关键词获取客户IDs失败, Err: " + err.Error()
  46. return
  47. }
  48. companyIds = append(companyIds, enCompanyIds...)
  49. cond += fmt.Sprintf(` AND c.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIds)))
  50. pars = append(pars, companyIds)
  51. }
  52. if sellerId > 0 {
  53. cond = ` AND m.seller_id=? `
  54. pars = append(pars, sellerId)
  55. }
  56. list, err := obj.GetCustomTotal(cond, pars)
  57. if err != nil {
  58. br.Msg = "获取失败"
  59. br.ErrMsg = "获取各状态总数失败, Err: " + err.Error()
  60. return
  61. }
  62. br.Ret = 200
  63. br.Success = true
  64. br.Msg = "获取成功"
  65. br.Data = list
  66. }