user_view_history.go 734 B

1234567891011121314151617181920212223242526272829303132
  1. package models
  2. import (
  3. "eta/eta_mobile/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. )
  6. type ResearchReportViewPUV struct {
  7. ResearchReportId int
  8. Pv int
  9. Uv int
  10. }
  11. // GetPUVByResearchReportIds 通过报告IDs获取老报告PV、UV
  12. func GetPUVByResearchReportIds(reportIds []string) (list []*ResearchReportViewPUV, err error) {
  13. if len(reportIds) == 0 {
  14. return
  15. }
  16. o := orm.NewOrmUsingDB("weekly")
  17. sql := `SELECT
  18. research_report_id,
  19. COUNT(1) AS pv,
  20. COUNT(DISTINCT user_id) AS uv
  21. FROM
  22. user_view_history
  23. WHERE
  24. research_report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)
  25. GROUP BY
  26. research_report_id`
  27. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  28. return
  29. }