修改经纬度默认

This commit is contained in:
liu 2024-07-02 13:54:21 +08:00
parent 84e0500e7c
commit 7421de9d10
2 changed files with 31 additions and 21 deletions

View File

@ -51,9 +51,9 @@ class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterfac
$latitude = $this->request->get('latitude',''); $latitude = $this->request->get('latitude','');
$longitude = $this->request->get('longitude',''); $longitude = $this->request->get('longitude','');
$cart_id = $this->request->get('cart_id',''); $cart_id = $this->request->get('cart_id','');
if(empty($longitude) || empty($latitude)){ // if(empty($longitude) || empty($latitude)){
throw new Exception('缺失经纬度'); // throw new Exception('缺失经纬度');
} // }
$where[]=['is_show','=',YesNoEnum::YES]; $where[]=['is_show','=',YesNoEnum::YES];
$data = SystemStore::where($this->searchWhere)->where($where) $data = SystemStore::where($this->searchWhere)->where($where)
->field(['id', 'name', 'phone', 'detailed_address', 'image', 'is_show', ->field(['id', 'name', 'phone', 'detailed_address', 'image', 'is_show',
@ -65,6 +65,7 @@ class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterfac
->select() ->select()
->toArray(); ->toArray();
if($cart_id){ if($cart_id){
if($latitude && $longitude){
$cart_id = explode(',',$cart_id); $cart_id = explode(',',$cart_id);
$cart_select = Cart::whereIn('id', $cart_id) $cart_select = Cart::whereIn('id', $cart_id)
->field('id,product_id,cart_num,store_id')->select()->toArray(); ->field('id,product_id,cart_num,store_id')->select()->toArray();
@ -85,6 +86,12 @@ class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterfac
} }
} }
}else{
foreach ($data as &$values){
$values['distance'] = 0;
}
}
}else{ }else{
foreach ($data as &$value){ foreach ($data as &$value){
$value['distance'] = haversineDistance($value['latitude'],$value['longitude'],$latitude,$longitude); $value['distance'] = haversineDistance($value['latitude'],$value['longitude'],$latitude,$longitude);

View File

@ -176,7 +176,6 @@ class OrderLogic extends BaseLogic
$order['source'] = $params['source']; $order['source'] = $params['source'];
} }
//处理返回最近的店铺 //处理返回最近的店铺
$store['near_store'] = [];
if ((isset($params['lat']) && $params['lat'] != '') && (isset($params['long']) && $params['long'] != '')) { if ((isset($params['lat']) && $params['lat'] != '') && (isset($params['long']) && $params['long'] != '')) {
$storeAll = SystemStore::field('id,name,phone,address,detailed_address,latitude,longitude')->select()->toArray(); $storeAll = SystemStore::field('id,name,phone,address,detailed_address,latitude,longitude')->select()->toArray();
$nearestStore = null; $nearestStore = null;
@ -188,9 +187,13 @@ class OrderLogic extends BaseLogic
$nearestStore = $value; $nearestStore = $value;
} }
} }
$store['near_store'] =[];
if ($nearestStore) { if ($nearestStore) {
$store['near_store'] = $nearestStore; $store['near_store'] = $nearestStore;
} }
}else{
$store_id = getenv('STORE_ID') ?? 1;
$store['near_store'] =SystemStore::where('id', $store_id)->field('id,name,phone,address,detailed_address,latitude,longitude')->find()??[];
} }
} catch (\Exception $e) { } catch (\Exception $e) {
self::setError($e->getMessage()); self::setError($e->getMessage());