创建订单显示最近店铺

This commit is contained in:
liu 2024-06-29 16:50:24 +08:00
parent 4177bf71ed
commit 04e8f6eccc

View File

@ -166,11 +166,30 @@ class OrderLogic extends BaseLogic
$order['is_vip'] = 1;
}
//处理返回最近的店铺
$store['near_store'] = [];
if($params['lat'] && $params['long']){
$storeAll = SystemStore::field('id,name,phone,address,detailed_address,latitude,longitude')->select()->toArray();
$nearestStore = null;
$minDistance = PHP_FLOAT_MAX;
foreach ($storeAll as $value){
$value['distance'] = haversineDistance($value['latitude'],$value['longitude'],$params['lat'] ,$params['long']);
if ($value['distance'] < $minDistance) {
$minDistance = $value['distance'];
$nearestStore = $value;
}
}
if ($nearestStore) {
$store['near_store'] =$nearestStore;
}
}
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
return ['order' => $order, 'cart_list' => $cart_select];
return ['order' => $order, 'cart_list' => $cart_select,'shopInfo'=>$store];
}
/**