From dac214fa72dc2974954a4d8ee934695f548ad155 Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期三, 02 八月 2023 14:14:30 +0800
Subject: [PATCH] fix

---
 model/quotation.go |   41 +++++++++++++++++++++++++++++++++++++----
 1 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/model/quotation.go b/model/quotation.go
index d5fdec8..2999797 100644
--- a/model/quotation.go
+++ b/model/quotation.go
@@ -22,12 +22,19 @@
 		Client            Client     `json:"client" gorm:"foreignKey:ClientId"`
 		Contact           Contact    `json:"contact" gorm:"foreignKey:ContactId"`
 		SaleChance        SaleChance `json:"sale_chance" gorm:"foreignKey:SaleChanceId"`
+		gorm.Model        `json:"-"`
 	}
 
 	// QuotationSearch 鎶ヤ环鍗曟悳绱㈡潯浠�
 	QuotationSearch struct {
 		Quotation
-		Orm *gorm.DB
+
+				Orm      *gorm.DB
+		Keyword  string
+		OrderBy  string
+		PageNum  int
+		PageSize int
+
 	}
 )
 
@@ -43,6 +50,9 @@
 
 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)
 	}
@@ -72,11 +82,19 @@
 	return &record, err
 }
 
-func (slf *QuotationSearch) FindAll() ([]*Quotation, error) {
+func (slf *QuotationSearch) FindAll() ([]*Quotation, int64, error) {
 	var db = slf.build()
-	var records []*Quotation
+	var records = make([]*Quotation, 0)
+	var total int64
+	if err := db.Count(&total).Error; err != nil {
+		return records, total, err
+	}
+	if slf.PageNum > 0 && slf.PageSize > 0 {
+		db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
+	}
+
 	err := db.Find(&records).Error
-	return records, err
+	return records, total, err
 }
 
 func (slf *QuotationSearch) SetId(id int) *QuotationSearch {
@@ -88,3 +106,18 @@
 	var db = slf.build()
 	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
+}
+
+func (slf *QuotationSearch) SetOrder(order string) *QuotationSearch {
+	slf.OrderBy = order
+	return slf
+}
\ No newline at end of file

--
Gitblit v1.8.0