liujiandao
2023-11-02 f9ce7300c4ce1673d06a052e43cb462f8a69c13c
api/v1/test/product.go
@@ -36,6 +36,19 @@
      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)
@@ -160,6 +173,10 @@
      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,
@@ -219,11 +236,11 @@
      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
   }