package models

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
)

type CygxResearchSummaryVoiceHistory struct {
	Id          int       `orm:"column(id);pk"`
	ArticleId  int       `description:"文章ID"`
	UserId      int       `description:"用户ID"`
	CreateTime  time.Time `description:"创建时间"`
	Mobile      string    `description:"手机号"`
	Email       string    `description:"邮箱"`
	CompanyId   int       `description:"公司id"`
	CompanyName string    `description:"公司名称"`
	RealName    string    `description:"用户实际名称"`
	SellerName      string    `description:"所属销售"`
	PlaySeconds     string    `description:"播放时间 单位s"`
	ModifyTime      time.Time `description:"视频修改时间"`
}

//添加
func AddCygxResearchSummaryVoiceHistory(item *CygxResearchSummaryVoiceHistory) (err error) {
	o := orm.NewOrm()
	_, err = o.Insert(item)
	return
}

func GetLastCygxResearchSummaryVoiceHistory(articleId, userId int) (item *CygxResearchSummaryVoiceHistory, err error) {
	o := orm.NewOrm()
	sql := ` SELECT * FROM cygx_research_summary_voice_history WHERE article_id=? AND user_id=? ORDER BY create_time DESC limit 1 `
	err = o.Raw(sql, articleId, userId).QueryRow(&item)
	return
}

func UpdateLastCygxResearchSummaryVoiceHistory(playSeconds string, lastId int) (err error) {
	o := orm.NewOrm()
	sql := ` UPDATE cygx_research_summary_voice_history SET play_seconds =? WHERE id=? `
	_, err = o.Raw(sql, playSeconds, lastId).Exec()
	return
}

