| | |
| | | if req.ProductId == "" { |
| | | return nil, errors.New("产品id为空") |
| | | } |
| | | var pt purchase.PurchaseType |
| | | err := global.GVA_DB.Model(&purchase.PurchaseType{}).First(&pt).Error |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | var product test.SupplierMaterial |
| | | err = global.GVA_DB.Model(&test.SupplierMaterial{}).Where("number = ?", req.ProductId).First(&product).Error |
| | | err := global.GVA_DB.Model(&test.SupplierMaterial{}).Where("number = ?", req.ProductId).First(&product).Error |
| | | if err != nil { |
| | | if err == gorm.ErrRecordNotFound { |
| | | var material test.Material |
| | |
| | | |
| | | //采购单 |
| | | var purchaseRecord purchase.Purchase |
| | | purchaseRecord.PurchaseTypeId = int(pt.ID) |
| | | |
| | | //purchaseRecord.SupplierId = int(req.SupplierId) |
| | | if req.Source == "WMS" { |
| | | purchaseRecord.OrderSource = "WMS推送" |
| | |
| | | resp.Infos = infos |
| | | return resp, nil |
| | | } |
| | | |
| | | func (s *Server) ExistSupplier(ctx context.Context, req *ExistSupplierRequest) (*ExistSupplierResponse, error) { |
| | | resp := new(ExistSupplierResponse) |
| | | if len(req.ProductId) == 0 { |
| | | resp.Exist = false |
| | | return resp, nil |
| | | } |
| | | var products []test.SupplierMaterial |
| | | err := global.GVA_DB.Model(&test.SupplierMaterial{}).Where("number in (?)", req.ProductId).Find(&products).Error |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | for _, number := range req.ProductId { |
| | | exit := false |
| | | for _, product := range products { |
| | | if number == product.Number && product.SupplierId > 0 { |
| | | exit = true |
| | | break |
| | | } |
| | | } |
| | | if !exit { |
| | | resp.Exist = exit |
| | | return resp, nil |
| | | } |
| | | } |
| | | resp.Exist = true |
| | | return resp, nil |
| | | } |