fusenapi/model/gmodel/fs_cloud_pick_up_logic.go
laodaming c5bcf9d676 fix
2023-06-27 14:25:25 +08:00

32 lines
894 B
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
})
}