You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.4 KiB

package goods
import (
"recook/internal/v2/lib/db"
)
const (
RecookGoodsCategoryShowNo = 0
RecookGoodsCategoryShowYes = 1
)
type RecookGoodsCategoryModel struct {
db.BaseModel
Id uint `gorm:"column:id;primary_key" json:"id"`
Name string `gorm:"column:name" json:"name"`
ParentId uint `gorm:"column:parent_id" json:"parentId"`
Depth uint `gorm:"column:depth" json:"depth"`
LogoURL string `gorm:"column:logo_url" json:"logoUrl"`
Location uint `gorm:"column:location" json:"location"`
Show uint `gorm:"column:show" json:"show"`
GysShow uint `gorm:"column:gys_show" json:"gysShow"`
IsAllow bool `gorm:"column:is_allow" json:"is_allow"`
}
// TableName sets the insert table name for this struct type
func (r *RecookGoodsCategoryModel) TableName() string {
return "recook_goods_category"
}
// @Style 获取层级数据
func (r *RecookGoodsCategoryModel) GetLevelList(level int) (result []RecookGoodsCategoryModel) {
r.GetDb().Model(&RecookGoodsCategoryModel{}).Order("location asc").Find(&result, "depth = ? and gys_show = ?", level, RecookGoodsCategoryShowYes)
return
}
// @Style 获取层级数据
func (r *RecookGoodsCategoryModel) GetByIds(ids []uint) (result []RecookGoodsCategoryModel) {
r.GetDb().Model(&RecookGoodsCategoryModel{}).Order("location asc").Find(&result, "id in (?)", ids)
return
}
// @Style 获取层级数据
func (r *RecookGoodsCategoryModel) GetAll() (result []RecookGoodsCategoryModel) {
r.GetDb().Model(&RecookGoodsCategoryModel{}).Order("location asc").Find(&result)
return
}
// @Style 获取层级数据
func (r *RecookGoodsCategoryModel) GetByParentIds(ids []uint) (result []RecookGoodsCategoryModel) {
r.GetDb().Model(&RecookGoodsCategoryModel{}).Order("location asc").Find(&result, "parent_id in (?) and `gys_show` = ?", ids, RecookGoodsCategoryShowYes)
return
}
// @Style 获取层级数据
func (r *RecookGoodsCategoryModel) FindById(id uint) (result RecookGoodsCategoryModel) {
r.GetDb().First(&result, "id = ?", id)
return
}
// @Style 获取层级数据
func (r *RecookGoodsCategoryModel) FindByIds(ids []uint) (result []RecookGoodsCategoryModel) {
r.GetDb().Model(RecookGoodsCategoryModel{}).Find(&result, "id in (?)", ids)
return
}
// @Style 获取层级数据
func (r *RecookGoodsCategoryModel) GetWhere(query interface{}, args ...interface{}) (result []RecookGoodsCategoryModel) {
r.GetDb().Model(&RecookGoodsCategoryModel{}).Where(query, args...).Order("location asc").Find(&result)
return
}