custom.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package overseas_custom
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hz_crm_api/utils"
  6. )
  7. type Custom struct {
  8. CompanyId int `description:"客户id"`
  9. CompanyName string `description:"客户名称"`
  10. Nation string `description:"国家"`
  11. SellerId int `description:"销售id"`
  12. SellerName string `description:"销售名称"`
  13. CompanyStatus string `description:"状态"`
  14. ViewTotal int `description:"累计点击量"`
  15. RoadShowTotal int `description:"路演数量"`
  16. LastViewTime string `description:"最近阅读时间"`
  17. CreateTime string `description:"创建时间"`
  18. }
  19. type CustomTotal struct {
  20. CompanyStatus string `description:"状态"`
  21. Total int `description:"总数"`
  22. }
  23. func (obj *Custom) GetCustomTotal(condition string, pars []interface{}) (list []*CustomTotal, err error) {
  24. o := orm.NewOrm()
  25. sql := ``
  26. var databaseName string
  27. if utils.RunMode == "debug" {
  28. databaseName = "test_v2_hongze_rddp"
  29. } else {
  30. databaseName = "hongze_rddp"
  31. }
  32. sql = `SELECT company_status,COUNT(1) AS total FROM (
  33. SELECT a.company_id,a.company_name,a.nation,b.seller_id,b.seller_name,
  34. CASE b.status
  35. WHEN '正式' THEN '正式'
  36. WHEN '永续' THEN '正式'
  37. WHEN '试用' THEN '试用'
  38. ELSE '关闭' END AS company_status,
  39. b.view_total,b.road_show_total,a.created_time AS create_time,b.last_view_time
  40. FROM company AS a
  41. INNER JOIN company_product AS b ON a.company_id=b.company_id
  42. INNER JOIN overseas_custom_seller AS c ON b.seller_id=c.seller_id
  43. WHERE b.is_overseas = 0
  44. UNION ALL
  45. SELECT t.company_id+10000000,t.company_name,t.nation,t.seller_id,t.seller_name,
  46. CASE t.enabled
  47. WHEN 0 THEN '关闭'
  48. ELSE '试用' END AS company_status,
  49. t.view_total,0 AS road_show_total,t.create_time,'' AS last_view_time
  50. FROM %s.english_company AS t
  51. INNER JOIN overseas_custom_seller AS n ON t.seller_id=n.seller_id
  52. )AS m
  53. WHERE 1=1
  54. `
  55. if condition != "" {
  56. sql += condition
  57. }
  58. sql += ` GROUP BY m.company_status `
  59. sql = fmt.Sprintf(sql, databaseName)
  60. _, err = o.Raw(sql, pars).QueryRows(&list)
  61. return
  62. }
  63. // GetCompanyIdsByKeyword 关键词获取客户IDs
  64. func (obj *Custom) GetCompanyIdsByKeyword(keyword string) (companyIds []int, err error) {
  65. o := orm.NewOrm()
  66. sql := ` SELECT DISTINCT b.company_id FROM wx_user AS a
  67. INNER JOIN company AS b ON a.company_id=b.company_id
  68. WHERE 1=1 AND (a.email LIKE ? OR a.mobile LIKE ? OR b.company_name LIKE ? OR b.credit_code LIKE ? ) `
  69. _, err = o.Raw(sql, keyword, keyword, keyword, keyword).QueryRows(&companyIds)
  70. return
  71. }