fusenapi/model/gmodel/fs_cloud_pick_up_logic.go
2023-06-28 19:32:41 +08:00

38 lines
1.0 KiB
Go

package gmodel
import (
"context"
"gorm.io/gorm"
)
// TODO: 使用model的属性做你想做的
func (p *FsCloudPickUpModel) SavePickUpWithTransaction(ctx context.Context, pickUpData *FsCloudPickUp, stockList []FsUserStock, pickUpDetailAddList []FsCloudPickUpDetail) error {
return p.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
//保存总提单信息
if err := tx.Model(&FsCloudPickUp{}).Create(&pickUpData).Error; err != nil {
return err
}
//更新云仓库存
for _, v := range stockList {
if err := tx.Model(&FsUserStock{}).Where("`id` = ?", v.Id).Updates(&v).Error; err != nil {
return err
}
}
//添加提单详情
for _, v := range pickUpDetailAddList {
v.PickId = &pickUpData.Id //外面没赋值在这需要赋值
if err := tx.Model(&FsCloudPickUpDetail{}).Create(&v).Error; err != nil {
return err
}
}
return nil
})
}
func (p *FsCloudPickUpModel) GetCloudPickUpByIDAndUserID(ctx context.Context, userId int64, RelationID int64) (cloudOrder *FsCloudPickUp, err error) {
return cloudOrder, err
}