article_history_record_newpv.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package models
  2. import (
  3. "rdluck_tools/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. }
  20. //添加收藏信息
  21. func AddCygxArticleViewRecordNewpv(item *CygxArticleHistoryRecordNewpv) (lastId int64, err error) {
  22. o := orm.NewOrm()
  23. lastId, err = o.Insert(item)
  24. return
  25. }
  26. //获取最新的一条阅读记录
  27. func GetNewArticleHistoryRecordNewpv(uid, articleId int, modifytime string) (item *AddStopTimeNewRep, err error) {
  28. o := orm.NewOrm()
  29. sql := `SELECT * FROM cygx_article_history_record_newpv WHERE user_id = ? AND article_id = ? AND modify_time <='` + modifytime + `' ORDER BY id DESC LIMIT 1;`
  30. err = o.Raw(sql, uid, articleId).QueryRow(&item)
  31. return
  32. }
  33. //把十分钟之内的阅读记录进行累加
  34. func UpdateCygxArticleViewRecordNewpv(itemRep *CygxArticleHistoryRecordNewpv, stopTime int) (err error) {
  35. o := orm.NewOrm()
  36. sql := `UPDATE cygx_article_history_record_newpv
  37. SET stop_time = stop_time + ` + strconv.Itoa(stopTime) + `
  38. WHERE
  39. article_id = ?
  40. AND user_id = ?
  41. AND modify_time = ?
  42. AND timestampdiff(MINUTE,modify_time,NOW()) < 10`
  43. _, err = o.Raw(sql, itemRep.ArticleId, itemRep.UserId, itemRep.ModifyTime).Exec()
  44. return
  45. }
  46. //把十分钟之内的阅读记录进行累加
  47. func UpdateCygxArticleViewRecordNewpvList(itemRep *CygxArticleHistoryRecordNewpv, stopTime int) (err error) {
  48. o := orm.NewOrm()
  49. sql := `UPDATE cygx_article_history_record_newpv
  50. SET stop_time = stop_time + ` + strconv.Itoa(stopTime) + `
  51. WHERE
  52. article_id = ?
  53. AND user_id = ?
  54. AND modify_time = ?
  55. AND id = ?`
  56. _, err = o.Raw(sql, itemRep.ArticleId, itemRep.UserId, itemRep.ModifyTime, itemRep.Id).Exec()
  57. return
  58. }