fusenapi/model/gmodel/fs_order_logic.go

26 lines
821 B
Go
Raw Normal View History

2023-06-16 07:11:37 +00:00
package gmodel
import (
"context"
"errors"
2023-06-19 02:12:58 +00:00
2023-06-16 07:11:37 +00:00
"gorm.io/gorm"
)
func (o *FsOrderModel) FindOneBySn(ctx context.Context, userId int64, sn string) (resp FsOrder, err error) {
2023-06-20 08:46:56 +00:00
err = o.db.WithContext(ctx).Model(&FsOrder{}).Where(" `user_id` = ? and `sn` = ? ", userId, sn).Take(&resp).Error
2023-06-16 07:11:37 +00:00
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsOrder{}, err
}
return resp, nil
}
2023-06-20 08:46:56 +00:00
func (o *FsOrderModel) FindOne(ctx context.Context, userId int64, OrderId int64) (order FsOrder, err error) {
err = o.db.WithContext(ctx).Model(&order).Where("`user_id` = ? and `id` = ?", userId, OrderId).Take(&order).Error
return order, err
}
2023-06-16 07:11:37 +00:00
func (o *FsOrderModel) Update(ctx context.Context, id int64, data FsOrder) error {
return o.db.WithContext(ctx).Model(&FsOrder{}).Where("`id` = ?", id).Updates(data).Error
}