From 18f5a87f2b647a27417aaffd62f48ff38be1d0d8 Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期一, 14 八月 2023 13:35:29 +0800
Subject: [PATCH] fix

---
 model/contract.go |   53 +++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/model/contract.go b/model/contract.go
index 024cf8b..505871d 100644
--- a/model/contract.go
+++ b/model/contract.go
@@ -15,18 +15,17 @@
 		Quotation   Quotation `json:"quotation" gorm:"foreignKey:QuotationId;references:Id"`
 		StatusId    int       `json:"statusId" gorm:"column:status_id;type:int;comment:鍚堝悓鐘舵��"`
 		File        string    `json:"file" gorm:"column:file;type:varchar(255);comment:鍚堝悓鏂囦欢"`
-		gorm.Model  `json:"-"`
+		gormModel
 	}
 
 	ContractSearch struct {
 		Contract
 
-				Orm      *gorm.DB
-		Keyword  string
-		OrderBy  string
-		PageNum  int
-		PageSize int
-
+		Orm       *gorm.DB
+		SearchMap map[string]interface{}
+		OrderBy   string
+		PageNum   int
+		PageSize  int
 	}
 )
 
@@ -42,11 +41,33 @@
 
 func (slf *ContractSearch) build() *gorm.DB {
 	var db = slf.Orm.Model(&Contract{})
-	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 == "client_name" {
+					db = db.Joins("Client").Where("Client.name LIKE ?", "%"+v+"%")
+				}
+
+				if key == "member_name" {
+					db = db.Joins("User").Where("User.username LIKE ?", "%"+v+"%")
+				}
+
+				if key == "number" {
+					db = db.Where("number LIKE ?", "%"+v+"%")
+				}
+
+				if key == "created_at" {
+					db = db.Where(key+"= ?", v)
+				}
+			case int:
+			}
+		}
 	}
 
 	return db
@@ -98,11 +119,6 @@
 	return slf
 }
 
-func (slf *ContractSearch) SetKeyword(keyword string) *ContractSearch {
-	slf.Keyword = keyword
-	return slf
-}
-
 func (slf *ContractSearch) SetPage(page, size int) *ContractSearch {
 	slf.PageNum, slf.PageSize = page, size
 	return slf
@@ -111,4 +127,9 @@
 func (slf *ContractSearch) SetOrder(order string) *ContractSearch {
 	slf.OrderBy = order
 	return slf
-}
\ No newline at end of file
+}
+
+func (slf *ContractSearch) SetSearchMap(data map[string]interface{}) *ContractSearch {
+	slf.SearchMap = data
+	return slf
+}

--
Gitblit v1.8.0