| | |
| | | import ( |
| | | "context" |
| | | "github.com/shopspring/decimal" |
| | | "gorm.io/gorm" |
| | | "strconv" |
| | | "time" |
| | | "wms/constvar" |
| | |
| | | operation.Number = strconv.FormatInt(time.Now().Unix(), 10) |
| | | operation.Status = constvar.OperationStatus_Ready |
| | | operation.CompanyName = req.SupplierName |
| | | operation.Source = req.Source |
| | | warehouse, err := models.NewWarehouseSearch().First() |
| | | if err != nil { |
| | | return nil, err |
| | |
| | | detail.Amount = decimal.NewFromInt(product.Amount) |
| | | details = append(details, &detail) |
| | | } |
| | | err = models.NewOperationSearch().Create(&operation) |
| | | return new(PurchaseToWmsResponse), err |
| | | err = models.WithTransaction(func(db *gorm.DB) error { |
| | | err := models.NewOperationSearch().SetOrm(db).Create(&operation) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | for _, detail := range details { |
| | | detail.OperationID = operation.Id |
| | | } |
| | | err = models.NewOperationDetailsSearch().SetOrm(db).CreateBatch(details) |
| | | return err |
| | | }) |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | resp := new(PurchaseToWmsResponse) |
| | | resp.Warehouse = warehouse.Name |
| | | return resp, nil |
| | | } |