Commit afadd21c by mushishixian

修复

parent 3c05f0a9
Showing with 32 additions and 6 deletions
...@@ -165,10 +165,34 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType, sort ...@@ -165,10 +165,34 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType, sort
return return
} }
index := configs.ESSetting.GoodsIndexName index := configs.ESSetting.GoodsIndexName
//如果是大陆收货(type=1),就要包含专卖和自营 var ziyingGoodsMapList []GoodsMap
//如果是大陆收货(type=1),就要包含专卖,其中自营单独查
if deliveryType == 1 { if deliveryType == 1 {
index = index + ",zhuanmai,liexin_ziying" //先去自营查一遍
ziyingGoodsMapList, err = search("liexin_ziying", bomId, bomItems, deliveryType, sort, client, rawSearch)
if err != nil {
return nil, err
} }
index = index + ",zhuanmai"
}
//查完以后去除已经匹配的自营商品,然后去搜索联营的商品
bomItems = removeZiyingMatchBomItem(ziyingGoodsMapList, bomItems)
lianyingGoodsMapList, _ := search(index, bomId, bomItems, deliveryType, sort, client, rawSearch)
goodsMapList = append(ziyingGoodsMapList, lianyingGoodsMapList...)
return
}
func removeZiyingMatchBomItem(ziyingGoodsMapList []GoodsMap, bomItems []model.BomItem) (result []model.BomItem) {
for _, bomItem := range bomItems {
if !checkInGoodsMap(bomItem, ziyingGoodsMapList) {
result = append(result, bomItem)
}
}
return
}
func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sort int, client *es.Client, rawSearch bool) (goodsMapList []GoodsMap, err error) {
//先去自营查一遍
search := client.MultiSearch().Index(index) search := client.MultiSearch().Index(index)
//多重搜索,第一次先去精确匹配 //多重搜索,第一次先去精确匹配
for _, bom := range bomItems { for _, bom := range bomItems {
...@@ -180,7 +204,7 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType, sort ...@@ -180,7 +204,7 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType, sort
} }
} }
//构建一个goods_name对应的bomItems列表 //构建一个goods_name对应的bomItems列表
searchRequest := getSearchParams(bom.GoodsName, bom.BrandName, sort, bom.Number, rawSearch) searchRequest := getSearchParams(index, bom.GoodsName, bom.BrandName, sort, bom.Number, rawSearch)
search.Add(searchRequest) search.Add(searchRequest)
} }
res, err := search.Do(context.Background()) res, err := search.Do(context.Background())
...@@ -220,9 +244,9 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType, sort ...@@ -220,9 +244,9 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType, sort
} }
//构建请求参数 //构建请求参数
func getSearchParams(goodsName, brandName string, sort, number int, flag bool) (searchRequest *es.SearchRequest) { func getSearchParams(index, goodsName, brandName string, sort, number int, flag bool) (searchRequest *es.SearchRequest) {
query := getTermQuery(goodsName, brandName, number, flag) query := getTermQuery(goodsName, brandName, number, flag)
source := es.NewSearchSource().IndexBoost("liexin_ziying", 2).Query(query) source := es.NewSearchSource().Query(query)
if sort == 1 { if sort == 1 {
source.Sort("sort", false) source.Sort("sort", false)
source.Sort("stock", false) source.Sort("stock", false)
...@@ -230,7 +254,9 @@ func getSearchParams(goodsName, brandName string, sort, number int, flag bool) ( ...@@ -230,7 +254,9 @@ func getSearchParams(goodsName, brandName string, sort, number int, flag bool) (
} }
//要去判断sort,sort=2是按照价格排序 //要去判断sort,sort=2是按照价格排序
if sort == 2 { if sort == 2 {
if index != "liexin_ziying" {
source.Sort("single_price_sort", false) source.Sort("single_price_sort", false)
}
source.Sort("single_price", true) source.Sort("single_price", true)
//sort=3是按照库存排序 //sort=3是按照库存排序
} else if sort == 3 { } else if sort == 3 {
...@@ -264,7 +290,7 @@ func getTermQuery(goodsName, brandName string, number int, flag bool) (query *es ...@@ -264,7 +290,7 @@ func getTermQuery(goodsName, brandName string, number int, flag bool) (query *es
field := "auto_goods_name" field := "auto_goods_name"
query = query.Must(es.NewTermQuery(field, goodsName)) query = query.Must(es.NewTermQuery(field, goodsName))
} }
query = query.Filter(es.NewTermQuery("status", 1)) //query = query.Filter(es.NewTermQuery("status", 1))
//query = query.Filter(es.NewRangeQuery("single_price").Gt(0)) //query = query.Filter(es.NewRangeQuery("single_price").Gt(0))
//src, err := query.Source() //src, err := query.Source()
//if err != nil { //if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment