From e0a433e9c31594527a3bf7766c0bfb2cbbceffdb Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期三, 26 七月 2023 10:09:04 +0800
Subject: [PATCH] fix add pageInfo, keyword to all the list

---
 model/saleChance.go |   47 +++++++++++++++++++++++++++++++++++------------
 1 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/model/saleChance.go b/model/saleChance.go
index fdfb54b..060a15c 100644
--- a/model/saleChance.go
+++ b/model/saleChance.go
@@ -45,9 +45,14 @@
 		gorm.Model `json:"-"`
 	}
 
-	SaleChangeSearch struct {
+	SaleChanceSearch struct {
 		SaleChance
-		Orm *gorm.DB
+
+		Orm      *gorm.DB
+		Keyword  string
+		OrderBy  string
+		PageNum  int
+		PageSize int
 	}
 )
 
@@ -55,12 +60,15 @@
 	return "sale_chance"
 }
 
-func NewSaleChangeSearch() *SaleChangeSearch {
-	return &SaleChangeSearch{Orm: mysqlx.GetDB()}
+func NewSaleChanceSearch() *SaleChanceSearch {
+	return &SaleChanceSearch{Orm: mysqlx.GetDB()}
 }
 
-func (slf *SaleChangeSearch) build() *gorm.DB {
+func (slf *SaleChanceSearch) build() *gorm.DB {
 	var db = slf.Orm.Model(&SaleChance{})
+	if slf.Keyword != "" {
+		db = db.Where("name LIKE ?", "%"+slf.Keyword+"%")
+	}
 	if slf.Id > 0 {
 		db = db.Where("id = ?", slf.Id)
 	}
@@ -71,42 +79,57 @@
 	return db
 }
 
-func (slf *SaleChangeSearch) Create(record *SaleChance) (err error) {
+func (slf *SaleChanceSearch) Create(record *SaleChance) (err error) {
 	var db = slf.build()
 	err = db.Create(record).Error
 	return
 }
 
-func (slf *SaleChangeSearch) Update(record *SaleChance) (err error) {
+func (slf *SaleChanceSearch) Update(record *SaleChance) (err error) {
 	var db = slf.build()
 	err = db.Updates(record).Error
 	return
 }
 
-func (slf *SaleChangeSearch) Delete() (err error) {
+func (slf *SaleChanceSearch) Delete() (err error) {
 	var db = slf.build()
 	err = db.Delete(&SaleChance{}).Error
 	return
 }
 
-func (slf *SaleChangeSearch) Find() (record SaleChance, err error) {
+func (slf *SaleChanceSearch) Find() (record SaleChance, err error) {
 	var db = slf.build()
 	err = db.First(&record).Error
 	return
 }
 
-func (slf *SaleChangeSearch) FindAll() (record []*SaleChance, err error) {
+func (slf *SaleChanceSearch) FindAll() (record []*SaleChance, err error) {
 	var db = slf.build()
 	err = db.Preload("Client").Preload("Contact").Find(&record).Error
 	return
 }
 
-func (slf *SaleChangeSearch) SetId(id int) *SaleChangeSearch {
+func (slf *SaleChanceSearch) SetId(id int) *SaleChanceSearch {
 	slf.Id = id
 	return slf
 }
 
-func (slf *SaleChangeSearch) SetName(name string) *SaleChangeSearch {
+func (slf *SaleChanceSearch) SetName(name string) *SaleChanceSearch {
 	slf.Name = name
 	return slf
 }
+
+func (slf *SaleChanceSearch) SetKeyword(keyword string) *SaleChanceSearch {
+	slf.Keyword = keyword
+	return slf
+}
+
+func (slf *SaleChanceSearch) SetPage(page, size int) *SaleChanceSearch {
+	slf.PageNum, slf.PageSize = page, size
+	return slf
+}
+
+func (slf *SaleChanceSearch) SetOrder(order string) *SaleChanceSearch {
+	slf.OrderBy = order
+	return slf
+}

--
Gitblit v1.8.0