article_history_record_newpv.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "strconv"
  5. "time"
  6. )
  7. type CygxArticleHistoryRecordNewpv struct {
  8. Id int `orm:"column(id);pk"`
  9. ArticleId int
  10. UserId int
  11. CreateTime time.Time
  12. ModifyTime time.Time
  13. Mobile string `description:"手机号"`
  14. Email string `description:"邮箱"`
  15. CompanyId int `description:"公司id"`
  16. CompanyName string `description:"公司名称"`
  17. StopTime int `description:"停留时间"`
  18. OutType int `description:"退出方式,1正常退出,2强制关闭"`
  19. Source string `description:"来源,MOBILE:手机端,PC:电脑端"`
  20. }
  21. //添加收藏信息
  22. func AddCygxArticleViewRecordNewpv(item *CygxArticleHistoryRecordNewpv) (lastId int64, err error) {
  23. o := orm.NewOrm()
  24. lastId, err = o.Insert(item)
  25. return
  26. }
  27. //获取最新的一条阅读记录
  28. func GetNewArticleHistoryRecordNewpv(uid, articleId int, modifytime string) (item *AddStopTimeNewRep, err error) {
  29. o := orm.NewOrm()
  30. sql := `SELECT * FROM cygx_article_history_record_newpv WHERE user_id = ? AND article_id = ? AND modify_time <='` + modifytime + `' ORDER BY id DESC LIMIT 1;`
  31. err = o.Raw(sql, uid, articleId).QueryRow(&item)
  32. return
  33. }
  34. //把十分钟之内的阅读记录进行累加
  35. func UpdateCygxArticleViewRecordNewpv(itemRep *CygxArticleHistoryRecordNewpv, stopTime int) (err error) {
  36. o := orm.NewOrm()
  37. sql := `UPDATE cygx_article_history_record_newpv
  38. SET modify_time = NOW(), stop_time = stop_time + ` + strconv.Itoa(stopTime) + `
  39. WHERE
  40. article_id = ?
  41. AND user_id = ?
  42. AND out_type = 2
  43. AND timestampdiff(MINUTE,modify_time,NOW()) < 10`
  44. _, err = o.Raw(sql, itemRep.ArticleId, itemRep.UserId).Exec()
  45. return
  46. }
  47. //把十分钟之内的阅读记录进行累加
  48. func UpdateCygxArticleViewRecordNewpvList(itemRep *CygxArticleHistoryRecordNewpv, stopTime int) (err error) {
  49. o := orm.NewOrm()
  50. sql := `UPDATE cygx_article_history_record_newpv
  51. SET stop_time = stop_time + ` + strconv.Itoa(stopTime) + `
  52. WHERE
  53. article_id = ?
  54. AND user_id = ?
  55. AND modify_time = ?
  56. AND id = ?`
  57. _, err = o.Raw(sql, itemRep.ArticleId, itemRep.UserId, itemRep.ModifyTime, itemRep.Id).Exec()
  58. return
  59. }