company.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package roadshow
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/utils"
  5. )
  6. type CompanySearchView struct {
  7. CompanyId int `orm:"column(company_id);pk"`
  8. CompanyName string `description:"客户名称"`
  9. CreditCode string `description:"社会统一信用码"`
  10. CompanyCode string `description:"客户编码"`
  11. EnglishCompany int `description:"是否为英文客户"`
  12. }
  13. func CompanySearch(sellerId int, keyWord string) (list []*CompanySearchView, err error) {
  14. o := orm.NewOrm()
  15. sql := ` SELECT b.company_id,b.company_name FROM company AS a
  16. INNER JOIN company_product AS b ON a.company_id=b.company_id
  17. WHERE b.seller_id=?
  18. AND b.status IN('正式','试用')
  19. AND b.company_name LIKE ?
  20. `
  21. sql += ` GROUP BY b.company_id `
  22. _, err = o.Raw(sql, sellerId, keyWord).QueryRows(&list)
  23. return
  24. }
  25. func CompanySearchV2(sellerId, groupId int, keyWord, roleTypeCode string) (list []*CompanySearchView, err error) {
  26. list = make([]*CompanySearchView, 0)
  27. // 中文客户
  28. companies := make([]*CompanySearchView, 0)
  29. o := orm.NewOrm()
  30. var sql string
  31. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN { // 权益管理员跟管理员的筛选
  32. sql = `SELECT
  33. b.company_id,
  34. a.company_name,
  35. 0 AS english_company
  36. FROM
  37. company AS a
  38. INNER JOIN company_product AS b ON a.company_id = b.company_id
  39. WHERE
  40. 1=1
  41. AND IF ( b.product_id = 1 , b.status IN ('正式', '试用', '永续') ,1=1 )
  42. AND IF ( b.product_id = 2 , b.status IN ('正式', '试用', '永续', '冻结', '流失') ,1=1 )
  43. AND a.company_name LIKE ?
  44. GROUP BY
  45. b.company_id `
  46. _, err = o.Raw(sql, keyWord).QueryRows(&companies)
  47. if err != nil {
  48. return
  49. }
  50. } else {
  51. sql = `SELECT
  52. b.company_id,
  53. a.company_name,
  54. 0 AS english_company
  55. FROM
  56. company AS a
  57. INNER JOIN company_product AS b ON a.company_id = b.company_id
  58. WHERE
  59. 1=1
  60. AND IF ( b.product_id = 1 , b.status IN ('正式', '试用', '永续') ,1=1 )
  61. AND IF ( b.product_id = 2 , b.status IN ('正式', '试用', '永续', '冻结', '流失') ,1=1 )
  62. AND (b.seller_id = ? OR b.share_seller_id = ? OR b.group_id = ? OR b.share_group_id = ? ) AND a.company_name LIKE ?
  63. GROUP BY
  64. b.company_id `
  65. _, err = o.Raw(sql, sellerId, sellerId, groupId, groupId, keyWord).QueryRows(&companies)
  66. if err != nil {
  67. return
  68. }
  69. }
  70. list = append(list, companies...)
  71. // 英文客户
  72. enCompanies := make([]*CompanySearchView, 0)
  73. o2 := orm.NewOrmUsingDB("rddp")
  74. sql = `SELECT
  75. company_id,
  76. company_name,
  77. 1 AS english_company
  78. FROM
  79. english_company
  80. WHERE
  81. is_deleted = 0 AND enabled > 0 AND company_name LIKE ?`
  82. _, err = o2.Raw(sql, keyWord).QueryRows(&enCompanies)
  83. if err != nil {
  84. return
  85. }
  86. list = append(list, enCompanies...)
  87. return
  88. }
  89. type CompanyDetailView struct {
  90. CompanyId int `orm:"column(company_id);pk"`
  91. CompanyName string `description:"客户名称"`
  92. Status string `description:"客户状态"`
  93. IndustryId int `description:"行业id"`
  94. IndustryName string `description:"行业名称"`
  95. PermissionName string `description:"开通品种"`
  96. ReportReadTotal int `description:"累计阅读次数"`
  97. EnglishCompany int `description:"是否为英文客户: 0-否; 1-是"`
  98. EnglishCountry string `description:"英文客户-国家"`
  99. EnglishViewTotal int `description:"英文客户-累计点击量"`
  100. }