26 lines
811 B
Go
Executable File
26 lines
811 B
Go
Executable File
package gmodel
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func (o *FsOrderModel) FindOneBySn(ctx context.Context, userId int64, sn string) (resp FsOrder, err error) {
|
|
err = o.db.WithContext(ctx).Model(&FsOrder{}).Where(" `user_id` = ? and `sn` = ? ", userId, sn).Take(&resp).Error
|
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return FsOrder{}, err
|
|
}
|
|
return resp, nil
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
func (o *FsOrderModel) Update(ctx context.Context, data *FsOrder) error {
|
|
return o.db.WithContext(ctx).Model(data).Where("`id` = ?", data.Id).Updates(data).Error
|
|
}
|