From 4dd4ae617e7f37817d2c795ff011d73a67dc29bf Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期五, 11 八月 2023 17:28:56 +0800
Subject: [PATCH] fix

---
 model/quotation.go |   38 +++++++++++++++++++++++++-------------
 1 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/model/quotation.go b/model/quotation.go
index b97befb..f6980ec 100644
--- a/model/quotation.go
+++ b/model/quotation.go
@@ -29,11 +29,11 @@
 	QuotationSearch struct {
 		Quotation
 
-		Orm      *gorm.DB
-		Keyword  string
-		OrderBy  string
-		PageNum  int
-		PageSize int
+		Orm       *gorm.DB
+		SearchMap map[string]interface{}
+		OrderBy   string
+		PageNum   int
+		PageSize  int
 	}
 )
 
@@ -49,11 +49,23 @@
 
 func (slf *QuotationSearch) build() *gorm.DB {
 	var db = slf.Orm.Model(&Quotation{})
-	if slf.Keyword != "" {
-		db = db.Where("name LIKE ?", "%"+slf.Keyword+"%")
-	}
 	if slf.Id != 0 {
 		db = db.Where("id = ?", slf.Id)
+	}
+
+	if len(slf.SearchMap) > 0 {
+		for key, value := range slf.SearchMap {
+			switch v := value.(type) {
+			case string:
+				if key == "validity_date" {
+					db = db.Where(key+" = ?", v)
+				}
+			case int:
+				if key == "client_id" || key == "sale_chance_id" {
+					db = db.Where(key+" = ?", v)
+				}
+			}
+		}
 	}
 
 	return db
@@ -106,11 +118,6 @@
 	return db.Updates(data).Error
 }
 
-func (slf *QuotationSearch) SetKeyword(keyword string) *QuotationSearch {
-	slf.Keyword = keyword
-	return slf
-}
-
 func (slf *QuotationSearch) SetPage(page, size int) *QuotationSearch {
 	slf.PageNum, slf.PageSize = page, size
 	return slf
@@ -120,3 +127,8 @@
 	slf.OrderBy = order
 	return slf
 }
+
+func (slf *QuotationSearch) SetSearchMap(searchMap map[string]interface{}) *QuotationSearch {
+	slf.SearchMap = searchMap
+	return slf
+}

--
Gitblit v1.8.0