Browse Source

no message

master
Shuixiang 4 years ago
parent
commit
07b598e6fe
  1. 6
      app/Http/Controllers/Api/AgentProductController.php

6
app/Http/Controllers/Api/AgentProductController.php

@ -28,14 +28,13 @@ class AgentProductController extends Controller
$lat = $formData['lat'] ?? 0;
$lng = $formData['lng'] ?? 0;
$list = AgentProductView::list($this->agent_id)->addSelect('latitude', 'logitude', 'address');
$list = AgentProductView::list($this->agent_id);
if ($category_id) {
$list = $list->whereIn('category_id', [$category_id, ...$this->get_category_child_ids($category_id)]);
}
// 距离排序,TODO 优化
if ($type == 4) {
$list = $list->addSelect(DB::raw(<<<SQL
$list = $list->addSelect('latitude', 'logitude', 'address', DB::raw(<<<SQL
round(
(((6371.393 * 2) * asin(
sqrt((
@ -47,7 +46,6 @@ round(
pow( sin((((( {$lng} * 3.1415926 ) / 180 ) - (( `logitude` * pi()) / 180 )) / 2 )), 2 ))))
)) * 1000),0) AS `distance_m`
SQL));
}
$fields = ['id', 'sale', 'updated_at', 'price', 'distance_m']; //排序字段 TODO 还有距离排序

Loading…
Cancel
Save