fusenapi/model/gmodel/fs_cloud_pick_up_logic.go

32 lines
894 B
Go
Raw Normal View History

2023-06-19 10:27:31 +00:00
package gmodel
2023-06-27 06:25:25 +00:00
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
})
}