From d4bf53dd19a45ef09a367babcf7a2ac04ae1d08f Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期二, 17 十月 2023 14:31:31 +0800 Subject: [PATCH] bug修改 --- model/salesRefund.go | 69 ++++++++++++++++++++++++++++++++-- 1 files changed, 64 insertions(+), 5 deletions(-) diff --git a/model/salesRefund.go b/model/salesRefund.go index c5519c9..380aa9a 100644 --- a/model/salesRefund.go +++ b/model/salesRefund.go @@ -15,19 +15,21 @@ 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 + Source SalesReturn `gorm:"foreignKey:SourceId" json:"Source"` 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"` // 浠风◣鍚堣 + CodeStandID string `json:"codeStandID" gorm:"column:code_stand_id;type:varchar(255);comment:缂栫爜id"` CrmModel } @@ -40,6 +42,8 @@ PageNum int PageSize int Preload bool + Ids []int + MemberIds []int } ) @@ -53,16 +57,34 @@ } } +func (slf *SalesRefundSearch) SetOrm(tx *gorm.DB) *SalesRefundSearch { + slf.Orm = tx + return slf +} + func (slf *SalesRefundSearch) build() *gorm.DB { 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.SourceType != 0 { + db = db.Where("source_type = ?", slf.SourceType) + } + + if slf.SourceId != 0 { + db = db.Where("source_id = ?", slf.SourceId) + } + if slf.Preload { db = db.Preload("Client"). Preload("PaymentType"). Preload("BankAccount"). + Preload("Source"). Preload("Products") } if slf.KeywordType != "" { @@ -89,6 +111,10 @@ } } + if len(slf.MemberIds) > 0 { + db = db.Where("sales_refund.member_id in ?", slf.MemberIds) + } + return db } @@ -107,11 +133,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) { @@ -138,6 +172,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 @@ -162,3 +211,13 @@ slf.OrderBy = order return slf } + +func (slf *SalesRefundSearch) UpdateByMap(data map[string]interface{}) error { + var db = slf.build() + return db.Updates(data).Error +} + +func (slf *SalesRefundSearch) SetMemberIds(memberIds []int) *SalesRefundSearch { + slf.MemberIds = memberIds + return slf +} -- Gitblit v1.8.0