From b6a7b9f16c227125fcaec83e223d1cf3e514e7a2 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 9 Sep 2020 18:58:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E8=B7=9D=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/LocationService.php | 11 ++++++++++- app/Service/v3/Implementations/UserAddressService.php | 8 +------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/Service/v3/Implementations/LocationService.php b/app/Service/v3/Implementations/LocationService.php index a5af342..671cf71 100644 --- a/app/Service/v3/Implementations/LocationService.php +++ b/app/Service/v3/Implementations/LocationService.php @@ -2,6 +2,8 @@ namespace App\Service\v3\Implementations; +use App\Constants\v3\ErrorCode; +use App\Exception\ErrorCodeException; use App\Service\v3\Interfaces\LocationServiceInterface; use App\Model\v3\Area; use App\Model\v3\Market; @@ -88,6 +90,13 @@ class LocationService implements LocationServiceInterface */ $type = 'bicycling'; $key = 'GB3BZ-7W2CU-LW3VH-B7ZIF-XRKSF-D3FOL'; - return file_get_contents($url.$type.'/?from='.$lat1.','.$lng1.'&to='.$lat2.','.$lng2.'&output=json&key='.$key); + $result = file_get_contents($url.$type.'/?from='.$lat1.','.$lng1.'&to='.$lat2.','.$lng2.'&output=json&key='.$key); + $resultArr = json_decode($result,true); + if($resultArr['status'] > 0) + { + throw new ErrorCodeException(ErrorCode::LOCATION_ERROR,$resultArr['message']); + } + $distance = $resultArr['result']['routes'][0]['distance']; + return $distance; } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/UserAddressService.php b/app/Service/v3/Implementations/UserAddressService.php index cc6912b..06d3bcf 100644 --- a/app/Service/v3/Implementations/UserAddressService.php +++ b/app/Service/v3/Implementations/UserAddressService.php @@ -75,13 +75,7 @@ class UserAddressService implements UserAddressServiceInterface { $address = $this->get($userAddressId); $market = Market::query()->select('lng','lat')->find($marketId); - $result = $this->locationService->getDistanceByTencent($address->lng,$address->lat,$market->lng,$market->lat); - $resultArr = json_decode($result,true); - if($resultArr['status'] > 0) - { - throw new ErrorCodeException(ErrorCode::LOCATION_ERROR,$resultArr['message']); - } - $distance = $resultArr['result']['routes'][0]['distance']; + $distance = $this->locationService->getDistanceByTencent($address->lng,$address->lat,$market->lng,$market->lat); $distributionRrice = $this->calculateDistributionRrice($distance); $res['address'] = $address; $res['distribution_price'] = $distributionRrice;