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/invoice.go |   75 ++++++++++++++++++++++++++++++++++---
 1 files changed, 68 insertions(+), 7 deletions(-)

diff --git a/model/invoice.go b/model/invoice.go
index 8db5f13..7089b18 100644
--- a/model/invoice.go
+++ b/model/invoice.go
@@ -12,6 +12,7 @@
 	// Invoice 閿�鍞彂绁�
 	Invoice struct {
 		Id               int                        `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+		Number           string                     `json:"number" gorm:"column:number;type:varchar(255);comment:鍙戠エ缂栧彿"`
 		ClientId         int                        `gorm:"client_id" json:"clientId"` // 瀹㈡埛id
 		Client           Client                     `gorm:"foreignKey:ClientId"`
 		InvoiceTypeId    int                        `gorm:"invoice_type_id" json:"invoiceTypeId"` // 鍙戠エ绫诲瀷id
@@ -28,18 +29,20 @@
 		CourierNumber    string                     `gorm:"courier_number" json:"courierNumber"`        // 鐗╂祦鍗曞彿
 		CourierCompanyId int                        `gorm:"courier_company_id" json:"courierCompanyId"` // 鐗╂祦鍏徃
 		CourierCompany   CourierCompany             `gorm:"foreignKey:CourierCompanyId"`
-		Products         []Product                  `json:"products" gorm:"many2many:invoice_product;"`
+		Products         []*Product                 `json:"products" gorm:"many2many:invoice_product;"`
+		CodeStandID      string                     `json:"codeStandID" gorm:"column:code_stand_id;type:varchar(255);comment:缂栫爜id"`
 	}
 
 	// InvoiceSearch 閿�鍞彂绁ㄦ悳绱㈡潯浠�
 	InvoiceSearch struct {
 		Invoice
-		Orm         *gorm.DB
-		QueryClass  constvar.InvoiceQueryClass
-		KeywordType constvar.InvoiceKeywordType
-		Keyword     string
-		PageNum     int
-		PageSize    int
+		Orm          *gorm.DB
+		QueryClass   constvar.InvoiceQueryClass
+		KeywordType  constvar.InvoiceKeywordType
+		Keyword      string
+		PageNum      int
+		PageSize     int
+		PrincipalIds []int
 	}
 )
 
@@ -53,10 +56,39 @@
 	}
 }
 
+func (slf *InvoiceSearch) SetSourceType(sourceType constvar.InvoiceSourceType) *InvoiceSearch {
+	slf.SourceType = sourceType
+	return slf
+}
+
+func (slf *InvoiceSearch) SetSourceId(sourceId int) *InvoiceSearch {
+	slf.SourceId = sourceId
+	return slf
+}
+
+func (slf *InvoiceSearch) SetPrincipalIds(principalIds []int) *InvoiceSearch {
+	slf.PrincipalIds = principalIds
+	return slf
+}
+
 func (slf *InvoiceSearch) build() *gorm.DB {
 	var db = slf.Orm.Model(&Invoice{})
 	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.Number != "" {
+		db.Where("number = ?", slf.Number)
+	}
+	if len(slf.PrincipalIds) > 0 {
+		db = db.Where("principal_id in ?", slf.PrincipalIds)
 	}
 
 	return db
@@ -89,6 +121,35 @@
 	return record, err
 }
 
+func (slf *InvoiceSearch) Count() (int64, error) {
+	var db = slf.build()
+	var total int64
+	err := db.Count(&total).Error
+	return total, err
+}
+
+func (slf *InvoiceSearch) MaxAutoIncr() (int, error) {
+	type Result struct {
+		Max int
+	}
+
+	var (
+		result Result
+		db     = slf.build()
+	)
+
+	err := db.Select("MAX(id) as max").Scan(&result).Error
+	if err != nil {
+		return result.Max, fmt.Errorf("max err: %v", err)
+	}
+	return result.Max, nil
+}
+
+func (slf *InvoiceSearch) SetNumber(number string) *InvoiceSearch {
+	slf.Number = number
+	return slf
+}
+
 func (slf *InvoiceSearch) SetId(id int) *InvoiceSearch {
 	slf.Id = id
 	return slf

--
Gitblit v1.8.0