From d557ed582308257aaefcbcfe2bada1e195d83a91 Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期二, 08 八月 2023 19:24:30 +0800 Subject: [PATCH] fix --- model/request/salesLeads.go | 2 api/v1/salesLeads.go | 2 model/salesLeads.go | 70 ++++++++++++++++++---------------- service/salesLeads.go | 4 +- model/request/client.go | 2 docs/swagger.yaml | 12 ++++-- docs/docs.go | 10 +++-- docs/swagger.json | 10 +++-- 8 files changed, 62 insertions(+), 50 deletions(-) diff --git a/api/v1/salesLeads.go b/api/v1/salesLeads.go index 228f6a3..bd501e9 100644 --- a/api/v1/salesLeads.go +++ b/api/v1/salesLeads.go @@ -151,7 +151,7 @@ return } - salesLeadss, total, errCode := salesLeadsService.GetSalesLeadsList(params.Page, params.PageSize, params.Keyword) + salesLeadss, total, errCode := salesLeadsService.GetSalesLeadsList(params.Page, params.PageSize, params.SearchMap) if errCode != ecode.OK { ctx.Fail(errCode) return diff --git a/docs/docs.go b/docs/docs.go index 0a3b8b5..7e7d830 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -13572,7 +13572,7 @@ "type": "integer" }, "search_map": { - "description": "鎼滅储鏉′欢: map[string]interface{}{\"name\": \"xxx\"}; \"not_contact\": 瓒呰繃15澶╂湭鑱旂郴; \"public_sea\": 鍏捣瀹㈡埛", + "description": "鎼滅储鏉′欢: map[string]interface{}{\"name\": \"xxx\"}; \"name\": 瀹㈡埛鍚嶇О; \"number\": 鍏捣瀹㈡埛", "type": "object", "additionalProperties": true } @@ -13747,9 +13747,6 @@ "request.GetSalesLeadsList": { "type": "object", "properties": { - "keyword": { - "type": "string" - }, "page": { "description": "椤电爜", "type": "integer" @@ -13757,6 +13754,11 @@ "pageSize": { "description": "姣忛〉澶у皬", "type": "integer" + }, + "search_map": { + "description": "鎼滅储鏉′欢: map[string]interface{}{\"name\": \"xxx\"} {\"client_name\": \"瀹㈡埛鍚嶇О\", \"number\": \"閿�鍞嚎绱㈢紪鍙穃", \"contact_name\": \"鑱旂郴浜哄鍚峔", \"phone\": \"鎵嬫満鍙风爜\", \"sales_resources\": \"鍟嗘満鏉ユ簮\", \"city\": \"鍩庡競\", \"province\": \"鐪佷唤\", \"member_name\": \"璐熻矗浜篭"}", + "type": "object", + "additionalProperties": true } } }, diff --git a/docs/swagger.json b/docs/swagger.json index 202697f..f9dbb35 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -13560,7 +13560,7 @@ "type": "integer" }, "search_map": { - "description": "鎼滅储鏉′欢: map[string]interface{}{\"name\": \"xxx\"}; \"not_contact\": 瓒呰繃15澶╂湭鑱旂郴; \"public_sea\": 鍏捣瀹㈡埛", + "description": "鎼滅储鏉′欢: map[string]interface{}{\"name\": \"xxx\"}; \"name\": 瀹㈡埛鍚嶇О; \"number\": 鍏捣瀹㈡埛", "type": "object", "additionalProperties": true } @@ -13735,9 +13735,6 @@ "request.GetSalesLeadsList": { "type": "object", "properties": { - "keyword": { - "type": "string" - }, "page": { "description": "椤电爜", "type": "integer" @@ -13745,6 +13742,11 @@ "pageSize": { "description": "姣忛〉澶у皬", "type": "integer" + }, + "search_map": { + "description": "鎼滅储鏉′欢: map[string]interface{}{\"name\": \"xxx\"} {\"client_name\": \"瀹㈡埛鍚嶇О\", \"number\": \"閿�鍞嚎绱㈢紪鍙穃", \"contact_name\": \"鑱旂郴浜哄鍚峔", \"phone\": \"鎵嬫満鍙风爜\", \"sales_resources\": \"鍟嗘満鏉ユ簮\", \"city\": \"鍩庡競\", \"province\": \"鐪佷唤\", \"member_name\": \"璐熻矗浜篭"}", + "type": "object", + "additionalProperties": true } } }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 5022361..37ccd6b 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -2828,8 +2828,8 @@ type: integer search_map: additionalProperties: true - description: '鎼滅储鏉′欢: map[string]interface{}{"name": "xxx"}; "not_contact": - 瓒呰繃15澶╂湭鑱旂郴; "public_sea": 鍏捣瀹㈡埛' + description: '鎼滅储鏉′欢: map[string]interface{}{"name": "xxx"}; "name": 瀹㈡埛鍚嶇О; "number": + 鍏捣瀹㈡埛' type: object type: object request.GetContactList: @@ -2948,14 +2948,18 @@ type: object request.GetSalesLeadsList: properties: - keyword: - type: string page: description: 椤电爜 type: integer pageSize: description: 姣忛〉澶у皬 type: integer + search_map: + additionalProperties: true + description: '鎼滅储鏉′欢: map[string]interface{}{"name": "xxx"} {"client_name": + "瀹㈡埛鍚嶇О", "number": "閿�鍞嚎绱㈢紪鍙�", "contact_name": "鑱旂郴浜哄鍚�", "phone": "鎵嬫満鍙风爜", "sales_resources": + "鍟嗘満鏉ユ簮", "city": "鍩庡競", "province": "鐪佷唤", "member_name": "璐熻矗浜�"}' + type: object type: object request.GetSalesRefundList: properties: diff --git a/model/request/client.go b/model/request/client.go index c0e723a..d989869 100644 --- a/model/request/client.go +++ b/model/request/client.go @@ -30,7 +30,7 @@ type GetClientList struct { PageInfo - SearchMap map[string]interface{} `json:"search_map"` // 鎼滅储鏉′欢: map[string]interface{}{"name": "xxx"}; "not_contact": 瓒呰繃15澶╂湭鑱旂郴; "public_sea": 鍏捣瀹㈡埛 + SearchMap map[string]interface{} `json:"search_map"` // 鎼滅储鏉′欢: map[string]interface{}{"name": "xxx"}; "name": 瀹㈡埛鍚嶇О; "number": 鍏捣瀹㈡埛 } type DeleteClient struct { diff --git a/model/request/salesLeads.go b/model/request/salesLeads.go index d664c8b..d4684b2 100644 --- a/model/request/salesLeads.go +++ b/model/request/salesLeads.go @@ -25,7 +25,7 @@ type GetSalesLeadsList struct { PageInfo - Keyword string `json:"keyword"` + SearchMap map[string]interface{} `json:"search_map"` // 鎼滅储鏉′欢: map[string]interface{}{"name": "xxx"} {"name": "瀹㈡埛鍚嶇О", "number": "閿�鍞嚎绱㈢紪鍙�", "contact_name": "鑱旂郴浜哄鍚�", "phone": "鎵嬫満鍙风爜", "sales_resources": "鍟嗘満鏉ユ簮", "city": "鍩庡競", "province": "鐪佷唤", "member_name": "璐熻矗浜�"} } type DeleteSalesLeads struct { diff --git a/model/salesLeads.go b/model/salesLeads.go index 6e9f65e..b854d46 100644 --- a/model/salesLeads.go +++ b/model/salesLeads.go @@ -15,7 +15,9 @@ ContactPhone string `json:"contact_phone" gorm:"column:contact_phone;type:varchar(255);comment:鑱旂郴浜虹數璇�"` ContactPosition string `json:"contact_position" gorm:"column:contact_position;type:varchar(255);comment:鑱旂郴浜鸿亴浣�"` SalesSourcesId int `json:"sales_sources_id" gorm:"column:sales_sources_id;type:int(11);comment:鍟嗘満鏉ユ簮ID"` + SalesSources SalesSources `json:"-" gorm:"foreignKey:SalesSourcesId"` MemberId int `json:"member_id" gorm:"column:member_id;type:int(11);comment:閿�鍞礋璐d汉ID"` + Member User `json:"-" gorm:"foreignKey:MemberId"` SalesStatus constvar.SalesStatus `json:"sales_status" gorm:"column:sales_status;type:int(11);comment:閿�鍞姸鎬�"` Desc string `json:"desc" gorm:"column:desc;type:varchar(255);comment:澶囨敞"` Reason string `json:"reason" gorm:"column:reason;type:text;comment:澶辫触鍘熷洜"` @@ -27,11 +29,11 @@ SalesLeadsSearch struct { SalesLeads - Orm *gorm.DB - Keyword string - OrderBy string - PageNum int - PageSize int + Orm *gorm.DB + SearchMap map[string]interface{} + OrderBy string + PageNum int + PageSize int } ) @@ -51,12 +53,6 @@ func (slf *SalesLeadsSearch) build() *gorm.DB { var db = slf.Orm.Model(&SalesLeads{}) - if slf.Keyword != "" { - db = db.Where("name LIKE ?", "%"+slf.Keyword+"%") - } - if slf.Keyword != "" { - db = db.Where("name LIKE ?", "%"+slf.Keyword+"%") - } if slf.Id != 0 { db = db.Where("id = ?", slf.Id) } @@ -64,28 +60,36 @@ db = db.Where("name = ?", slf.Name) } - if slf.Number != "" { - db = db.Where("number = ?", slf.Number) - } + if len(slf.SearchMap) > 0 { + for key, value := range slf.SearchMap { + switch v := value.(type) { + case string: + if key == "number" || key == "contact_name" || key == "contact_phone" || key == "name" { + db = db.Where(key+" LIKE ?", "%"+v+"%") + } - if slf.ContactName != "" { - db = db.Where("contact_name = ?", slf.ContactName) - } + if key == "city" { + db = db.Joins("City").Where("City.name LIKE ?", "%"+v+"%") + } - if slf.ContactPhone != "" { - db = db.Where("contact_phone = ?", slf.ContactPhone) - } + if key == "province" { + db = db.Joins("Province").Where("Province.name LIKE ?", "%"+v+"%") + } - if slf.ContactPosition != "" { - db = db.Where("contact_position = ?", slf.ContactPosition) - } + if key == "sales_sources" { + db = db.Joins("SalesSources").Where("SalesSources.name LIKE ?", "%"+v+"%") + } - if slf.SalesSourcesId != 0 { - db = db.Where("sales_sources_id = ?", slf.SalesSourcesId) - } + if key == "member_name" { + db = db.Joins("Member").Where("Member.username LIKE ?", "%"+v+"%") + } - if slf.MemberId != 0 { - db = db.Where("member_id = ?", slf.MemberId) + case int: + if key == "member_id" { + db = db.Where("member_id = ?", v) + } + } + } } return db @@ -149,11 +153,6 @@ return } -func (slf *SalesLeadsSearch) SetKeyword(keyword string) *SalesLeadsSearch { - slf.Keyword = keyword - return slf -} - func (slf *SalesLeadsSearch) SetPage(page, size int) *SalesLeadsSearch { slf.PageNum, slf.PageSize = page, size return slf @@ -172,3 +171,8 @@ slf.Orm = slf.Orm.Where("id in (?)", ids) return slf } + +func (slf *SalesLeadsSearch) SetSearchMap(data map[string]interface{}) *SalesLeadsSearch { + slf.SearchMap = data + return slf +} diff --git a/service/salesLeads.go b/service/salesLeads.go index f43236b..d0d1525 100644 --- a/service/salesLeads.go +++ b/service/salesLeads.go @@ -40,9 +40,9 @@ return ecode.OK } -func (SalesLeadsService) GetSalesLeadsList(page, pageSize int, keyword string) ([]*model.SalesLeads, int64, int) { +func (SalesLeadsService) GetSalesLeadsList(page, pageSize int, data map[string]interface{}) ([]*model.SalesLeads, int64, int) { // get contact list - contacts, total, err := model.NewSalesLeadsSearch(nil).SetKeyword(keyword).SetPage(page, pageSize).FindAll() + contacts, total, err := model.NewSalesLeadsSearch(nil).SetPage(page, pageSize).SetSearchMap(data).FindAll() if err != nil { return nil, 0, ecode.SalesLeadsListErr } -- Gitblit v1.8.0