From d8c708a30d938ceb87348257add9dc10926044df Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期二, 24 十月 2023 20:08:02 +0800 Subject: [PATCH] 编码规则需求功能开发2 --- model/invoice.go | 34 ++++++++++++++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-) diff --git a/model/invoice.go b/model/invoice.go index 48ddcd2..0db64fa 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 @@ -29,6 +30,7 @@ CourierCompanyId int `gorm:"courier_company_id" json:"courierCompanyId"` // 鐗╂祦鍏徃 CourierCompany CourierCompany `gorm:"foreignKey:CourierCompanyId"` Products []*Product `json:"products" gorm:"many2many:invoice_product;"` + CodeStandID string `json:"codeStandID" gorm:"column:code_stand_id;type:varchar(255);comment:缂栫爜id"` } // InvoiceSearch 閿�鍞彂绁ㄦ悳绱㈡潯浠� @@ -76,6 +78,9 @@ if slf.SourceId > 0 { db = db.Where("source_id = ?", slf.SourceId) } + if slf.Number != "" { + db.Where("number = ?", slf.Number) + } return db } @@ -107,6 +112,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