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.
43 lines
1.2 KiB
43 lines
1.2 KiB
package goods
|
|
|
|
import (
|
|
"recook/internal/v2/lib/db"
|
|
)
|
|
|
|
type RecookGoodsAttributeModel struct {
|
|
db.BaseModel
|
|
Id uint `gorm:"column:id;primary_key" json:"id"`
|
|
GoodsId uint `gorm:"column:goods_id" json:"-"`
|
|
Name string `gorm:"column:name" json:"name"`
|
|
Value string `gorm:"column:value" json:"value"`
|
|
}
|
|
|
|
// TableName sets the insert table name for this struct type
|
|
func (r *RecookGoodsAttributeModel) TableName() string {
|
|
return "recook_goods_attribute"
|
|
}
|
|
|
|
// @Style 添加
|
|
func (r *RecookGoodsAttributeModel) Create(data *RecookGoodsAttributeModel) {
|
|
r.GetDb().Create(data)
|
|
}
|
|
|
|
// @Style 批量添加
|
|
func (r *RecookGoodsAttributeModel) CreateAll(datas *[]RecookGoodsAttributeModel) int64 {
|
|
valueStr := ""
|
|
values := []interface{}{}
|
|
for _, item := range *datas {
|
|
valueStr += ",(?,?,?)"
|
|
values = append(values, item.GoodsId, item.Name, item.Value)
|
|
}
|
|
if len(values) > 0 {
|
|
return r.GetDb().Exec("insert into recook_goods_attribute(goods_id,name,value) values "+valueStr[1:], values...).RowsAffected
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// @Style 添加
|
|
func (r *RecookGoodsAttributeModel) DeleteByGoodsId(goodsId uint) {
|
|
r.GetDb().Delete(&RecookGoodsAttributeModel{}, "goods_id = ?", goodsId)
|
|
}
|