fusenapi/model/gmodel/fs_order_logic.go

38 lines
1.2 KiB
Go
Raw Normal View History

2023-06-16 07:11:37 +00:00
package gmodel
import (
"context"
2023-06-28 11:32:41 +00:00
"gorm.io/gorm"
2023-06-16 07:11:37 +00:00
)
2023-06-20 09:28:28 +00:00
func (o *FsOrderModel) FindOneBySn(ctx context.Context, userId int64, sn string) (resp *FsOrder, err error) {
2023-06-21 04:34:57 +00:00
err = o.db.WithContext(ctx).Model(&FsOrder{}).Where(" `user_id` = ? and `sn` = ? ", userId, sn).Take(&resp).Error
2023-06-20 09:28:28 +00:00
return resp, err
2023-06-16 07:11:37 +00:00
}
2023-06-20 08:46:56 +00:00
2023-06-20 09:28:28 +00:00
func (o *FsOrderModel) FindOne(ctx context.Context, userId int64, OrderId int64) (order *FsOrder, err error) {
2023-06-28 09:05:31 +00:00
err = o.db.WithContext(ctx).Model(&FsOrder{}).Where("`user_id` = ? and `id` = ?", userId, OrderId).Take(&order).Error
2023-06-20 09:28:28 +00:00
if err != nil {
return nil, err
}
return
2023-06-20 08:46:56 +00:00
}
2023-06-20 09:29:02 +00:00
func (o *FsOrderModel) Update(ctx context.Context, data *FsOrder) error {
2023-06-28 09:05:31 +00:00
return o.db.WithContext(ctx).Model(&FsOrder{}).Where("`id` = ?", data.Id).Updates(&data).Error
}
func (o *FsOrderModel) Create(ctx context.Context, data *FsOrder) error {
return o.db.WithContext(ctx).Model(&FsOrder{}).Create(&data).Error
2023-06-16 07:11:37 +00:00
}
2023-06-28 11:32:41 +00:00
func (o *FsOrderModel) FindOneAndCreateServiceContact(ctx context.Context, userId int64, OrderId int64) (order *FsOrder, err error) {
err = o.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
err = tx.Model(order).Where("`user_id` = ? and `id` = ?", userId, OrderId).Take(&order).Error
tx.Table("").Model(FsContactService{})
return err
})
return order, err
}