custom.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. package overseas_custom
  2. import (
  3. "fmt"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/overseas_custom"
  7. "hongze/hz_crm_api/utils"
  8. )
  9. // @Title 海外客户统计数据
  10. // @Description 海外客户统计数据
  11. // @Param Keywords query string false "关键词:客户名称/社会信用码/联系人手机号/邮箱"
  12. // @Param SellerId query int false "销售ID"
  13. // @Success 200 {object} models.EnglishCompanyPageListResp
  14. // @router /custom/statistics [get]
  15. func (this *OverseasCustomController) CustomStatistics() {
  16. br := new(models.BaseResponse).Init()
  17. br.IsSendEmail = false
  18. defer func() {
  19. this.Data["json"] = br
  20. this.ServeJSON()
  21. }()
  22. sysUser := this.SysUser
  23. if sysUser == nil {
  24. br.Msg = "请登录"
  25. br.ErrMsg = "请登录,SysUser Is Empty"
  26. br.Ret = 408
  27. return
  28. }
  29. keywords := this.GetString("Keywords", "")
  30. sellerId, _ := this.GetInt("SellerId", 0)
  31. obj := new(overseas_custom.Custom)
  32. var cond string
  33. var pars []interface{}
  34. if keywords != "" {
  35. k := "%" + keywords + "%"
  36. enCompanyIds, e := models.GetEnCompanyIdsByKeyword(k)
  37. if e != nil {
  38. br.Msg = "获取失败"
  39. br.ErrMsg = "关键词获取英文客户IDs失败, Err: " + e.Error()
  40. return
  41. }
  42. //获取中文客户
  43. companyIds, err := obj.GetCompanyIdsByKeyword(k)
  44. if err != nil {
  45. br.Msg = "获取失败"
  46. br.ErrMsg = "关键词获取客户IDs失败, Err: " + err.Error()
  47. return
  48. }
  49. companyIds = append(companyIds, enCompanyIds...)
  50. cond += fmt.Sprintf(` AND c.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIds)))
  51. pars = append(pars, companyIds)
  52. }
  53. if sellerId > 0 {
  54. cond = ` AND m.seller_id=? `
  55. pars = append(pars, sellerId)
  56. }
  57. list, err := obj.GetCustomTotal(cond, pars)
  58. if err != nil {
  59. br.Msg = "获取失败"
  60. br.ErrMsg = "获取各状态总数失败, Err: " + err.Error()
  61. return
  62. }
  63. br.Ret = 200
  64. br.Success = true
  65. br.Msg = "获取成功"
  66. br.Data = list
  67. }
  68. // @Title 获取海外客户列表数据
  69. // @Description 获取海外客户列表数据
  70. // @Param PageSize query int true "每页数据条数"
  71. // @Param CurrentIndex query int true "当前页页码,从1开始"
  72. // @Param Keywords query string false "关键词:客户名称/社会信用码/联系人手机号/邮箱"
  73. // @Param CompanyStatus query string false "状态:全部,正式,试用,关闭"
  74. // @Param SellerId query int false "销售ID"
  75. // @Param CustomType query int false "1:海外客户,2:隐藏客户"
  76. // @Param SortField query string false "排序字段:ViewTotal,RoadShowTotal,CreateTime"
  77. // @Param SortDesc query int false "1:降序,默认,2:升序"
  78. // @Success 200 {object} models.EnglishCompanyPageListResp
  79. // @router /custom/list [get]
  80. func (this *OverseasCustomController) CustomList() {
  81. br := new(models.BaseResponse).Init()
  82. br.IsSendEmail = false
  83. defer func() {
  84. this.Data["json"] = br
  85. this.ServeJSON()
  86. }()
  87. sysUser := this.SysUser
  88. if sysUser == nil {
  89. br.Msg = "请登录"
  90. br.ErrMsg = "请登录,SysUser Is Empty"
  91. br.Ret = 408
  92. return
  93. }
  94. pageSize, _ := this.GetInt("PageSize")
  95. currentIndex, _ := this.GetInt("CurrentIndex")
  96. keywords := this.GetString("Keywords", "")
  97. sellerId, _ := this.GetInt("SellerId", 0)
  98. companyStatus := this.GetString("CompanyStatus")
  99. sortField := this.GetString("SortField")
  100. sortDesc, _ := this.GetInt("SortDesc")
  101. var startSize int
  102. if pageSize <= 0 {
  103. pageSize = utils.PageSize20
  104. }
  105. if currentIndex <= 0 {
  106. currentIndex = 1
  107. }
  108. startSize = paging.StartIndex(currentIndex, pageSize)
  109. obj := new(overseas_custom.Custom)
  110. var condition string
  111. var pars []interface{}
  112. if keywords != "" {
  113. k := "%" + keywords + "%"
  114. enCompanyIds, e := models.GetEnCompanyIdsByKeyword(k)
  115. if e != nil {
  116. br.Msg = "获取失败"
  117. br.ErrMsg = "关键词获取英文客户IDs失败, Err: " + e.Error()
  118. return
  119. }
  120. //获取中文客户
  121. companyIds, err := obj.GetCompanyIdsByKeyword(k)
  122. if err != nil {
  123. br.Msg = "获取失败"
  124. br.ErrMsg = "关键词获取客户IDs失败, Err: " + err.Error()
  125. return
  126. }
  127. companyIds = append(companyIds, enCompanyIds...)
  128. condition += fmt.Sprintf(` AND c.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIds)))
  129. pars = append(pars, companyIds)
  130. }
  131. if sellerId > 0 {
  132. condition = ` AND m.seller_id=? `
  133. pars = append(pars, sellerId)
  134. }
  135. total, err := obj.GetCustomListCount(condition, pars, companyStatus)
  136. if err != nil {
  137. br.Msg = "获取失败"
  138. br.ErrMsg = "获取数据总数失败, Err: " + err.Error()
  139. return
  140. }
  141. list, err := obj.GetCustomList(condition, pars, companyStatus, sortField, startSize, pageSize, sortDesc)
  142. if err != nil {
  143. br.Msg = "获取失败"
  144. br.ErrMsg = "获取数据失败, Err: " + err.Error()
  145. return
  146. }
  147. page := paging.GetPaging(currentIndex, pageSize, total)
  148. resp := new(overseas_custom.CustomListResp)
  149. resp.Paging = page
  150. resp.List = list
  151. br.Ret = 200
  152. br.Success = true
  153. br.Msg = "获取成功"
  154. br.Data = resp
  155. }