From f0d1625680597fb0ccb20e34fccd749d52966535 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 17 Sep 2020 21:54:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=B8=82=E5=9C=BA=E6=8E=92?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v3/Implementations/LocationService.php | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/Service/v3/Implementations/LocationService.php b/app/Service/v3/Implementations/LocationService.php index ad32232..df22dc0 100644 --- a/app/Service/v3/Implementations/LocationService.php +++ b/app/Service/v3/Implementations/LocationService.php @@ -74,14 +74,27 @@ class LocationService implements LocationServiceInterface ['city_id','=',$cityId] ]) ->get(); - foreach ($res as &$v){ + foreach ($res as &$m){ if(!empty($lng) && !empty($lat)){ - $v->distance = ($this->getDistance($v->lng,$v->lat,$lng,$lat)).' km'; + $m->distance_num = $this->getDistance($m->lng, $m->lat, $lng, $lat); + $m->distance = $m->distance_num.' km'; }else{ - $v->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 getNearestMarket($lng,$lat)