article_history_record.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. Source string `description:"来源,MOBILE:手机端,PC:电脑端"`
  66. }
  67. type AddStopTimeHtgjRep struct {
  68. ArticleId int `description:"文章ID"`
  69. StopTime int `description:"停留时间"`
  70. OutType int `description:"退出方式,1正常退出,2强制关闭"`
  71. Source string `description:"来源,MOBILE:手机端,PC:电脑端"`
  72. CompanyCode string `description:"机构编码"`
  73. CompanyName string `description:"机构名称"`
  74. Email string `description:"机构邮箱"`
  75. Sign string `description:"签名"`
  76. }
  77. type AddStopTimeNewRep struct {
  78. Id int `description:"ID"`
  79. ArticleId int `description:"文章ID"`
  80. StopTime int `description:"停留时间"`
  81. OutType int `description:"退出方式,1正常退出,2强制关闭"`
  82. }
  83. type ArticleDetailAddStopTimeRep struct {
  84. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  85. HasFree int `description:"1:已付费(至少包含一个品类的权限),2:未付费(没有任何品类权限)"`
  86. }
  87. func UpdateArticleStopTime(item *AddStopTimeNewRep) (err error) {
  88. o := orm.NewOrm()
  89. sql := `UPDATE cygx_article_history_record SET stop_time = ?,out_type = ? WHERE id =?`
  90. _, err = o.Raw(sql, item.StopTime, item.OutType, item.Id).Exec()
  91. return
  92. }
  93. //获取最新的一条阅读记录
  94. func GetNewArticleHistoryRecord(uid, articleId int) (item *AddStopTimeNewRep, err error) {
  95. o := orm.NewOrm()
  96. sql := `SELECT * FROM cygx_article_history_record WHERE user_id = ? AND article_id = ? ORDER BY id DESC LIMIT 1;`
  97. err = o.Raw(sql, uid, articleId).QueryRow(&item)
  98. return
  99. }
  100. //获取用户阅读记录
  101. func GetNoAddStoptimeArticleCount(uid, articleId int) (count int, err error) {
  102. 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 `
  103. o := orm.NewOrm()
  104. err = o.Raw(sqlCount, uid, articleId).QueryRow(&count)
  105. return
  106. }
  107. //最新标的列表
  108. func GetArticleHistoryList() (items []*CygxArticleHistoryRecordNewpv, err error) {
  109. o := orm.NewOrm()
  110. sql := `SELECT * FROM cygx_article_history_record WHERE company_id != 16 `
  111. _, err = o.Raw(sql).QueryRows(&items)
  112. return
  113. }