package models

import (
	"rdluck_tools/orm"
	"time"
)

type EdbdataClassify struct {
	ClassifyId   int `orm:"column(classify_id);pk"`
	ClassifyName string
	ParentId     int
	CreateTime   time.Time
	Sort         int
}

func GetEdbdataClassifyByClassifyName(classifyName string) (item *EdbdataClassify, err error) {
	sql := `SELECT * FROM edbdata_classify WHERE classify_name=? `
	o := orm.NewOrm()
	o.Using("edb")
	err = o.Raw(sql, classifyName).QueryRow(&item)
	return
}

func AddEdbdataClassify(item *EdbdataClassify) (newId int64, err error) {
	o := orm.NewOrm()
	o.Using("edb")
	newId, err = o.Insert(item)
	return
}

func GetEdbdataClassifyByParentId(parentId int) (items []*EdbdataClassify, err error) {
	sql := ` SELECT * FROM edbdata_classify WHERE parent_id=? `
	o := orm.NewOrm()
	o.Using("edb")
	o.Raw(sql, parentId).QueryRows(&items)
	return
}

type LzPriceClassify struct {
	ProductName string
}

func GetLzPriceClassify() (items []*LzPriceClassify, err error) {
	sql := ` SELECT product_name  FROM longzhongpriceinfo GROUP BY product_name ORDER BY product_name DESC `
	o := orm.NewOrm()
	o.Using("edb")
	o.Raw(sql).QueryRows(&items)
	return
}