From 250cbfa1ddcb3cf38e0d0505c1c7e282b940d25b Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期五, 13 十月 2023 10:30:05 +0800
Subject: [PATCH] admin user id 转crm user id
---
model/salesRefund.go | 55 +++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 49 insertions(+), 6 deletions(-)
diff --git a/model/salesRefund.go b/model/salesRefund.go
index 0d942a0..c68a0e9 100644
--- a/model/salesRefund.go
+++ b/model/salesRefund.go
@@ -15,16 +15,17 @@
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"` // 浠风◣鍚堣
@@ -40,6 +41,7 @@
PageNum int
PageSize int
Preload bool
+ Ids []int
}
)
@@ -53,16 +55,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 != "" {
@@ -107,11 +127,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) {
@@ -129,7 +157,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
}
@@ -138,6 +166,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