article_history_record_newpv.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 out_type = 2
  43. AND timestampdiff(MINUTE,modify_time,NOW()) < 10`
  44. _, err = o.Raw(sql, itemRep.ArticleId, itemRep.UserId, itemRep.ModifyTime).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. }