article_history_record.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hongze_cygx/utils"
  6. "time"
  7. )
  8. type CygxArticleHistoryRecord struct {
  9. Id int `orm:"column(id);pk"`
  10. ArticleId int
  11. UserId int
  12. CreateTime time.Time
  13. Mobile string `description:"手机号"`
  14. Email string `description:"邮箱"`
  15. CompanyId int `description:"公司id"`
  16. CompanyName string `description:"公司名称"`
  17. ModifyTime time.Time `description:"修改时间"`
  18. StopTime int `description:"停留时间"`
  19. OutType int `description:"退出方式,1正常退出,2强制关闭"`
  20. }
  21. //添加历史信息
  22. func AddCygxArticleHistoryRecord(item *CygxArticleHistoryRecord) (lastId int64, err error) {
  23. o, err := orm.NewOrm().Begin()
  24. if err != nil {
  25. return
  26. }
  27. defer func() {
  28. fmt.Println(err)
  29. if err == nil {
  30. o.Commit()
  31. } else {
  32. o.Rollback()
  33. }
  34. }()
  35. //var count int
  36. //sql := `SELECT COUNT(1) AS count FROM cygx_article_history_record WHERE user_id=? AND article_id=? `
  37. //err = o.Raw(sql, item.UserId, item.ArticleId).QueryRow(&count)
  38. sql := `UPDATE wx_user SET report_last_view_time=NOW() WHERE user_id=?`
  39. _, err = o.Raw(sql, item.UserId).Exec()
  40. if err != nil {
  41. return
  42. }
  43. //if count > 0 {
  44. // sql := `UPDATE cygx_article_history_record SET modify_time=NOW() WHERE user_id=? AND article_id=? `
  45. // _, err = o.Raw(sql, item.UserId, item.ArticleId).Exec()
  46. //} else {
  47. // item.ModifyTime = time.Now()
  48. // lastId, err = o.Insert(item)
  49. //}
  50. item.ModifyTime = time.Now()
  51. lastId, err = o.Insert(item)
  52. return
  53. }
  54. //获取用户阅读记录
  55. func GetUserToArticleCount(uid, articleId int) (count int, err error) {
  56. sqlCount := `SELECT COUNT(1) AS count FROM cygx_article_history_record WHERE user_id=? AND article_id=? `
  57. o := orm.NewOrm()
  58. err = o.Raw(sqlCount, uid, articleId).QueryRow(&count)
  59. return
  60. }
  61. type AddStopTimeRep struct {
  62. ArticleId int `description:"文章ID"`
  63. StopTime int `description:"停留时间"`
  64. OutType int `description:"退出方式,1正常退出,2强制关闭"`
  65. }
  66. type AddStopTimeNewRep struct {
  67. Id int `description:"ID"`
  68. ArticleId int `description:"文章ID"`
  69. StopTime int `description:"停留时间"`
  70. OutType int `description:"退出方式,1正常退出,2强制关闭"`
  71. }
  72. type ArticleDetailAddStopTimeRep struct {
  73. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  74. HasFree int `description:"1:已付费(至少包含一个品类的权限),2:未付费(没有任何品类权限)"`
  75. }
  76. func UpdateArticleStopTime(item *AddStopTimeNewRep) (err error) {
  77. o := orm.NewOrm()
  78. sql := `UPDATE cygx_article_history_record SET stop_time = ?,out_type = ? WHERE id =?`
  79. _, err = o.Raw(sql, item.StopTime, item.OutType, item.Id).Exec()
  80. return
  81. }
  82. //获取最新的一条阅读记录
  83. func GetNewArticleHistoryRecord(uid, articleId int) (item *AddStopTimeNewRep, err error) {
  84. o := orm.NewOrm()
  85. sql := `SELECT * FROM cygx_article_history_record WHERE user_id = ? AND article_id = ? ORDER BY id DESC LIMIT 1;`
  86. err = o.Raw(sql, uid, articleId).QueryRow(&item)
  87. return
  88. }
  89. //获取用户阅读记录
  90. func GetNoAddStoptimeArticleCount(uid, articleId int) (count int, err error) {
  91. sqlCount := `SELECT COUNT(1) AS count FROM cygx_article_history_record WHERE user_id=? AND article_id=? AND create_time > '` + utils.OnlineTime + `' AND stop_time = 0 `
  92. //sqlCount := `SELECT COUNT(1) AS count FROM cygx_article_history_record WHERE id = ? AND stop_time = 0 `
  93. o := orm.NewOrm()
  94. err = o.Raw(sqlCount, uid, articleId).QueryRow(&count)
  95. return
  96. }
  97. //最新标的列表
  98. func GetArticleHistoryList() (items []*CygxArticleHistoryRecordNewpv, err error) {
  99. o := orm.NewOrm()
  100. sql := `SELECT * FROM cygx_article_history_record WHERE company_id != 16 `
  101. _, err = o.Raw(sql).QueryRows(&items)
  102. return
  103. }