custom.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package overseas_custom
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type Custom struct {
  7. }
  8. type RsCompany struct {
  9. CompanyId int
  10. Total int
  11. }
  12. // EnglishCompany 英文客户
  13. type EnglishCompany struct {
  14. CompanyId int `orm:"column(company_id);pk" description:"英文客户ID"`
  15. CompanyName string `description:"客户名称"`
  16. CountryCode string `description:"国家Code"`
  17. Country string `description:"国家"`
  18. SellerId int `description:"销售ID"`
  19. SellerName string `description:"销售姓名"`
  20. ViewTotal int `description:"累计点击量/阅读量"`
  21. IsDeleted int `description:"删除状态:0-正常;1-已删除"`
  22. CreateTime time.Time `description:"创建时间"`
  23. ModifyTime time.Time `description:"更新时间"`
  24. Enabled int `description:"0-禁用; 1-启用; 2-部分禁用"`
  25. Status int `description:"1:正式,2:临时,3:终止"`
  26. Nation string `description:"所属国家"`
  27. IsHide int `description:"是否隐藏:0:不隐藏,1:隐藏"`
  28. OverseasStatus string `description:"海外客户状态:'正式','试用','关闭'"`
  29. OverseasLabel int `description:"海外客户试用子标签:1未分类、2 推进、3 跟踪、4 预备、"`
  30. RoadShowTotal int `description:"累计路演次数"`
  31. LastViewTime string `description:"最后一次阅读时间"`
  32. }
  33. // 获取客户路演数据
  34. func (obj *Custom) GetRsCompanyTotal() (list []*RsCompany, err error) {
  35. o := orm.NewOrm()
  36. sql := `SELECT a.company_id,COUNT(1) AS total
  37. FROM rs_calendar AS a
  38. INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id = b.rs_calendar_id
  39. WHERE
  40. a.source = 0
  41. AND b.status = 2
  42. AND a.english_company=1
  43. GROUP BY a.company_id`
  44. _, err = o.Raw(sql).QueryRows(&list)
  45. return
  46. }
  47. // 获取所有英文客户
  48. func (obj *Custom) GetEnglishCompanyAll() (list []*EnglishCompany, err error) {
  49. o := orm.NewOrmUsingDB("rddp")
  50. sql := `SELECT * FROM english_company WHERE is_deleted = 0 `
  51. _, err = o.Raw(sql).QueryRows(&list)
  52. return
  53. }
  54. func (obj *Custom) UpdateEnglishCompanyRoadShowTotal(companyId, total int) (err error) {
  55. o := orm.NewOrmUsingDB("rddp")
  56. sql := ` UPDATE english_company SET road_show_total=? WHERE company_id=? `
  57. _, err = o.Raw(sql, total, companyId).Exec()
  58. return
  59. }
  60. // 获取客户路演数据
  61. func (obj *Custom) GetEnglishCompanyLastViewTime() (list []*EnglishCompany, err error) {
  62. o := orm.NewOrmUsingDB("rddp")
  63. sql := ` SELECT b.company_id,MAX(a.create_time) AS last_view_time
  64. FROM english_report_email_pv AS a
  65. INNER JOIN english_report_email AS b ON a.email_id=b.id
  66. GROUP BY b.company_id `
  67. _, err = o.Raw(sql).QueryRows(&list)
  68. return
  69. }
  70. func (obj *Custom) UpdateEnglishCompanyLastViewTime(companyId int, lastViewTime string) (err error) {
  71. o := orm.NewOrmUsingDB("rddp")
  72. sql := ` UPDATE english_company SET last_view_time=? WHERE company_id=? `
  73. _, err = o.Raw(sql, lastViewTime, companyId).Exec()
  74. return
  75. }