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.1 KiB

package goods
import (
"recook/internal/v2/lib/db"
)
type RecookGoodsNoticeGoodsModel struct {
db.BaseModel
Id uint `gorm:"column:id;primary_key" json:"id"`
NoticeId uint `json:"noticeId"`
GoodsId uint `json:"goodsId"`
}
// TableName sets the insert table name for this struct type
func (r *RecookGoodsNoticeGoodsModel) TableName() string {
return "recook_goods_notice_goods"
}
// @Style 添加
func (r *RecookGoodsNoticeGoodsModel) Create(data *RecookGoodsNoticeGoodsModel) {
r.GetDb().Create(data)
}
// @Style 批量添加
func (r *RecookGoodsNoticeGoodsModel) CreateAll(datas *[]RecookGoodsNoticeGoodsModel) int64 {
valueStr := ""
values := []interface{}{}
for _, item := range *datas {
valueStr += ",(?,?)"
values = append(values,
item.NoticeId,
item.GoodsId,
)
}
if len(values) > 0 {
return r.GetDb().Exec("insert into recook_goods_notice_goods(notice_id, goods_id) values "+valueStr[1:], values...).RowsAffected
}
return 0
}
// @Style 获取数据
func (r *RecookGoodsNoticeGoodsModel) FindByNoticeId(noticeId uint) (result []RecookGoodsNoticeGoodsModel) {
r.GetDb().Model(&RecookGoodsNoticeGoodsModel{}).Find(&result, "notice_id = ?", noticeId)
return
}
// @Style 获取数据
func (r *RecookGoodsNoticeGoodsModel) FindByGoodsId(goodsId uint) (result RecookGoodsNoticeGoodsModel) {
r.GetDb().Model(&RecookGoodsNoticeGoodsModel{}).First(&result, "goods_id = ?", goodsId)
return
}
// @Style 删除数据
func (r *RecookGoodsNoticeGoodsModel) DeleteByGoodsId(goodsId uint) error {
return r.GetDb().Delete(&RecookGoodsNoticeGoodsModel{}, "goods_id = ?", goodsId).Error
}
// @Style 删除数据
func (r *RecookGoodsNoticeGoodsModel) DeleteByNoticeId(noticeId uint) error {
return r.GetDb().Delete(&RecookGoodsNoticeGoodsModel{}, "notice_id = ?", noticeId).Error
}
//商详关联图片
type RecookGoodsNoticeImageModel struct {
Id uint `gorm:"column:id" json:"id"`
NoticeId uint `gorm:"column:noticeId" json:"noticeId"`
Image string `gorm:"column:image"`
}
// TableName sets the insert table name for this struct type
func (r *RecookGoodsNoticeImageModel) TableName() string {
return "recook_goods_notice_image"
}