32 lines
1.3 KiB
Go
Executable File
32 lines
1.3 KiB
Go
Executable File
package gmodel
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
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
|
|
}
|
|
return
|
|
}
|
|
|
|
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 {
|
|
if len(ids) == 0 {
|
|
return nil
|
|
}
|
|
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
|
|
}
|
|
|
|
func (c *FsCanteenProductModel) GetAllByCanteenTypeIdOrderAsc(ctx context.Context, typeId int64) (resp []FsCanteenProduct, err error) {
|
|
err = c.db.WithContext(ctx).Model(&FsCanteenProduct{}).Where("`canteen_type` = ? and `status` = ?", typeId, 1).Order("sort asc").Find(&resp).Error
|
|
return resp, err
|
|
}
|