fusenapi/model/gmodel/fs_cloud_pick_up_logic.go

38 lines
1.0 KiB
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"
2023-06-28 11:32:41 +00:00
2023-06-27 06:25:25 +00:00
"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
})
}
2023-06-28 11:32:41 +00:00
func (p *FsCloudPickUpModel) GetCloudPickUpByIDAndUserID(ctx context.Context, userId int64, RelationID int64) (cloudOrder *FsCloudPickUp, err error) {
return cloudOrder, err
}