diff --git a/app/Service/v3/Implementations/LocationService.php b/app/Service/v3/Implementations/LocationService.php index 89ff26c..1a19c7b 100644 --- a/app/Service/v3/Implementations/LocationService.php +++ b/app/Service/v3/Implementations/LocationService.php @@ -31,16 +31,38 @@ class LocationService implements LocationServiceInterface $cityIds = Market::query()->pluck('city_id'); $res = Area::query()->with('markets')->whereIn('id',$cityIds)->get(); 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) { 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{ - $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) @@ -52,9 +74,9 @@ class LocationService implements LocationServiceInterface ->get(); foreach ($res as &$v){ 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{ - $v->Distance = ''; + $v->distance = ''; } } return $res; diff --git a/app/Service/v3/Implementations/SearchService.php b/app/Service/v3/Implementations/SearchService.php index 82f85f5..6127c98 100644 --- a/app/Service/v3/Implementations/SearchService.php +++ b/app/Service/v3/Implementations/SearchService.php @@ -104,7 +104,6 @@ class SearchService implements SearchServiceInterface } } - $builder->select(['id', 'logo', 'name']); $paginate = $builder->paginate($params['pagesize']); $stores = $paginate->toArray(); return ['has_more_pages' => $paginate->hasMorePages(), 'stores' => $stores['data']];