| | |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | | for _, t := range p.List { |
| | | var num int64 |
| | | db := global.GVA_DB.Model(&test.Product{}) |
| | | err := db.Where("number = ?", t.Number).Where("supplier_id = ?", t.SupplierId).Count(&num).Error |
| | | if err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | | if num > 0 { |
| | | response.FailWithMessage("当前供应商已经提供此产品", c) |
| | | return |
| | | } |
| | | } |
| | | if err := pService.CreateProduct(p.List); err != nil { |
| | | global.GVA_LOG.Error("创建失败!", zap.Error(err)) |
| | | response.FailWithMessage("创建失败", c) |
| | |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | | } else { |
| | | //添加供应商名称 |
| | | for i := 0; i < len(list); i++ { |
| | | list[i].SupplierName = list[i].Supplier.Name |
| | | } |
| | | response.OkWithDetailed(response.PageResult{ |
| | | List: list, |
| | | Total: total, |
| | |
| | | productList[k].Number = v.Number |
| | | productList[k].Name = v.Name |
| | | productList[k].Unit = v.Unit |
| | | productList[k].PurchasePrice = &v.SalePrice |
| | | productList[k].PurchasePrice = v.SalePrice |
| | | min := int(v.MinInventory) |
| | | productList[k].MinimumStock = &min |
| | | productList[k].MinimumStock = min |
| | | max := int(v.MaxInventory) |
| | | productList[k].MaximumStock = &max |
| | | productList[k].MaximumStock = max |
| | | productList[k].Remark = v.Node |
| | | productList[k].ProductType = v.MaterialMode |
| | | } |