From d8ac88cfb72e3aac3a89c3cfe77774be3024a24c Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期五, 11 八月 2023 17:54:43 +0800
Subject: [PATCH] update

---
 model/quotation.go |   67 +++++++++++++++++++--------------
 1 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/model/quotation.go b/model/quotation.go
index 34262bc..f6980ec 100644
--- a/model/quotation.go
+++ b/model/quotation.go
@@ -3,26 +3,25 @@
 import (
 	"aps_crm/pkg/mysqlx"
 	"gorm.io/gorm"
-	"time"
 )
 
 type (
 	// Quotation 鎶ヤ环鍗�
 	Quotation struct {
-		Id                int        `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
-		ClientId          int        `json:"client_id" gorm:"column:client_id;type:int;comment:瀹㈡埛id"`
-		Number            string     `json:"number" gorm:"column:number;type:varchar(255);comment:鎶ヤ环鍗曞彿"`
-		QuotationStatusId int        `json:"quotation_status_id" gorm:"column:quotation_status_id;type:int;comment:鎶ヤ环鍗曠姸鎬乮d"`
-		ValidityDate      *time.Time `json:"validity_date" gorm:"column:validity_date;type:datetime;comment:鏈夋晥鏈�"`
-		ContactId         int        `json:"contact_id" gorm:"column:contact_id;type:int;comment:鑱旂郴浜篿d"`
-		MemberId          int        `json:"member_id" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"`
-		SaleChanceId      int        `json:"sale_chance_id" gorm:"column:sale_chance_id;type:int;comment:閿�鍞満浼歩d"`
-		Conditions        string     `json:"conditions" gorm:"column:conditions;type:text;comment:鎶ヤ环鏉′欢"`
-		File              string     `json:"file" gorm:"column:file;type:varchar(255);comment:闄勪欢"`
-		Client            Client     `json:"client" gorm:"foreignKey:ClientId"`
-		Contact           Contact    `json:"contact" gorm:"foreignKey:ContactId"`
-		SaleChance        SaleChance `json:"sale_chance" gorm:"foreignKey:SaleChanceId"`
-		Products          []Product  `json:"products" gorm:"many2many:quotation_product"`
+		Id                int         `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+		ClientId          int         `json:"client_id" gorm:"column:client_id;type:int;comment:瀹㈡埛id"`
+		Number            string      `json:"number" gorm:"column:number;type:varchar(255);comment:鎶ヤ环鍗曞彿"`
+		QuotationStatusId int         `json:"quotation_status_id" gorm:"column:quotation_status_id;type:int;comment:鎶ヤ环鍗曠姸鎬乮d"`
+		ValidityDate      *CustomTime `json:"validity_date" gorm:"column:validity_date;type:datetime;comment:鏈夋晥鏈�"`
+		ContactId         int         `json:"contact_id" gorm:"column:contact_id;type:int;comment:鑱旂郴浜篿d"`
+		MemberId          int         `json:"member_id" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"`
+		SaleChanceId      int         `json:"sale_chance_id" gorm:"column:sale_chance_id;type:int;comment:閿�鍞満浼歩d"`
+		Conditions        string      `json:"conditions" gorm:"column:conditions;type:text;comment:鎶ヤ环鏉′欢"`
+		File              string      `json:"file" gorm:"column:file;type:varchar(255);comment:闄勪欢"`
+		Client            Client      `json:"client" gorm:"foreignKey:ClientId"`
+		Contact           Contact     `json:"contact" gorm:"foreignKey:ContactId"`
+		SaleChance        SaleChance  `json:"sale_chance" gorm:"foreignKey:SaleChanceId"`
+		Products          []Product   `json:"products" gorm:"many2many:quotation_product"`
 		gorm.Model        `json:"-"`
 	}
 
@@ -30,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
 	}
 )
 
@@ -50,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
@@ -107,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
@@ -121,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