|
|
@ -31,16 +31,38 @@ class LocationService implements LocationServiceInterface |
|
|
$cityIds = Market::query()->pluck('city_id'); |
|
|
$cityIds = Market::query()->pluck('city_id'); |
|
|
$res = Area::query()->with('markets')->whereIn('id',$cityIds)->get(); |
|
|
$res = Area::query()->with('markets')->whereIn('id',$cityIds)->get(); |
|
|
foreach ($res as &$v){ |
|
|
foreach ($res as &$v){ |
|
|
|
|
|
|
|
|
|
|
|
if(!empty($lng) && !empty($lat)) { |
|
|
|
|
|
$v->distance_num = $this->getDistance($v->lng, $v->lat, $lng, $lat); |
|
|
|
|
|
$v->distance = $v->distance_num . ' km'; |
|
|
|
|
|
} else { |
|
|
|
|
|
$v->distance_num = 0; |
|
|
|
|
|
$v->distance = ''; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
foreach ($v->markets as &$m) |
|
|
foreach ($v->markets as &$m) |
|
|
{ |
|
|
{ |
|
|
if(!empty($lng) && !empty($lat)){ |
|
|
if(!empty($lng) && !empty($lat)){ |
|
|
$m->Distance = ($this->getDistance($m->lng,$m->lat,$lng,$lat)).' km'; |
|
|
|
|
|
|
|
|
$m->distance_num = $this->getDistance($m->lng, $m->lat, $lng, $lat); |
|
|
|
|
|
$m->distance = $m->distance_num.' km'; |
|
|
}else{ |
|
|
}else{ |
|
|
$m->Distance = ''; |
|
|
|
|
|
|
|
|
$m->distance_num = 0; |
|
|
|
|
|
$m->distance = ''; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return $res; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$res = collect($res->toArray())->sortBy(function ($area, $key) { |
|
|
|
|
|
return $area['distance_num']; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
$res = collect($res->all())->map(function ($area, $key) { |
|
|
|
|
|
$markets = collect($area['markets'])->sortBy('distance_num'); |
|
|
|
|
|
$area['markets'] = $markets->values()->all(); |
|
|
|
|
|
return $area; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return $res->all(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function searchMarket($keywords,$lng,$lat,$cityId = 2163) |
|
|
public function searchMarket($keywords,$lng,$lat,$cityId = 2163) |
|
|
@ -52,9 +74,9 @@ class LocationService implements LocationServiceInterface |
|
|
->get(); |
|
|
->get(); |
|
|
foreach ($res as &$v){ |
|
|
foreach ($res as &$v){ |
|
|
if(!empty($lng) && !empty($lat)){ |
|
|
if(!empty($lng) && !empty($lat)){ |
|
|
$v->Distance = ($this->getDistance($v->lng,$v->lat,$lng,$lat)).' km'; |
|
|
|
|
|
|
|
|
$v->distance = ($this->getDistance($v->lng,$v->lat,$lng,$lat)).' km'; |
|
|
}else{ |
|
|
}else{ |
|
|
$v->Distance = ''; |
|
|
|
|
|
|
|
|
$v->distance = ''; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return $res; |
|
|
return $res; |
|
|
|