Commit 9809db81 authored by luhongguang's avatar luhongguang

update:es 编辑数据

parent 87b069d5
...@@ -124,7 +124,6 @@ class ElasticGoodService ...@@ -124,7 +124,6 @@ class ElasticGoodService
$sortList = [ $sortList = [
["price_sort" => "asc", "total_amount_sold" => "desc"], ["price_sort" => "asc", "total_amount_sold" => "desc"],
//todo 距离排序
["total_amount_sold" => "desc"], ["total_amount_sold" => "desc"],
["price_sort" => "asc"], ["price_sort" => "asc"],
]; ];
...@@ -194,7 +193,7 @@ class ElasticGoodService ...@@ -194,7 +193,7 @@ class ElasticGoodService
$result["list"][$key]["shop_location"] = $source["_source"]["shop_location"]; $result["list"][$key]["shop_location"] = $source["_source"]["shop_location"];
$result["list"][$key]["life_account_name"] = $source["_source"]["life_account_name"]; $result["list"][$key]["life_account_name"] = $source["_source"]["life_account_name"];
$result["list"][$key]["life_account_icon"] = $source["_source"]["life_account_icon"]; $result["list"][$key]["life_account_icon"] = $source["_source"]["life_account_icon"];
$result["list"][$key]["distance"] = empty($source["sort"][2]) ? "" : round($source["sort"][2], 2)."km"; $result["list"][$key]["distance"] = empty($source["sort"][2]) ? "" : round($source["sort"][2], 2) . "km";
} }
} }
...@@ -202,4 +201,23 @@ class ElasticGoodService ...@@ -202,4 +201,23 @@ class ElasticGoodService
return $result ? $result : (object)$result; return $result ? $result : (object)$result;
} }
/**
* id 在es数据里是否存在
* @param $skuId
* @return bool
*/
public static function isHaveById($skuId)
{
$data["query"]["bool"]["must"] = [
["term" => ["_id" => $skuId]],
];
$elasticClient = ElasticUtil::getInstance();
$res = $elasticClient->searchDoc(self::INDEX, $data);
if (!empty($res["hits"]["total"]["value"])) {
return $res["hits"]["total"]["value"] > 0;
}
return false;
}
} }
\ No newline at end of file
...@@ -951,7 +951,13 @@ class GoodsService ...@@ -951,7 +951,13 @@ class GoodsService
"shop_location" => $subShop["latitude"].",".$subShop["longitude"], "shop_location" => $subShop["latitude"].",".$subShop["longitude"],
], ],
]; ];
ElasticGoodService::updateDoc($goodsSkuId, $data); $isHaveId = ElasticGoodService::isHaveById($goodsSkuId);
if ($isHaveId) {
ElasticGoodService::updateDoc($goodsSkuId, $data);
} else {
$data = $data["doc"];
ElasticGoodService::indexDoc($goodsSkuId, $data);
}
} }
} }
} }
......
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 to comment