package models

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

type CygxAskserieVideoCollect struct {
	Id               int       `orm:"column(id);pk"`
	AskserieVideoId  int       `description:"askserie_video_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:"所属销售"`
	RegisterPlatform int       `description:"来源 1小程序，2：网页"`
	ModifyTime       time.Time `description:"更新时间"`
}

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

func RemoveAskserieVideoCollect(userId, askserieVideoId int) (err error) {
	o := orm.NewOrm()
	sql := `DELETE FROM cygx_askserie_video_collect WHERE user_id=? AND askserie_video_id=? `
	_, err = o.Raw(sql, userId, askserieVideoId).Exec()
	return
}

func GetAskserieVideoCount(userId, askserieVideoId int) (count int, err error) {
	sql := `SELECT COUNT(1) AS count FROM cygx_askserie_video_collect WHERE user_id=? AND askserie_video_id=? `
	err = orm.NewOrm().Raw(sql, userId, askserieVideoId).QueryRow(&count)
	return
}

func GetUserCygxAskserieVideoCollectList(userId int) (items []*CygxAskserieVideoCollect, err error) {
	sql := `SELECT a.* FROM cygx_askserie_video_collect AS a 
			WHERE a.user_id=?
           ORDER BY a.id DESC `
	_, err = orm.NewOrm().Raw(sql, userId).QueryRows(&items)
	return
}
