From f84d9c46574a2cd663105859035bc17891270923 Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期一, 14 八月 2023 10:41:54 +0800
Subject: [PATCH] Merge branch 'master' into fly

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

diff --git a/model/quotation.go b/model/quotation.go
index b97befb..61061ae 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,36 @@
 
 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" || key == "number" {
+					db = db.Where(key+" = ?", v)
+				}
+
+				if key == "client_name" {
+					db = db.Joins("Client").Where("client.name = ?", v)
+				}
+
+				if key == "contact_name" {
+					db = db.Joins("Contact").Where("contact.name = ?", v)
+				}
+
+				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 +131,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 +140,8 @@
 	slf.OrderBy = order
 	return slf
 }
+
+func (slf *QuotationSearch) SetSearchMap(searchMap map[string]interface{}) *QuotationSearch {
+	slf.SearchMap = searchMap
+	return slf
+}

--
Gitblit v1.8.0