custom.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package overseas_custom
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hongze_task/utils"
  6. "time"
  7. )
  8. type Custom struct {
  9. CompanyId int `description:"客户id"`
  10. CompanyName string `description:"客户名称"`
  11. Nation string `description:"国家"`
  12. SellerId int `description:"销售id"`
  13. SellerName string `description:"销售名称"`
  14. CompanyStatus string `description:"状态"`
  15. ViewTotal int `description:"累计点击量"`
  16. RoadShowTotal int `description:"路演数量"`
  17. LastViewTime string `description:"最近阅读时间"`
  18. CreateTime string `description:"创建时间"`
  19. IsHide int `description:"是否隐藏:0:不隐藏,1:隐藏"`
  20. OverseasStatus string `description:"海外客户状态:'正式','试用','关闭'"`
  21. Source int `description:"来源:1,英文客户,2:客户列表"`
  22. OverseasLabel int `description:"海外客户试用子标签:1未分类、2 推进、3 跟踪、4 预备、"`
  23. ResetBtn int `description:"转正式和重置按钮:同步过来默认为0:显示转正式为1:显示重置为2"`
  24. }
  25. type RsCompany struct {
  26. CompanyId int
  27. Total int
  28. }
  29. // EnglishCompany 英文客户
  30. type EnglishCompany struct {
  31. CompanyId int `orm:"column(company_id);pk" description:"英文客户ID"`
  32. CompanyName string `description:"客户名称"`
  33. CountryCode string `description:"国家Code"`
  34. Country string `description:"国家"`
  35. SellerId int `description:"销售ID"`
  36. SellerName string `description:"销售姓名"`
  37. ViewTotal int `description:"累计点击量/阅读量"`
  38. IsDeleted int `description:"删除状态:0-正常;1-已删除"`
  39. CreateTime time.Time `description:"创建时间"`
  40. ModifyTime time.Time `description:"更新时间"`
  41. Enabled int `description:"0-禁用; 1-启用; 2-部分禁用"`
  42. Status int `description:"1:正式,2:临时,3:终止"`
  43. Nation string `description:"所属国家"`
  44. IsHide int `description:"是否隐藏:0:不隐藏,1:隐藏"`
  45. OverseasStatus string `description:"海外客户状态:'正式','试用','关闭'"`
  46. OverseasLabel int `description:"海外客户试用子标签:1未分类、2 推进、3 跟踪、4 预备、"`
  47. RoadShowTotal int `description:"累计路演次数"`
  48. LastViewTime string `description:"最后一次阅读时间"`
  49. }
  50. // 获取客户路演数据
  51. func (obj *Custom) GetRsCompanyTotal() (list []*RsCompany, err error) {
  52. o := orm.NewOrm()
  53. sql := `SELECT a.company_id,COUNT(1) AS total
  54. FROM rs_calendar AS a
  55. INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id = b.rs_calendar_id
  56. WHERE
  57. a.source = 0
  58. AND b.status = 2
  59. AND a.english_company=1
  60. GROUP BY a.company_id`
  61. _, err = o.Raw(sql).QueryRows(&list)
  62. return
  63. }
  64. // 获取所有英文客户
  65. func (obj *Custom) GetEnglishCompanyAll() (list []*EnglishCompany, err error) {
  66. o := orm.NewOrmUsingDB("rddp")
  67. sql := `SELECT * FROM english_company WHERE is_deleted = 0 `
  68. _, err = o.Raw(sql).QueryRows(&list)
  69. return
  70. }
  71. func (obj *Custom) UpdateEnglishCompanyRoadShowTotal(companyId, total int) (err error) {
  72. o := orm.NewOrmUsingDB("rddp")
  73. sql := ` UPDATE english_company SET road_show_total=? WHERE company_id=? `
  74. _, err = o.Raw(sql, total, companyId).Exec()
  75. return
  76. }
  77. // 获取客户路演数据
  78. func (obj *Custom) GetEnglishCompanyLastViewTime() (list []*EnglishCompany, err error) {
  79. o := orm.NewOrmUsingDB("rddp")
  80. sql := ` SELECT b.company_id,MAX(a.create_time) AS last_view_time
  81. FROM english_report_email_pv AS a
  82. INNER JOIN english_report_email AS b ON a.email_id=b.id
  83. GROUP BY b.company_id `
  84. _, err = o.Raw(sql).QueryRows(&list)
  85. return
  86. }
  87. func (obj *Custom) UpdateEnglishCompanyLastViewTime(companyId int, lastViewTime string) (err error) {
  88. o := orm.NewOrmUsingDB("rddp")
  89. sql := ` UPDATE english_company SET last_view_time=? WHERE company_id=? `
  90. _, err = o.Raw(sql, lastViewTime, companyId).Exec()
  91. return
  92. }
  93. type OverseasCompany struct {
  94. }
  95. // 获取客户路演数据
  96. func (obj *Custom) GetOverseasCompany() (list []*Custom, err error) {
  97. o := orm.NewOrm()
  98. sql := ``
  99. var databaseName string
  100. if utils.RunMode == "debug" {
  101. databaseName = "test_v2_hongze_rddp"
  102. } else {
  103. databaseName = "hongze_rddp"
  104. }
  105. sql = ` SELECT * FROM (
  106. SELECT a.company_id,a.company_name,a.nation,b.seller_id,b.seller_name,
  107. b.view_total,b.road_show_total,a.created_time AS create_time,b.last_view_time,a.is_hide,a.overseas_status,
  108. 2 AS source,b.overseas_label,a.reset_btn,
  109. CASE b.status
  110. WHEN '正式' THEN '正式'
  111. WHEN '永续' THEN '正式'
  112. WHEN '试用' THEN '试用'
  113. ELSE '关闭' END AS company_status
  114. FROM company AS a
  115. INNER JOIN company_product AS b ON a.company_id=b.company_id
  116. INNER JOIN overseas_custom_seller AS c ON b.seller_id=c.seller_id
  117. WHERE b.product_id=1 AND b.is_overseas = 0
  118. UNION ALL
  119. SELECT t.company_id+10000000,t.company_name,t.nation,t.seller_id,t.seller_name,
  120. t.view_total,t.road_show_total,t.create_time,t.last_view_time,t.is_hide,t.overseas_status,
  121. 1 AS source,t.overseas_label,t.reset_btn,
  122. CASE t.enabled
  123. WHEN 0 THEN '关闭'
  124. ELSE '试用' END AS company_status
  125. FROM %s.english_company AS t
  126. INNER JOIN overseas_custom_seller AS n ON t.seller_id=n.seller_id
  127. WHERE 1=1 AND t.is_deleted=0
  128. )AS m WHERE 1=1
  129. AND m.company_status<>m.overseas_status `
  130. sql = fmt.Sprintf(sql, databaseName)
  131. _, err = o.Raw(sql).QueryRows(&list)
  132. return
  133. }
  134. func (obj *Custom) UpdateEnglishCompanyOverseasStatus(companyId int, companyStatus string) (err error) {
  135. o := orm.NewOrmUsingDB("rddp")
  136. sql := ` UPDATE english_company SET overseas_status=? WHERE company_id=? AND overseas_status<>'正式' `
  137. _, err = o.Raw(sql, companyStatus, companyId).Exec()
  138. return
  139. }
  140. func (obj *Custom) UpdateCompanyOverseasStatus(companyId int, companyStatus string) (err error) {
  141. o := orm.NewOrm()
  142. sql := ` UPDATE company SET overseas_status=? WHERE company_id=? AND overseas_status<>'正式' `
  143. _, err = o.Raw(sql, companyStatus, companyId).Exec()
  144. return
  145. }