package models

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

type CygxYanxuanSpecialCollect struct {
	CygxYanxuanSpecialCollectId int       `orm:"column(cygx_yanxuan_special_collect_id);pk"`
	UserId                      int       // 用户ID
	Mobile                      string    // 手机号
	Email                       string    // 邮箱
	CompanyId                   int       // 公司ID
	CompanyName                 string    // 公司名称
	RealName                    string    // 用户实际名称
	SellerName                  string    // 所属销售
	CreateTime                  time.Time // 创建时间
	ModifyTime                  time.Time // 修改时间
	RegisterPlatform            int       // 来源 1小程序，2：网页
	YanxuanSpecialId            int       // cygx_yanxuan_special 表主键ID
}

func AddCygxYanxuanSpecialCollect(item *CygxYanxuanSpecialCollect) (lastId int64, err error) {
	o := orm.NewOrm()
	lastId, err = o.Insert(item)
	return
}

type CollectCygxYanxuanSpecialReq struct {
	Id     int // 文章id
	Status int // 1收藏2取消收藏
}

func DelCygxYanxuanSpecialCollect(userId, articleId int) (err error) {
	o := orm.NewOrm()
	sql := `DELETE FROM cygx_yanxuan_special_collect WHERE user_id=? AND yanxuan_special_id=? `
	_, err = o.Raw(sql, userId, articleId).Exec()
	return
}

// 获取数量
func GetCygxYanxuanSpecialCollectCount(condition string, pars []interface{}) (count int, err error) {
	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_yanxuan_special_collect as a  WHERE 1= 1  `
	if condition != "" {
		sqlCount += condition
	}
	o := orm.NewOrm()
	err = o.Raw(sqlCount, pars).QueryRow(&count)
	return
}

// GetCygxYanxuanSpecialCollectByUser 根据用户ID获取所有文章收藏
func GetCygxYanxuanSpecialCollectByUser(userId int) (items []*CygxYanxuanSpecialCollect, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM cygx_yanxuan_special_collect  WHERE 1 =1  AND  user_id =?  `
	_, err = o.Raw(sql, userId).QueryRows(&items)
	return
}
