article_history_record.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/rdlucklib/rdluck_tools/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 := orm.NewOrm()
  24. o.Begin()
  25. defer func() {
  26. fmt.Println(err)
  27. if err == nil {
  28. o.Commit()
  29. } else {
  30. o.Rollback()
  31. }
  32. }()
  33. //var count int
  34. //sql := `SELECT COUNT(1) AS count FROM cygx_article_history_record WHERE user_id=? AND article_id=? `
  35. //err = o.Raw(sql, item.UserId, item.ArticleId).QueryRow(&count)
  36. sql := `UPDATE wx_user SET report_last_view_time=NOW() WHERE user_id=?`
  37. _, err = o.Raw(sql, item.UserId).Exec()
  38. if err != nil {
  39. return
  40. }
  41. //if count > 0 {
  42. // sql := `UPDATE cygx_article_history_record SET modify_time=NOW() WHERE user_id=? AND article_id=? `
  43. // _, err = o.Raw(sql, item.UserId, item.ArticleId).Exec()
  44. //} else {
  45. // item.ModifyTime = time.Now()
  46. // lastId, err = o.Insert(item)
  47. //}
  48. item.ModifyTime = time.Now()
  49. lastId, err = o.Insert(item)
  50. return
  51. }
  52. //获取用户阅读记录
  53. func GetUserToArticleCount(uid, articleId int) (count int, err error) {
  54. sqlCount := `SELECT COUNT(1) AS count FROM cygx_article_history_record WHERE user_id=? AND article_id=? `
  55. o := orm.NewOrm()
  56. err = o.Raw(sqlCount, uid, articleId).QueryRow(&count)
  57. return
  58. }
  59. type AddStopTimeRep struct {
  60. ArticleId int `description:"文章ID"`
  61. StopTime int `description:"停留时间"`
  62. OutType int `description:"退出方式,1正常退出,2强制关闭"`
  63. }
  64. type AddStopTimeNewRep struct {
  65. Id int `description:"ID"`
  66. ArticleId int `description:"文章ID"`
  67. StopTime int `description:"停留时间"`
  68. OutType int `description:"退出方式,1正常退出,2强制关闭"`
  69. }
  70. type ArticleDetailAddStopTimeRep struct {
  71. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  72. HasFree int `description:"1:已付费(至少包含一个品类的权限),2:未付费(没有任何品类权限)"`
  73. }
  74. func UpdateArticleStopTime(item *AddStopTimeNewRep) (err error) {
  75. o := orm.NewOrm()
  76. sql := `UPDATE cygx_article_history_record SET stop_time = ?,out_type = ? WHERE id =?`
  77. _, err = o.Raw(sql, item.StopTime, item.OutType, item.Id).Exec()
  78. return
  79. }
  80. //获取最新的一条阅读记录
  81. func GetNewArticleHistoryRecord(uid, articleId int) (item *AddStopTimeNewRep, err error) {
  82. o := orm.NewOrm()
  83. sql := `SELECT * FROM cygx_article_history_record WHERE user_id = ? AND article_id = ? ORDER BY id DESC LIMIT 1;`
  84. err = o.Raw(sql, uid, articleId).QueryRow(&item)
  85. return
  86. }
  87. //获取用户阅读记录
  88. func GetNoAddStoptimeArticleCount(uid, articleId int) (count int, err error) {
  89. 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 `
  90. //sqlCount := `SELECT COUNT(1) AS count FROM cygx_article_history_record WHERE id = ? AND stop_time = 0 `
  91. o := orm.NewOrm()
  92. err = o.Raw(sqlCount, uid, articleId).QueryRow(&count)
  93. return
  94. }
  95. //最新标的列表
  96. func GetArticleHistoryList() (items []*CygxArticleHistoryRecordNewpv, err error) {
  97. o := orm.NewOrm()
  98. sql := `SELECT * FROM cygx_article_history_record WHERE company_id != 16 `
  99. _, err = o.Raw(sql).QueryRows(&items)
  100. return
  101. }