From f9ce7300c4ce1673d06a052e43cb462f8a69c13c Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期四, 02 十一月 2023 14:30:19 +0800
Subject: [PATCH] 优化重构2

---
 api/v1/test/product.go |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/api/v1/test/product.go b/api/v1/test/product.go
index 937a65c..dfb82c9 100644
--- a/api/v1/test/product.go
+++ b/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
 	}

--
Gitblit v1.8.0