package models import ( "github.com/beego/beego/v2/client/orm" "strconv" "time" ) type CygxArticleHistoryRecordNewpv struct { Id int `orm:"column(id);pk"` ArticleId int UserId int CreateTime time.Time ModifyTime time.Time Mobile string `description:"手机号"` Email string `description:"邮箱"` CompanyId int `description:"公司id"` CompanyName string `description:"公司名称"` StopTime int `description:"停留时间"` OutType int `description:"退出方式,1正常退出,2强制关闭"` Source string `description:"来源,MOBILE:手机端,PC:电脑端"` } //添加收藏信息 func AddCygxArticleViewRecordNewpv(item *CygxArticleHistoryRecordNewpv) (lastId int64, err error) { o := orm.NewOrm() lastId, err = o.Insert(item) return } //获取最新的一条阅读记录 func GetNewArticleHistoryRecordNewpv(uid, articleId int, modifytime string) (item *AddStopTimeNewRep, err error) { o := orm.NewOrm() sql := `SELECT * FROM cygx_article_history_record_newpv WHERE user_id = ? AND article_id = ? AND modify_time <='` + modifytime + `' ORDER BY id DESC LIMIT 1;` err = o.Raw(sql, uid, articleId).QueryRow(&item) return } //把十分钟之内的阅读记录进行累加 func UpdateCygxArticleViewRecordNewpv(itemRep *CygxArticleHistoryRecordNewpv, stopTime int) (err error) { o := orm.NewOrm() sql := `UPDATE cygx_article_history_record_newpv SET modify_time = NOW(), stop_time = stop_time + ` + strconv.Itoa(stopTime) + ` WHERE article_id = ? AND user_id = ? AND out_type = 2 AND timestampdiff(MINUTE,modify_time,NOW()) < 10` _, err = o.Raw(sql, itemRep.ArticleId, itemRep.UserId).Exec() return } //把十分钟之内的阅读记录进行累加 func UpdateCygxArticleViewRecordNewpvList(itemRep *CygxArticleHistoryRecordNewpv, stopTime int) (err error) { o := orm.NewOrm() sql := `UPDATE cygx_article_history_record_newpv SET stop_time = stop_time + ` + strconv.Itoa(stopTime) + ` WHERE article_id = ? AND user_id = ? AND modify_time = ? AND id = ?` _, err = o.Raw(sql, itemRep.ArticleId, itemRep.UserId, itemRep.ModifyTime, itemRep.Id).Exec() return }