From 530fed8ec225453572d57b15c200ab062c335457 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 01 十一月 2023 19:20:21 +0800
Subject: [PATCH] 公海member_id使用0

---
 model/receipt.go |   66 ++++++++++++++++++++++++++++----
 1 files changed, 57 insertions(+), 9 deletions(-)

diff --git a/model/receipt.go b/model/receipt.go
index c93385f..ff0a169 100644
--- a/model/receipt.go
+++ b/model/receipt.go
@@ -14,6 +14,7 @@
 	Receipt struct {
 		Id            int                        `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
 		ClientId      int                        `gorm:"column:client_id;type:int;not null;default 0;comment:瀹㈡埛id" json:"clientId"`                                // 瀹㈡埛id
+		Client        Client                     `gorm:"foreignKey:ClientId" json:"client"`                                                                        // 瀹㈡埛id
 		SourceType    constvar.ReceiptSourceType `gorm:"column:source_type;type:int;not null;default 0;comment:鏉ユ簮绫诲瀷锛�1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓3閿�鍞彂绁�4鏀舵璁″垝5鍑哄簱鍗曪級" json:"sourceType"` // 鏉ユ簮绫诲瀷锛�1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓3閿�鍞彂绁�4鏀舵璁″垝5鍑哄簱鍗曪級
 		SourceId      int                        `gorm:"column:source_id;type:int;not null;default 0;comment:婧愬崟id " json:"sourceId"`                               // 婧愬崟id
 		PrincipalId   int                        `gorm:"column:principal_id;type:int;not null;default 0;comment:璐熻矗浜篿d" json:"principalId"`                         // 璐熻矗浜篿d
@@ -27,23 +28,33 @@
 		BankAccount   BankAccount                `gorm:"foreignKey:BankAccountId" json:"bankAccount"`
 		Remark        string                     `gorm:"column:remark;type:varchar(255);not null;default '';comment:澶囨敞" json:"remark"` // 澶囨敞
 		FileId        int                        `gorm:"column:file_id;type:int;not null;default 0;comment:闄勪欢id" json:"fileId"`        // 闄勪欢id
-		gorm.Model    `json:"-"`
+		CrmModel
 	}
 
 	// ReceiptSearch 鏀舵鍗曟悳绱㈡潯浠�
 	ReceiptSearch struct {
 		Receipt
-		Orm         *gorm.DB
-		QueryClass  constvar.ReceiptQueryClass
-		KeywordType constvar.ReceiptKeywordType
-		Keyword     string
-		PageNum     int
-		PageSize    int
+		Orm          *gorm.DB
+		QueryClass   constvar.ReceiptQueryClass
+		KeywordType  constvar.ReceiptKeywordType
+		Keyword      string
+		PageNum      int
+		PageSize     int
+		PrincipalIds []int
 	}
 )
 
-func (Receipt) TableName() string {
+func (slf *Receipt) TableName() string {
 	return "receipt"
+}
+
+func (slf *Receipt) AfterFind(db *gorm.DB) (err error) {
+	err = slf.CrmModel.AfterFind(db)
+	if slf.CrmModel.ID == 0 {
+		slf.CrmModel.ID = uint(slf.Id)
+	}
+	slf.CrmModel.SetNumber(constvar.NumberPrefixOfReceipt)
+	return nil
 }
 
 func NewReceiptSearch() *ReceiptSearch {
@@ -52,10 +63,42 @@
 	}
 }
 
+func (slf *ReceiptSearch) SetSourceType(sourceType constvar.ReceiptSourceType) *ReceiptSearch {
+	slf.SourceType = sourceType
+	return slf
+}
+
+func (slf *ReceiptSearch) SetSourceId(sourceId int) *ReceiptSearch {
+	slf.SourceId = sourceId
+	return slf
+}
+
+func (slf *ReceiptSearch) SetPrincipalIds(principalIds []int) *ReceiptSearch {
+	slf.PrincipalIds = principalIds
+	return slf
+}
+
+func (slf *ReceiptSearch) SetPage(page, size int) *ReceiptSearch {
+	slf.PageNum, slf.PageSize = page, size
+	return slf
+}
+
 func (slf *ReceiptSearch) build() *gorm.DB {
 	var db = slf.Orm.Model(&Receipt{})
 	if slf.Id != 0 {
 		db = db.Where("id = ?", slf.Id)
+	}
+	if slf.SourceType != 0 {
+		db = db.Where("source_type = ?", slf.SourceType)
+	}
+	if slf.SourceId != 0 {
+		db = db.Where("source_id = ?", slf.SourceId)
+	}
+	if slf.ClientId != 0 {
+		db = db.Where("client_id = ?", slf.ClientId)
+	}
+	if len(slf.PrincipalIds) != 0 {
+		db = db.Where("principal_id in ?", slf.PrincipalIds)
 	}
 
 	return db
@@ -90,6 +133,11 @@
 
 func (slf *ReceiptSearch) SetId(id int) *ReceiptSearch {
 	slf.Id = id
+	return slf
+}
+
+func (slf *ReceiptSearch) SetClientId(clientId int) *ReceiptSearch {
+	slf.ClientId = clientId
 	return slf
 }
 
@@ -134,7 +182,7 @@
 		db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
 	}
 
-	err := db.Find(&records).Error
+	err := db.Preload("Principal").Preload("Client").Preload("PaymentType").Preload("BankAccount").Order("created_at desc").Find(&records).Error
 	return records, total, err
 }
 

--
Gitblit v1.8.0