user_view_history.go 974 B

12345678910111213141516171819202122232425262728293031
  1. package models
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. )
  6. type ResearchReportViewPUV struct {
  7. ResearchReportId int `gorm:"column:research_report_id;primaryKey;type:int" orm:"column(research_report_id);pk" description:"研究报告ID"`
  8. Pv int `gorm:"column:pv;type:int" orm:"column(pv)" description:"页面浏览量"`
  9. Uv int `gorm:"column:uv;type:int" orm:"column(uv)" description:"独立访客数"`
  10. }
  11. // GetPUVByResearchReportIds 通过报告IDs获取老报告PV、UV
  12. func GetPUVByResearchReportIds(reportIds []string) (list []*ResearchReportViewPUV, err error) {
  13. if len(reportIds) == 0 {
  14. return
  15. }
  16. sql := `SELECT
  17. research_report_id,
  18. COUNT(1) AS pv,
  19. COUNT(DISTINCT user_id) AS uv
  20. FROM
  21. user_view_history
  22. WHERE
  23. research_report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)
  24. GROUP BY
  25. research_report_id`
  26. err = global.DmSQL["weekly"].Raw(sql, reportIds).Scan(&list).Error
  27. return
  28. }