report_history_record.go 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxReportHistoryRecord struct {
  7. Id int `orm:"column(id);pk"`
  8. ArticleId int
  9. UserId int
  10. CreateTime time.Time
  11. Mobile string `description:"手机号"`
  12. Email string `description:"邮箱"`
  13. CompanyId int `description:"公司id"`
  14. CompanyName string `description:"公司名称"`
  15. ModifyTime time.Time `description:"修改时间"`
  16. ReportType string `description:"报告类型,bgjx:报告精选、bzyjhz:本周研究汇总、szjyhz:上周纪要汇总"`
  17. RealName string `description:"用户实际名称"`
  18. SellerName string `description:"所属销售"`
  19. StopTime int `description:"停留时间"`
  20. OutType int `description:"退出方式,1正常退出,2强制关闭"`
  21. RegisterPlatform int `description:"来源 1小程序,2:网页"`
  22. }
  23. type CygxReportHistoryRecordLog struct {
  24. Id int `orm:"column(id);pk"`
  25. ArticleId int
  26. UserId int
  27. CreateTime time.Time
  28. Mobile string `description:"手机号"`
  29. Email string `description:"邮箱"`
  30. CompanyId int `description:"公司id"`
  31. CompanyName string `description:"公司名称"`
  32. ModifyTime time.Time `description:"修改时间"`
  33. ReportType string `description:"报告类型,bgjx:报告精选、bzyjhz:本周研究汇总、szjyhz:上周纪要汇总"`
  34. RealName string `description:"用户实际名称"`
  35. SellerName string `description:"所属销售"`
  36. StopTime int `description:"停留时间"`
  37. OutType int `description:"退出方式,1正常退出,2强制关闭"`
  38. RegisterPlatform int `description:"来源 1小程序,2:网页"`
  39. }
  40. // 添加历史信息
  41. func AddCygxReportHistoryRecord(item *CygxReportHistoryRecord) (lastId int64, err error) {
  42. o := orm.NewOrm()
  43. item.ModifyTime = time.Now()
  44. lastId, err = o.Insert(item)
  45. return
  46. }
  47. // 添加历史信息
  48. func AddCygxReportHistoryRecordLog(item *CygxReportHistoryRecordLog) (lastId int64, err error) {
  49. o := orm.NewOrm()
  50. item.ModifyTime = time.Now()
  51. lastId, err = o.Insert(item)
  52. return
  53. }
  54. type AddStopTimeNewRep struct {
  55. Id int `description:"ID"`
  56. ArticleId int `description:"文章ID"`
  57. StopTime int `description:"停留时间"`
  58. OutType int `description:"退出方式,1正常退出,2强制关闭"`
  59. }
  60. func UpdateArticleStopTime(item *AddStopTimeNewRep) (err error) {
  61. o := orm.NewOrm()
  62. sql := `UPDATE cygx_article_history_record SET stop_time = ?,out_type = ? WHERE id =?`
  63. _, err = o.Raw(sql, item.StopTime, item.OutType, item.Id).Exec()
  64. return
  65. }
  66. // 获取最新的一条阅读记录
  67. func GetNewArticleHistoryRecord(uid, articleId int) (item *AddStopTimeNewRep, err error) {
  68. o := orm.NewOrm()
  69. sql := `SELECT * FROM cygx_article_history_record WHERE user_id = ? AND article_id = ? ORDER BY id DESC LIMIT 1;`
  70. err = o.Raw(sql, uid, articleId).QueryRow(&item)
  71. return
  72. }
  73. type ListPvResp struct {
  74. ArticleId int `description:"文章ID"`
  75. Pv int `description:"pv"`
  76. }
  77. // 列表
  78. func GetCygxReportHistoryRecordListPv(condition string, pars []interface{}) (items []*ListPvResp, err error) {
  79. o := orm.NewOrm()
  80. sql := `SELECT article_id ,COUNT(*) as pv FROM cygx_report_history_record WHERE 1= 1 `
  81. if condition != "" {
  82. sql += condition
  83. }
  84. sql += " GROUP BY article_id "
  85. _, err = o.Raw(sql, pars).QueryRows(&items)
  86. return
  87. }