From 5906a2067ff026db4a54817e479222a7e766ae1b Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期三, 02 八月 2023 15:39:04 +0800 Subject: [PATCH] 服务费管理增加查询条件 --- model/serviceFeeManage.go | 83 +++++++++++++++++++++++++++++++++-------- 1 files changed, 67 insertions(+), 16 deletions(-) diff --git a/model/serviceFeeManage.go b/model/serviceFeeManage.go index 16b6ab4..8ebf843 100644 --- a/model/serviceFeeManage.go +++ b/model/serviceFeeManage.go @@ -1,6 +1,7 @@ package model import ( + "aps_crm/constvar" "aps_crm/pkg/mysqlx" "gorm.io/gorm" "time" @@ -20,13 +21,13 @@ ServiceFeeManageSearch struct { ServiceFeeManage - - Orm *gorm.DB - Keyword string - OrderBy string - PageNum int - PageSize int - + Orm *gorm.DB + QueryClass constvar.ServiceFeeQueryClass + KeywordType constvar.ServiceFeeKeywordType + Keyword string + OrderBy string + PageNum int + PageSize int } ) @@ -46,14 +47,54 @@ func (slf *ServiceFeeManageSearch) build() *gorm.DB { var db = slf.Orm.Model(&ServiceFeeManage{}) - if slf.Keyword != "" { - db = db.Where("name LIKE ?", "%"+slf.Keyword+"%") - } if slf.Id != 0 { db.Where("id = ?", slf.Id) } if slf.ClientId != 0 { db.Where("client_id = ?", slf.ClientId) + } + switch slf.QueryClass { + case constvar.ServiceFeeQueryClassExpireLessThen60Days: + db = db.Where("latest_date > ? and latest_date < ?", time.Now(), time.Now().AddDate(0, 0, 60)) + case constvar.ServiceFeeQueryClassExpireLessThen30Days: + db = db.Where("latest_date > ? and latest_date < ?", time.Now(), time.Now().AddDate(0, 0, 30)) + case constvar.ServiceFeeQueryClassExpireAboutTo60Day: + db = db.Where("latest_date = ?", time.Now().AddDate(0, 0, -60)) + case constvar.ServiceFeeQueryClassExpireAboutTo30Day: + db = db.Where("latest_date = ?", time.Now().AddDate(0, 0, -30)) + case constvar.ServiceFeeQueryClassExpired: + db = db.Where("latest_date < ?", time.Now()) + case constvar.ServiceFeeQueryClassNoService: + db = db.Where("latest_date < ?", time.Now().AddDate(0, 0, -60)) + + } + + switch slf.KeywordType { + case constvar.ServiceFeeKeywordCustomerName: + db.Joins("left join clients on clients.id = service_fee_manage.client_id") + db = db.Where("clients.name = ?", slf.Keyword) + case constvar.ServiceFeeKeywordCustomerType: + db.Joins("left join clients on clients.id = service_fee_manage.client_id") + db = db.Where("clients.client_type_id = ?", slf.Keyword) + case constvar.ServiceFeeKeywordSalesPrincipal: + db.Joins("left join clients on clients.id = service_fee_manage.client_id") + db = db.Where("clients.member_id = ?", slf.Keyword) + case constvar.ServiceFeeKeywordCustomerScale: + db.Joins("left join clients on clients.id = service_fee_manage.client_id") + db = db.Where("clients.enterprise_scale_id = ?", slf.Keyword) + case constvar.ServiceFeeKeywordClientLevel: + db.Joins("left join clients on clients.id = service_fee_manage.client_id") + db = db.Where("clients.client_level_id = ?", slf.Keyword) + case constvar.ServiceFeeKeywordCustomerNo: + db.Joins("left join clients on clients.id = service_fee_manage.client_id") + db = db.Where("clients.number = ?", slf.Keyword) + case constvar.ServiceFeeKeywordCustomerStatus: + db.Joins("left join clients on clients.id = service_fee_manage.client_id") + db = db.Where("clients.client_status_id = ?", slf.Keyword) + case constvar.ServiceFeeKeywordServiceEndDate: + db = db.Where("latest_date = ?", slf.Keyword) + case constvar.ServiceFeeKeywordProductName: + //todo } return db @@ -76,6 +117,21 @@ func (slf *ServiceFeeManageSearch) SetId(id int) *ServiceFeeManageSearch { slf.Id = id + return slf +} + +func (slf *ServiceFeeManageSearch) SetKeywordType(keyword constvar.ServiceFeeKeywordType) *ServiceFeeManageSearch { + slf.KeywordType = keyword + return slf +} + +func (slf *ServiceFeeManageSearch) SetQueryClass(queryClass constvar.ServiceFeeQueryClass) *ServiceFeeManageSearch { + slf.QueryClass = queryClass + return slf +} + +func (slf *ServiceFeeManageSearch) SetKeyword(keyword string) *ServiceFeeManageSearch { + slf.Keyword = keyword return slf } @@ -105,11 +161,6 @@ return records, total, err } -func (slf *ServiceFeeManageSearch) SetKeyword(keyword string) *ServiceFeeManageSearch { - slf.Keyword = keyword - return slf -} - func (slf *ServiceFeeManageSearch) SetPage(page, size int) *ServiceFeeManageSearch { slf.PageNum, slf.PageSize = page, size return slf @@ -118,4 +169,4 @@ func (slf *ServiceFeeManageSearch) SetOrder(order string) *ServiceFeeManageSearch { slf.OrderBy = order return slf -} \ No newline at end of file +} -- Gitblit v1.8.0