From 4630cbf64d1d4f33376efaaec7b4fcb90b01bf05 Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期日, 07 四月 2024 11:55:17 +0800
Subject: [PATCH] 采购单修改2

---
 service/test/product.go |   41 ++++++++++++++++++++++++++++++++++++++---
 1 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/service/test/product.go b/service/test/product.go
index 7449f97..f33fa33 100644
--- a/service/test/product.go
+++ b/service/test/product.go
@@ -26,6 +26,8 @@
 			DeliveryTime:     p.DeliveryTime,
 			ShippingDuration: p.ShippingDuration,
 			Specifications:   p.Specifications,
+			CategoryName:     p.CategoryName,
+			ModelNumber:      p.ModelNumber,
 		})
 	}
 
@@ -71,7 +73,13 @@
 	var ps []test.SupplierMaterial
 	//鎼滅储妗嗗悎涓�娣诲姞鏌ヨ鏉′欢
 	if info.Keyword != "" {
-		db = db.Where("`srm_supplier_material`.name LIKE ?", "%"+info.Keyword+"%").Joins("Supplier").Or("Supplier.name LIKE ?", "%"+info.Keyword+"%")
+		kw := "%" + info.Keyword + "%"
+		if info.SupplierId == 0 {
+			db = db.Where("`srm_supplier_material`.name LIKE ?", kw).Joins("Supplier").Or("Supplier.name LIKE ?", kw)
+		} else {
+			db = db.Where("name LIKE ? OR number LIKE ? OR specifications LIKE ?", kw, kw, kw)
+		}
+
 	}
 	if info.Name != "" {
 		db = db.Where("name LIKE ?", "%"+info.Name+"%")
@@ -80,16 +88,18 @@
 		db = db.Where("number LIKE ?", "%"+info.Number+"%")
 	}
 
+	supplierIds := []uint{0}
 	if info.SupplierId != 0 {
-		db = db.Where("supplier_id = ?", info.SupplierId)
+		supplierIds = append(supplierIds, info.SupplierId)
 	}
+	db = db.Where("supplier_id in (?)", supplierIds)
 
 	err = db.Count(&total).Error
 	if err != nil {
 		return
 	}
 
-	err = db.Limit(limit).Offset(offset).Preload("Supplier").Find(&ps).Error
+	err = db.Limit(limit).Offset(offset).Order("id desc").Preload("Supplier").Find(&ps).Error
 	return ps, total, err
 }
 
@@ -105,3 +115,28 @@
 	}
 	return
 }
+
+// GetMaterials 鑾峰彇鐗╂枡
+func (pService *ProductService) GetMaterials(info testReq.ProductSearch) (list []test.Material, total int64, err error) {
+	limit := info.PageSize
+	offset := info.PageSize * (info.Page - 1)
+	// 鍒涘缓db
+	db := global.GVA_DB.Model(&test.Material{})
+	var ps []test.Material
+	if info.Keyword != "" {
+		db = db.Where("name LIKE ? or id LIKE ?", "%"+info.Keyword+"%", "%"+info.Keyword+"%")
+	}
+
+	//绫诲瀷涓洪噰璐�
+	db = db.Where("purchase_types LIKE ?", "%1%")
+
+	db = db.Where("is_storage = ?", 1)
+
+	err = db.Count(&total).Error
+	if err != nil {
+		return
+	}
+
+	err = db.Limit(limit).Offset(offset).Find(&ps).Error
+	return ps, total, err
+}

--
Gitblit v1.8.0