user_view_statistics.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package models
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/orm"
  4. "time"
  5. )
  6. // UserViewStatistics 用户报告报告阅读数量统计表
  7. type UserViewStatistics struct {
  8. Id int `orm:"column(id)" description:"自增Id"`
  9. Mobile string `description:"手机号"`
  10. Email string `description:"手机号"`
  11. RealName string `description:"联系人名称"`
  12. CompanyName string `description:"客户名称"`
  13. ViewNum int `description:"阅读总数"`
  14. Date time.Time `description:"阅读日期"`
  15. CreateTime time.Time `description:"添加时间"`
  16. }
  17. // AddMultiUserViewStatistics 添加用户报告报告阅读数量统计记录
  18. func AddMultiUserViewStatistics(list []*UserViewStatistics) (err error) {
  19. if len(list) <= 0 {
  20. return
  21. }
  22. o := orm.NewOrm()
  23. _, err = o.InsertMulti(len(list), list)
  24. return
  25. }
  26. // GetUserViewStatisticsCount 获取某天的用户报告报告阅读数量统计记录数量
  27. func GetUserViewStatisticsCount(dayStr string) (count int, err error) {
  28. o := orm.NewOrm()
  29. //产品权限
  30. sql := `SELECT count(1) count FROM user_view_statistics WHERE date = ?`
  31. err = o.Raw(sql, dayStr).QueryRow(&count)
  32. return
  33. }
  34. // UserViewMobileTotalSlice 根据用户手机号字符串获取用户的浏览数
  35. type UserViewMobileTotalSlice struct {
  36. Mobile string `description:"用户手机号"`
  37. CompanyName string `description:"客户名称"`
  38. RealName string `description:"用户名称"`
  39. Total int `description:"总阅读数"`
  40. }
  41. // UserViewEmailTotalSlice 根据用户邮箱字符串获取用户的浏览数
  42. type UserViewEmailTotalSlice struct {
  43. Email string `description:"用户邮箱"`
  44. CompanyName string `description:"客户名称"`
  45. RealName string `description:"用户名称"`
  46. Total int `description:"总阅读数"`
  47. }
  48. func GetCountUserViewHistoryByMobiles(date string) (items []*UserViewMobileTotalSlice, err error) {
  49. o := orm.NewOrm()
  50. sql := `SELECT count(1) total,mobile,company_name,real_name FROM user_view_history WHERE created_time >= ? and created_time <= ? and mobile != "" group by mobile`
  51. _, err = o.Raw(sql, date+" 00:00:00", date+" 23:59:59").QueryRows(&items)
  52. return
  53. }
  54. func GetCountUserViewHistoryByEmails(date string) (items []*UserViewEmailTotalSlice, err error) {
  55. o := orm.NewOrm()
  56. sql := `SELECT count(1) total,email,company_name,real_name FROM user_view_history WHERE created_time >= ? and created_time <= ? and email != "" group by email`
  57. _, err = o.Raw(sql, date+" 00:00:00", date+" 23:59:59").QueryRows(&items)
  58. return
  59. //return items2,err
  60. }
  61. func GetReportViewMaxTimeByMobiles(date string) (items []*UserViewMobileTotalSlice, err error) {
  62. o := orm.NewOrm()
  63. o.Using("rddp")
  64. rddpSql := `SELECT mobile,company_name,real_name,COUNT(1) AS total FROM report_view_record WHERE create_time >= ? and create_time <= ? and mobile != "" group by mobile`
  65. _, err = o.Raw(rddpSql, date+" 00:00:00", date+" 23:59:59").QueryRows(&items)
  66. return
  67. }
  68. func GetReportViewMaxTimeByEmails(date string) (items []*UserViewEmailTotalSlice, err error) {
  69. o := orm.NewOrm()
  70. o.Using("rddp")
  71. rddpSql := `SELECT mobile,company_name,real_name,COUNT(1) AS total FROM report_view_record WHERE create_time >= ? and create_time <= ? and email != "" group by email`
  72. _, err = o.Raw(rddpSql, date+" 00:00:00", date+" 23:59:59").QueryRows(&items)
  73. return
  74. }
  75. // GetAdvisoryCountUserViewHistoryByMobiles 每日资讯
  76. func GetAdvisoryCountUserViewHistoryByMobiles(date string) (items []*UserViewMobileTotalSlice, err error) {
  77. o := orm.NewOrm()
  78. sql := `SELECT count(1) total,mobile,company_name,real_name FROM advisory_user_chart_article_record WHERE create_time >= ? and create_time <= ? and mobile != "" group by mobile`
  79. _, err = o.Raw(sql, date+" 00:00:00", date+" 23:59:59").QueryRows(&items)
  80. return
  81. }
  82. // GetAdvisoryCountUserViewHistoryByEmails 每日资讯
  83. func GetAdvisoryCountUserViewHistoryByEmails(date string) (items []*UserViewEmailTotalSlice, err error) {
  84. o := orm.NewOrm()
  85. sql := `SELECT count(1) total,email,company_name,real_name as created_time FROM advisory_user_chart_article_record WHERE create_time >= ? and create_time <= ? and email != "" group by email`
  86. _, err = o.Raw(sql, date+" 00:00:00", date+" 23:59:59").QueryRows(&items)
  87. return
  88. //return items2,err
  89. }