company_view_statistics.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // CompanyViewStatistics 客户报告报告阅读数量统计表
  7. type CompanyViewStatistics struct {
  8. Id int `orm:"column(id)" description:"自增Id"`
  9. CompanyId int `description:"客户id"`
  10. ViewNum int `description:"阅读总数"`
  11. Date time.Time `description:"阅读日期"`
  12. CreateTime time.Time `description:"添加时间"`
  13. }
  14. // CompanyViewTotalSlice 获取客户的浏览次数
  15. type CompanyViewTotalSellerSlice struct {
  16. CompanyIds string `description:"客户id字符串"`
  17. Num int `description:"用户浏览次数"`
  18. AdminId int `description:"所属销售id"`
  19. }
  20. // GetCompanyViewTotalList 获取客户的浏览数
  21. func GetCompanyViewTotalList(condition string, pars []interface{}, viewNum int, sumNumType string) (items []*CompanyViewTotalSellerSlice, err error) {
  22. o := orm.NewOrm()
  23. sql := `select count(DISTINCT(company_id)) num,GROUP_CONCAT(DISTINCT company_id SEPARATOR ',') AS company_ids,admin_id from (SELECT sum(a.view_num) sum_num,a.company_id,b.seller_id admin_id FROM company_view_statistics a
  24. join company_product b on a.company_id=b.company_id
  25. WHERE 1=1 `
  26. if condition != "" {
  27. sql += condition
  28. }
  29. childSql := ` sum_num >= `
  30. if sumNumType == "<" {
  31. childSql = ` sum_num ` + sumNumType + ` `
  32. }
  33. sql += ` GROUP BY company_id) b where 1 = 1 and ` + childSql + `? GROUP BY admin_id`
  34. _, err = o.Raw(sql, pars, viewNum).QueryRows(&items)
  35. return
  36. }
  37. // GetAllCompanyViewTotalList 获取所有客户的浏览数
  38. func GetAllCompanyViewTotalList(condition string, pars []interface{}, viewNum int, sumNumType string) (items []*CompanyViewTotalSellerSlice, err error) {
  39. o := orm.NewOrm()
  40. sql := `select count(DISTINCT(company_id)) num,GROUP_CONCAT(DISTINCT company_id SEPARATOR ',') AS company_ids,admin_id from (SELECT sum(a.view_num) sum_num,a.company_id,b.seller_id admin_id FROM company_view_statistics a
  41. join company_product b on a.company_id=b.company_id
  42. WHERE 1=1 `
  43. if condition != "" {
  44. sql += condition
  45. }
  46. childSql := ` sum_num >= `
  47. if sumNumType == "<" {
  48. childSql = ` sum_num ` + sumNumType + ` `
  49. }
  50. sql += ` GROUP BY company_id) b where 1 = 1 and ` + childSql + `? GROUP BY admin_id`
  51. _, err = o.Raw(sql, pars, viewNum).QueryRows(&items)
  52. return
  53. }