diff --git a/app/api/lists/store/SystemStoreLists.php b/app/api/lists/store/SystemStoreLists.php index 301b80b05..4462b893b 100644 --- a/app/api/lists/store/SystemStoreLists.php +++ b/app/api/lists/store/SystemStoreLists.php @@ -51,9 +51,9 @@ class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterfac $latitude = $this->request->get('latitude',''); $longitude = $this->request->get('longitude',''); $cart_id = $this->request->get('cart_id',''); - if(empty($longitude) || empty($latitude)){ - throw new Exception('缺失经纬度'); - } +// if(empty($longitude) || empty($latitude)){ +// throw new Exception('缺失经纬度'); +// } $where[]=['is_show','=',YesNoEnum::YES]; $data = SystemStore::where($this->searchWhere)->where($where) ->field(['id', 'name', 'phone', 'detailed_address', 'image', 'is_show', @@ -65,26 +65,33 @@ class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterfac ->select() ->toArray(); if($cart_id){ - $cart_id = explode(',',$cart_id); - $cart_select = Cart::whereIn('id', $cart_id) - ->field('id,product_id,cart_num,store_id')->select()->toArray(); - foreach ($cart_select as $v) { - foreach ($data as &$values){ - $store = StoreBranchProduct::where([ - 'store_id'=>$values['id'], - 'product_id'=>$v['product_id'], - ])->field('id,store_name,stock')->withTrashed()->find(); - if(empty($store)){ - $store['stock'] =0; + if($latitude && $longitude){ + $cart_id = explode(',',$cart_id); + $cart_select = Cart::whereIn('id', $cart_id) + ->field('id,product_id,cart_num,store_id')->select()->toArray(); + foreach ($cart_select as $v) { + foreach ($data as &$values){ + $store = StoreBranchProduct::where([ + 'store_id'=>$values['id'], + 'product_id'=>$v['product_id'], + ])->field('id,store_name,stock')->withTrashed()->find(); + if(empty($store)){ + $store['stock'] =0; + } + $values['reservation'] = 0; + if($store['stock'] < $v['cart_num']){ + $values['reservation'] = 1; + } + $values['distance'] = haversineDistance($values['latitude'],$values['longitude'],$latitude,$longitude); } - $values['reservation'] = 0; - if($store['stock'] < $v['cart_num']){ - $values['reservation'] = 1; - } - $values['distance'] = haversineDistance($values['latitude'],$values['longitude'],$latitude,$longitude); - } + } + }else{ + foreach ($data as &$values){ + $values['distance'] = 0; + } } + }else{ foreach ($data as &$value){ $value['distance'] = haversineDistance($value['latitude'],$value['longitude'],$latitude,$longitude); diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index df902eb98..3ea2e26aa 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -176,7 +176,6 @@ class OrderLogic extends BaseLogic $order['source'] = $params['source']; } //处理返回最近的店铺 - $store['near_store'] = []; if ((isset($params['lat']) && $params['lat'] != '') && (isset($params['long']) && $params['long'] != '')) { $storeAll = SystemStore::field('id,name,phone,address,detailed_address,latitude,longitude')->select()->toArray(); $nearestStore = null; @@ -188,9 +187,13 @@ class OrderLogic extends BaseLogic $nearestStore = $value; } } + $store['near_store'] =[]; if ($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) { self::setError($e->getMessage());