package yb

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

// VarietyClassify 标签库分类表
type PriceDrivenTag struct {
	Id             int       `orm:"column(id);pk" `
	VarietyTagId   int       `json:"variety_tag_id" description:"标签ID"`
	VarietyTagName string    `json:"variety_tag_name" description:"标签名称"`
	State          int       `json:"state" description:"显示状态 0-禁用 1-启用"`
	CreateTime     time.Time `json:"create_time" description:"创建时间"`
	ModifyTime     time.Time `json:"modify_time" description:"更新时间"`
}

// TableName 表名变更
func (priceDrivenTag *PriceDrivenTag) TableName() string {
	return "yb_price_driven_tag"
}

// Add 新增
func (priceDrivenTag *PriceDrivenTag) Add() (lastId int64, err error) {
	o := orm.NewOrm()
	lastId, err = o.Insert(priceDrivenTag)
	if err != nil {
		return
	}
	priceDrivenTag.Id = int(lastId)
	return
}

// Update 更新
func (priceDrivenTag *PriceDrivenTag) Update(cols []string) (err error) {
	o := orm.NewOrm()
	_, err = o.Update(priceDrivenTag, cols...)
	return
}

// GetPriceDrivenTagList 获取价格驱动标签列表
func GetPriceDrivenTagList() (list []*PriceDrivenTag, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM yb_price_driven_tag`
	_, err = o.Raw(sql).QueryRows(&list)
	return
}

// GetPriceDrivenTagByTagId 通过标签ID获取价格驱动标签
func GetPriceDrivenTagByTagId(tagId int) (item *PriceDrivenTag, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM yb_price_driven_tag WHERE variety_tag_id = ? LIMIT 1`
	err = o.Raw(sql, tagId).QueryRow(&item)
	return
}
