From 736516bc12f07f7b9a8e85fb37f8bde74f7e59e0 Mon Sep 17 00:00:00 2001 From: kanade Date: Fri, 27 May 2022 16:57:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BF=94=E5=9B=9E=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/api/mobile/goods/common_list.go | 31 ++++++++++++++++--- internal/v2/model/search_ali/searchByAliES.go | 5 ++- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/internal/api/mobile/goods/common_list.go b/internal/api/mobile/goods/common_list.go index 477a9b4..0248d4a 100755 --- a/internal/api/mobile/goods/common_list.go +++ b/internal/api/mobile/goods/common_list.go @@ -107,13 +107,20 @@ func QueryGoodsListByComprehension(c *gin.Context) { Expression: clause.Expr{SQL: "FIELD(id,?)", Vars: []interface{}{ids}, WithoutParentheses: true}}) q3 = q3.Where("id in (?) and sale_publish = 1 and is_sale = 1", ids) } - findByKeyWord(q3, p.Keyword, &goodsList, p.Page, p.IsSale, false) + filters := map[string]interface{}{} + if p.SecondCategoryID > 0 { + filters["brand_id"] = p.BrandID + } + if p.SecondCategoryID > 0 { + filters["second_category_id"] = p.SecondCategoryID + } + findByKeyWord(q3, p.Keyword, filters, &goodsList, p.Page, p.IsSale, false) back.Suc(c, "", GetGoodsRespByInfoList(goodsList, p.UserId, p.IsSale)) } -func findByKeyWord(q *gorm2.DB, str string, data *[]goods.Information, page uint, isSale bool, isCondition bool) { +func findByKeyWord(q *gorm2.DB, str string, filters map[string]interface{}, data *[]goods.Information, page uint, isSale bool, isCondition bool) { if str != "" { - gl, _, _ := search_ali.SearchByAliES(str, isSale, 20, int(page)) + gl, _, _ := search_ali.SearchByAliES(str, filters, isSale, 20, int(page)) q = q.Where("a.id in (?)", gl) if !isCondition { q = q.Clauses(clause.OrderBy{ @@ -167,7 +174,14 @@ func QueryGoodsListBySalesVolume(c *gin.Context) { sub := mysql2.Db.Table((&ac2.ActivityGoods{}).TableName()).Select("goods_id").Where("activity_id = ?", p.ActivityID) q3 = q3.Where("id in (?) and sale_publish = 1 and is_sale = 1", sub) } - findByKeyWord(q3, p.Keyword, &goodsList, p.Page, p.IsSale, true) + filters := map[string]interface{}{} + if p.SecondCategoryID > 0 { + filters["brand_id"] = p.BrandID + } + if p.SecondCategoryID > 0 { + filters["second_category_id"] = p.SecondCategoryID + } + findByKeyWord(q3, p.Keyword, filters, &goodsList, p.Page, p.IsSale, true) back.Suc(c, "", GetGoodsRespByInfoList(goodsList, p.UserId, p.IsSale)) } @@ -204,7 +218,14 @@ func QueryGoodsListByDiscountPrice(c *gin.Context) { q3 = q3.Where("id in (?) and sale_publish = 1 and is_sale= 1", sub) } - findByKeyWord(q3, p.Keyword, &goodsList, p.Page, p.IsSale, true) + filters := map[string]interface{}{} + if p.SecondCategoryID > 0 { + filters["brand_id"] = p.BrandID + } + if p.SecondCategoryID > 0 { + filters["second_category_id"] = p.SecondCategoryID + } + findByKeyWord(q3, p.Keyword, filters, &goodsList, p.Page, p.IsSale, true) back.Suc(c, "", GetGoodsRespByInfoList(goodsList, p.UserId, p.IsSale)) } diff --git a/internal/v2/model/search_ali/searchByAliES.go b/internal/v2/model/search_ali/searchByAliES.go index 875e0c5..4b2c4b1 100644 --- a/internal/v2/model/search_ali/searchByAliES.go +++ b/internal/v2/model/search_ali/searchByAliES.go @@ -139,7 +139,7 @@ func PushMessage() { } -func SearchByAliES(keyWords string, isSale bool, limit, page int) (goodsList []uint, total uint, err error) { +func SearchByAliES(keyWords string, filters map[string]interface{}, isSale bool, limit, page int) (goodsList []uint, total uint, err error) { // 创建请求用客户端实例 // Endpoint 为 要访问服务的区域域名. // AccessKeyId 及AccessKeySecret 用于构造鉴权信息. @@ -162,6 +162,9 @@ func SearchByAliES(keyWords string, isSale bool, limit, page int) (goodsList []u if isSale { query = fmt.Sprintf("config=start:%v,hit:%v,format:fulljson&&query=default:'%s'&&filter=sale_publish=1", limit*(page), limit, keyWords) } + for key, value := range filters { + query += fmt.Sprintf(" AND %s=%v", key, value) + } // requestParams 信息 requestParams := map[string]interface{}{ "query": query,