package models

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

type CygxMicroRoadshowVideoHistory struct {
	Id               int       `orm:"column(id);pk"description:"微路演视频浏览记录表id"`
	VideoId          int       `description:"微路演视频id"`
	UserId           int       `description:"用户id"`
	Mobile           string    `description:"手机号"`
	Email            string    `description:"邮箱"`
	CompanyId        int       `description:"公司Id"`
	CompanyName      string    `description:"公司名称"`
	RealName         string    `description:"用户实际名称"`
	SellerName       string    `description:"所属销售"`
	PlaySeconds      string    `description:"播放时间 单位s"`
	CreateTime       time.Time `description:"视频创建时间"`
	ModifyTime       time.Time `description:"视频修改时间"`
	RegisterPlatform int       `description:"来源 1小程序，2：网页"`
}

// 获取列表信息根据手机号分组
func GetMicroRoadshowVideoHistoryByMobileList(condition string) (items []*CygxMicroRoadshowVideoHistory, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM cygx_micro_roadshow_video_history  WHERE 1 =1  ` + condition + `  GROUP BY user_id  `
	_, err = o.Raw(sql).QueryRows(&items)
	return
}

// 修改用户浏览产业视频的相关信息
func UpdateCygxMicroRoadshowVideoHistory(wxUser *WxUserItem) (err error) {
	o := orm.NewOrm()
	var sql string
	if wxUser.Mobile != "" {
		sql = `UPDATE cygx_micro_roadshow_video_history SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
		_, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
	} else if wxUser.Email != "" {
		sql = `UPDATE cygx_micro_roadshow_video_history SET mobile=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE email=? `
		_, err = o.Raw(sql, wxUser.Mobile, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Email).Exec()
	}
	return
}
