From 9a7e0a7da01a9f9625ceaca0c61a59c540c6438f Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期五, 18 八月 2023 17:32:10 +0800 Subject: [PATCH] fix --- model/salesRefund.go | 41 ++++++++++++++++++++++++++++++++++------- 1 files changed, 34 insertions(+), 7 deletions(-) diff --git a/model/salesRefund.go b/model/salesRefund.go index c3bea82..233aa72 100644 --- a/model/salesRefund.go +++ b/model/salesRefund.go @@ -15,16 +15,16 @@ ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:瀹㈡埛id"` Client Client `json:"client" gorm:"foreignKey:ClientId"` Number string `json:"number" gorm:"column:number;type:varchar(255);comment:閫�娆惧崟鍙�"` - SourceType constvar.RefundSourceType `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 + SourceType constvar.RefundSourceType `gorm:"column:source_type;type:int;not null;default 0;comment:鏉ユ簮绫诲瀷锛�1閿�鍞��璐э級" json:"sourceType"` // 鏉ユ簮绫诲瀷锛�1閿�鍞��璐э級 + SourceId int `gorm:"column:source_id;type:int;not null;default 0;comment:婧愬崟id " json:"sourceId"` // 婧愬崟id MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"` Member User `json:"member" gorm:"foreignKey:MemberId"` - RefundDate string `json:"refundDate" gorm:"column:refund_date;type:datetime;comment:閫�娆炬棩鏈�"` + RefundDate string `json:"refundDate" gorm:"column:refund_date;type:varchar(255);comment:閫�娆炬棩鏈�"` PaymentTypeId int `gorm:"column:payment_type_id;type:int;not null;default 0;comment:鏀舵鏂瑰紡ID" json:"paymentTypeId"` // 鏀舵鏂瑰紡ID PaymentType PaymentType `gorm:"foreignKey:PaymentTypeId" json:"paymentType"` BankAccountId int `gorm:"column:bank_account_id;type:int;not null;default 0;comment:璐︽埛id" json:"bankAccountId"` // 璐︽埛id BankAccount BankAccount `gorm:"foreignKey:BankAccountId" json:"bankAccount"` - IsInvoice int `json:"isInvoice" gorm:"column:is_invoice;type:int;comment:鏄惁寮�绁�"` + IsInvoice string `json:"isInvoice" gorm:"column:is_invoice;type:varchar(255);comment:鏄惁寮�绁�"` Reason string `json:"reason" gorm:"column:reason;type:varchar(255);comment:閫�娆惧師鍥�"` Products []*Product `json:"products" gorm:"many2many:salesRefund_product;"` AmountTotal decimal.Decimal `gorm:"column:amount_total;type:decimal(12,2);comment:浠风◣鍚堣" json:"amountTotal"` // 浠风◣鍚堣 @@ -33,7 +33,6 @@ SalesRefundSearch struct { SalesRefund - Orm *gorm.DB KeywordType constvar.SalesRefundKeywordType Keyword string @@ -41,6 +40,7 @@ PageNum int PageSize int Preload bool + Ids []int } ) @@ -58,6 +58,10 @@ var db = slf.Orm.Model(&SalesRefund{}) if slf.Id != 0 { db = db.Where("id = ?", slf.Id) + } + + if len(slf.Ids) != 0 { + db = db.Where("id in ?", slf.Ids) } if slf.Preload { @@ -108,11 +112,19 @@ return db.Updates(record).Error } -func (slf *SalesRefundSearch) Find() (*SalesRefund, error) { +func (slf *SalesRefundSearch) First() (*SalesRefund, error) { var db = slf.build() var record = new(SalesRefund) err := db.First(record).Error return record, err +} + +func (slf *SalesRefundSearch) Find() ([]*SalesRefund, error) { + var db = slf.build() + var records = make([]*SalesRefund, 0) + + err := db.Find(&records).Error + return records, err } func (slf *SalesRefundSearch) FindAll() ([]*SalesRefund, int64, error) { @@ -130,7 +142,7 @@ db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) } - err := db.Preload("Products").Find(&records).Error + err := db.Preload("BankAccount").Preload("PaymentType").Preload("Member").Preload("Products").Order("id desc").Find(&records).Error return records, total, err } @@ -139,6 +151,21 @@ return slf } +func (slf *SalesRefundSearch) SetIds(id []int) *SalesRefundSearch { + slf.Ids = id + return slf +} + +func (slf *SalesRefundSearch) SetSourceType(sourceType constvar.RefundSourceType) *SalesRefundSearch { + slf.SourceType = sourceType + return slf +} + +func (slf *SalesRefundSearch) SetSourceId(id int) *SalesRefundSearch { + slf.SourceId = id + return slf +} + func (slf *SalesRefundSearch) SetPreload(preload bool) *SalesRefundSearch { slf.Preload = preload return slf -- Gitblit v1.8.0