fusenapi/model/gmodel/fs_canteen_product_logic.go

32 lines
1.3 KiB
Go
Raw Normal View History

2023-06-12 08:47:48 +00:00
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
}
2023-06-12 10:06:47 +00:00
return
2023-06-12 08:47:48 +00:00
}
2023-06-25 12:00:27 +00:00
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
}
2023-06-25 12:00:27 +00:00
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
2023-06-26 10:19:51 +00:00
return resp, err
2023-06-25 12:00:27 +00:00
}