search_keyword.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. )
  6. type KeyWordList struct {
  7. Sort int `description:"序号"`
  8. KeyWordNum int `description:"数量"`
  9. KeyWord string `description:"关键词"`
  10. }
  11. type CanDownload struct {
  12. IsCanDownload bool `description:"是否可以下载"`
  13. }
  14. func GetSearchKeyWordCount(condition string, pars []interface{}) (count int, err error) {
  15. sqlCount := ` SELECT COUNT(1) FROM( SELECT COUNT( 1 ) FROM cygx_search_key_word WHERE 1=1`
  16. if condition != "" {
  17. sqlCount += condition
  18. }
  19. sqlCount += ` GROUP BY key_word) as aa`
  20. o := orm.NewOrmUsingDB("hz_cygx")
  21. err = o.Raw(sqlCount, pars).QueryRow(&count)
  22. return
  23. }
  24. // 获取搜索关键词列表
  25. func GetSearchKeyWordList(condition string, pars []interface{}, startSize, pageSize int) (items []*KeyWordList, err error) {
  26. sql := `SELECT COUNT( key_word ) AS key_word_num, key_word FROM cygx_search_key_word WHERE 1= 1`
  27. if condition != "" {
  28. sql += condition
  29. }
  30. sql += ` GROUP BY key_word ORDER BY COUNT( key_word ) DESC LIMIT ?,? `
  31. o := orm.NewOrmUsingDB("hz_cygx")
  32. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  33. return
  34. }
  35. type SearchKeyWordListResp struct {
  36. List []*KeyWordList
  37. Paging *paging.PagingItem `description:"分页数据"`
  38. }
  39. type KeyWordListDownload struct {
  40. CompanyId int `description:"客户ID"`
  41. KeyWord string `description:"关键词"`
  42. CreateTime string `description:"搜索时间"`
  43. Mobile string `description:"手机号"`
  44. Email string `description:"邮箱"`
  45. RealName string `description:"客户姓名"`
  46. CompanyName string `description:"公司名称"`
  47. ProductName string `description:"产品名称"`
  48. SellerName string `description:"销售人员名称"`
  49. }
  50. // 获取7天搜索关键词列表
  51. func GetSearchKeyWordListDownload(starTime, endTime string) (items []*KeyWordListDownload, err error) {
  52. sql := `SELECT
  53. kw.*
  54. FROM
  55. cygx_search_key_word as kw
  56. WHERE
  57. kw.create_time > ?
  58. AND kw.create_time < ?
  59. AND wx.company_id > 1
  60. ORDER BY
  61. kw.create_time DESC`
  62. o := orm.NewOrmUsingDB("hz_cygx")
  63. _, err = o.Raw(sql, starTime, endTime).QueryRows(&items)
  64. return
  65. }
  66. // 销售获取7天搜索关键词列表
  67. func GetSearchKeyWordListDownloadSeller(starTime, endTime, sqlStr string) (items []*KeyWordListDownload, err error) {
  68. sql := `SELECT
  69. kw.*
  70. FROM
  71. cygx_search_key_word as kw
  72. WHERE
  73. kw.create_time > ?
  74. AND kw.create_time < ?
  75. AND wx.company_id > 1` + sqlStr +
  76. ` ORDER BY
  77. kw.create_time DESC`
  78. o := orm.NewOrmUsingDB("hz_cygx")
  79. _, err = o.Raw(sql, starTime, endTime).QueryRows(&items)
  80. return
  81. }
  82. type CompanyProduct struct {
  83. CompanyId int `description:"客户ID"`
  84. }
  85. //获取开通产品种类大于一的客户
  86. //func GetCompanyProductMoreOneList() (items []*CompanyProduct, err error) {
  87. // sql := `SELECT
  88. // company_id
  89. // FROM
  90. // company_product cp
  91. // WHERE cp.status IN ('试用','永续','正式')
  92. // GROUP BY
  93. // cp.company_id
  94. // HAVING
  95. // count( 1 )> 0`
  96. // o := orm.NewOrm()
  97. // _, err = o.Raw(sql).QueryRows(&items)
  98. // return
  99. //}
  100. func GetCompanyProductMoreOneList(starTime, endTime string) (items []*CompanyProduct, err error) {
  101. sql := `SELECT
  102. wx.company_id
  103. FROM
  104. cygx_search_key_word as kw
  105. WHERE
  106. kw.create_time > ?
  107. AND kw.create_time < ?
  108. AND wx.company_id > 1
  109. GROUP BY wx.company_id
  110. ORDER BY
  111. kw.create_time DESC`
  112. o := orm.NewOrmUsingDB("hz_cygx")
  113. _, err = o.Raw(sql, starTime, endTime).QueryRows(&items)
  114. return
  115. }
  116. type CompanyProductNameAndSeller struct {
  117. CompanyId int `description:"客户ID"`
  118. ProductName string `description:"产品名称"`
  119. SellerName string `description:"销售人员名称"`
  120. }
  121. // 获取开通产品种类大于一的客户
  122. func GetCompanyProductNameAndSellerAllList(pars []interface{}, companyIdStrr string) (items []*CompanyProductNameAndSeller, err error) {
  123. sql := `SELECT
  124. ad.real_name as seller_name,
  125. cp.product_name,
  126. cp.company_id
  127. FROM
  128. company_product as cp
  129. INNER JOIN admin AS ad ON cp.seller_id = ad.admin_id
  130. WHERE company_id IN (` + companyIdStrr + `)`
  131. o := orm.NewOrm()
  132. _, err = o.Raw(sql, pars).QueryRows(&items)
  133. return
  134. }
  135. type GetKeywordCountUrl struct {
  136. Url string `description:"下载链接"`
  137. }