|
|
|
@ -19,6 +19,7 @@ use App\Service\v3\Interfaces\DistributionPriceServiceInterface; |
|
|
|
use App\Service\v3\Interfaces\LocationServiceInterface; |
|
|
|
use App\Service\v3\Interfaces\SeparateAccountsServiceInterface; |
|
|
|
use App\Service\v3\Interfaces\ShopCartServiceInterface; |
|
|
|
use GuzzleHttp\Client; |
|
|
|
use Hyperf\DbConnection\Db; |
|
|
|
use Hyperf\Di\Annotation\Inject; |
|
|
|
use App\Service\v3\Interfaces\OrderOnlineServiceInterface; |
|
|
|
@ -101,19 +102,43 @@ class OrderOnlineController extends BaseController |
|
|
|
//->where('is_default',1)
|
|
|
|
->orderByDesc('is_default') |
|
|
|
->orderByDesc('updated_at') |
|
|
|
->first(); |
|
|
|
->get()->toArray(); |
|
|
|
$market = Market::find($marketId); |
|
|
|
$distance = 0; |
|
|
|
if(!empty($address->lng) && !empty($address->lat)){ |
|
|
|
$distance = $this->locationService->getDistanceByTencent($market->lng,$market->lat,$address->lng,$address->lat); |
|
|
|
$type = 'bicycling'; |
|
|
|
$key = config('map.tencent'); |
|
|
|
$url = 'https://apis.map.qq.com/ws/distance/v1/matrix?mode='.$type.'&from='.$market->lat.','.$market->lng.'&to='; |
|
|
|
$client = new Client(); |
|
|
|
foreach ($address as $item) { |
|
|
|
$url .= $item['lat'] . ','; |
|
|
|
$url .= $item['lng'] . ';'; |
|
|
|
} |
|
|
|
$url = rtrim($url, ";"); |
|
|
|
$response = $client->request('GET', $url.'&output=json&key='.$key); |
|
|
|
$response = $response->getBody()->getContents(); |
|
|
|
$resultArr = json_decode($response,true); |
|
|
|
$resultArr = $resultArr['result']['rows'][0]['elements']; |
|
|
|
$deliveryDistance = config('distance.delivery_distance'); |
|
|
|
if(isset($distance) && $distance < $deliveryDistance){ |
|
|
|
foreach ($address as $key => &$item) { |
|
|
|
if($resultArr[$key]['distance'] <= $deliveryDistance){ |
|
|
|
$item['distance'] = $resultArr[$key]['distance']; |
|
|
|
$addressNew[] = $item; |
|
|
|
} |
|
|
|
} |
|
|
|
$collection = collect($addressNew); |
|
|
|
$sorted = $collection->sortBy('distance')->sortByDesc('is_default'); |
|
|
|
$address = $sorted->values()->first(); |
|
|
|
if($address){ |
|
|
|
$distance = $address['distance']; |
|
|
|
if($distance >= 1000){ |
|
|
|
$distance_text = '距您收货地址 ' . bcdiv($distance,1000,2) . 'km'; |
|
|
|
}else{ |
|
|
|
$distance_text = '距您收货地址 ' . $distance . 'm'; |
|
|
|
} |
|
|
|
if($address['is_default'] == 1){ |
|
|
|
$address['tags'] = ['id' => 5,'name' => '默认']; |
|
|
|
}else{ |
|
|
|
$address['tags'] = ['id' => 6,'name' => '距离最近']; |
|
|
|
} |
|
|
|
$distributionPrice = $this->distributionPriceService->do($distance); |
|
|
|
$originalPrice = $this->distributionPriceService->original($distance); |
|
|
|
$res['location'] = [ |
|
|
|
@ -133,7 +158,7 @@ class OrderOnlineController extends BaseController |
|
|
|
'address' => '', |
|
|
|
'distribution_price' => 0, |
|
|
|
'original_price' => 0, |
|
|
|
'distance' => $distance, |
|
|
|
'distance' => 0, |
|
|
|
'within' => false, |
|
|
|
'style' => 'strike', |
|
|
|
'distribution_text' => '', |
|
|
|
|