2023-06-12 08:47:48 +00:00
|
|
|
package gmodel
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
type FsCanteenProduct struct {
|
|
|
|
Id int64 `gorm:"primary_key" json:"id"` // ID
|
|
|
|
CanteenType *int64 `gorm:"default:0" json:"canteen_type"` // 餐厅类别id
|
|
|
|
ProductId *int64 `gorm:"default:0" json:"product_id"` // 产品id
|
|
|
|
SizeId *int64 `gorm:"default:0" json:"size_id"` // 尺寸id
|
|
|
|
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
|
|
|
|
Status *int64 `gorm:"default:1" json:"status"` // 状态位 1启用0停用
|
|
|
|
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
|
|
|
|
Sid *string `gorm:"default:''" json:"sid"` // 前端带入的id
|
|
|
|
}
|
|
|
|
|
|
|
|
type FsCanteenProductModel struct {
|
|
|
|
db *gorm.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewFsCanteenProductModel(db *gorm.DB) *FsCanteenProductModel {
|
|
|
|
return &FsCanteenProductModel{db}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *FsCanteenProductModel) GetAllByCanteenTypeId(ctx context.Context, typeId int64) (resp []FsCanteenProduct, err error) {
|
|
|
|
err = c.db.WithContext(ctx).Model(&FsCanteenProduct{}).Where("`canteen_type` = ? and `status` = ?", typeId, 1).Find(&resp).Error
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-06-12 10:06:47 +00:00
|
|
|
return
|
2023-06-12 08:47:48 +00:00
|
|
|
}
|
|
|
|
func (c *FsCanteenProductModel) UpdateById(ctx context.Context, id int64, data *FsCanteenProduct) error {
|
|
|
|
return c.db.WithContext(ctx).Model(&FsCanteenProduct{}).Where("`id` = ? ", id).Updates(&data).Error
|
|
|
|
}
|
|
|
|
func (c *FsCanteenProductModel) UpdateByIdArr(ctx context.Context, ids []int64, data *FsCanteenProduct) error {
|
2023-06-13 04:15:06 +00:00
|
|
|
if len(ids) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2023-06-12 08:47:48 +00:00
|
|
|
return c.db.WithContext(ctx).Model(&FsCanteenProduct{}).Where("`id` in (?) ", ids).Updates(&data).Error
|
|
|
|
}
|
|
|
|
func (c *FsCanteenProductModel) Create(ctx context.Context, data *FsCanteenProduct) error {
|
|
|
|
return c.db.WithContext(ctx).Model(&FsCanteenProduct{}).Create(data).Error
|
|
|
|
}
|