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.
74 lines
2.5 KiB
74 lines
2.5 KiB
package goods
|
|
|
|
import (
|
|
"github.com/golangkit/formatime"
|
|
"github.com/jinzhu/gorm"
|
|
"recook/internal/v2/lib/db"
|
|
)
|
|
|
|
type RecookGoodsBrandModel struct {
|
|
db.BaseModel
|
|
Id uint `gorm:"column:id;primary_key" json:"id"`
|
|
Name string `gorm:"column:name" json:"name"`
|
|
LogoUrl string `gorm:"logo_url" json:"logoUrl"`
|
|
IsShow int `gorm:"is_show" json:"isShow"`
|
|
GoodsCount int `gorm:"goods_count" json:"goodsCount"`
|
|
CreatedAt formatime.Second `gorm:"column:created_at" json:"createAt"`
|
|
}
|
|
|
|
// TableName sets the insert table name for this struct type
|
|
func (r *RecookGoodsBrandModel) TableName() string {
|
|
return "recook_goods_brand"
|
|
}
|
|
|
|
// @Style 添加
|
|
func (r *RecookGoodsBrandModel) Create(data *RecookGoodsBrandModel) {
|
|
r.GetDb().Create(data)
|
|
}
|
|
|
|
// @Style 获取列表
|
|
func (r *RecookGoodsBrandModel) GetLists(start, limit int, query interface{}, args ...interface{}) (result []RecookGoodsBrandModel) {
|
|
r.GetDb().Model(&RecookGoodsBrandModel{}).Where(query, args...).Offset(start).Limit(limit).Find(&result)
|
|
return
|
|
}
|
|
|
|
// @Style 获取总数
|
|
func (r *RecookGoodsBrandModel) GetListsTotal(query interface{}, args ...interface{}) (result int) {
|
|
r.GetDb().Model(&RecookGoodsBrandModel{}).Where(query, args...).Count(&result)
|
|
return
|
|
}
|
|
|
|
// @Style 获取列表
|
|
func (r *RecookGoodsBrandModel) GetAll(query interface{}, args ...interface{}) (result []RecookGoodsBrandModel) {
|
|
r.GetDb().Model(&RecookGoodsBrandModel{}).Where(query, args...).Find(&result)
|
|
return
|
|
}
|
|
|
|
// @Style 获取数据
|
|
func (r *RecookGoodsBrandModel) FindById(id uint) (result RecookGoodsBrandModel) {
|
|
r.GetDb().Model(&RecookGoodsBrandModel{}).First(&result, "id = ?", id)
|
|
return
|
|
}
|
|
|
|
// @Style 获取数据
|
|
func (r *RecookGoodsBrandModel) FindByIds(ids []uint) (result []RecookGoodsBrandModel) {
|
|
r.GetDb().Model(&RecookGoodsBrandModel{}).Find(&result, "id in (?)", ids)
|
|
return
|
|
}
|
|
|
|
// @Style 获取数据
|
|
func (r *RecookGoodsBrandModel) FindByName(name string) (result RecookGoodsBrandModel) {
|
|
r.GetDb().Model(&RecookGoodsBrandModel{}).First(&result, "name = ?", name)
|
|
return
|
|
}
|
|
|
|
// @Style 修改数据
|
|
func (r *RecookGoodsBrandModel) UpdateById(id uint, data *RecookGoodsBrandModel) int64 {
|
|
return r.GetDb().Model(&RecookGoodsBrandModel{}).Where("id = ?", id).Update(data).RowsAffected
|
|
}
|
|
|
|
// @Style 新增商品
|
|
func (r *RecookGoodsBrandModel) AddGoodsCount(brandId uint) int64 {
|
|
return r.GetDb().Model(&RecookGoodsBrandModel{}).Where("id = ?", brandId).Update("goods_count", gorm.Expr("goods_count + 1")).RowsAffected
|
|
}
|