company_view_statistics.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // AddMultiCompanyViewStatistics 添加客户报告报告阅读数量统计记录
  15. func AddMultiCompanyViewStatistics(list []*CompanyViewStatistics) (err error) {
  16. if len(list) <= 0 {
  17. return
  18. }
  19. o := orm.NewOrm()
  20. _, err = o.InsertMulti(len(list), list)
  21. return
  22. }
  23. // AddCompanyViewStatistics 添加客户报告报告阅读数量统计记录
  24. func AddCompanyViewStatistics(item *CompanyViewStatistics) (err error) {
  25. o := orm.NewOrm()
  26. _, err = o.Insert(item)
  27. return
  28. }
  29. // Update 更新客户报告报告阅读数量统计表
  30. func (companyViewStatistics *CompanyViewStatistics) Update(cols []string) (err error) {
  31. o := orm.NewOrm()
  32. _, err = o.Update(companyViewStatistics, cols...)
  33. return
  34. }
  35. // GetCompanyViewStatisticsCount 获取某天的客户报告报告阅读数量统计记录数量
  36. func GetCompanyViewStatisticsCount(dayStr string) (count int, err error) {
  37. o := orm.NewOrm()
  38. sql := `SELECT count(1) count FROM company_view_statistics WHERE date = ?`
  39. err = o.Raw(sql, dayStr).QueryRow(&count)
  40. return
  41. }
  42. // GetCompanyViewStatisticsByCompanyId 根据客户id、日期获取数据
  43. func GetCompanyViewStatisticsByCompanyId(companyId int, date string) (item *CompanyViewStatistics, err error) {
  44. o := orm.NewOrm()
  45. sql := `SELECT * from company_view_statistics WHERE company_id=? and date = ?`
  46. err = o.Raw(sql, companyId, date).QueryRow(&item)
  47. return
  48. }
  49. // CompanyViewTotalSlice 根据用户手机号字符串获取客户的浏览数
  50. type CompanyViewTotalSlice struct {
  51. CompanyId int `description:"用户手机号"`
  52. Total int `description:"总阅读数"`
  53. Date string `description:"统计的日期"`
  54. }
  55. // GetCompanyViewMobileTotalList 根据用户手机号字符串获取客户的浏览数
  56. func GetCompanyViewMobileTotalList(date string) (items []*CompanyViewTotalSlice, err error) {
  57. o := orm.NewOrm()
  58. sql := `SELECT sum(a.view_num) total,a.date,b.company_id FROM user_view_statistics a join wx_user b on a.mobile=b.mobile
  59. WHERE a.mobile != "" and b.mobile != "" and a.date = ? group by company_id`
  60. _, err = o.Raw(sql, date).QueryRows(&items)
  61. return
  62. }
  63. // GetCompanyViewEmailTotalList 根据用户邮箱字符串获取客户的浏览数
  64. func GetCompanyViewEmailTotalList(date string) (items []*CompanyViewTotalSlice, err error) {
  65. o := orm.NewOrm()
  66. sql := `SELECT sum(a.view_num) total,a.date,b.company_id FROM user_view_statistics a join wx_user b on a.email=b.email
  67. WHERE a.email != "" and b.email != "" and a.date = ? group by company_id`
  68. _, err = o.Raw(sql, date).QueryRows(&items)
  69. return
  70. }