user_view_history.go 1.0 KB

123456789101112131415161718192021222324252627282930313233
  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. //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. err = global.DmSQL["weekly"].Raw(sql, reportIds).Scan(&list).Error
  29. return
  30. }