params[ 'latitude' ]) ? $this->params[ 'latitude' ] : null; // 纬度 $longitude = isset($this->params[ 'longitude' ]) ? $this->params[ 'longitude' ] : null; // 经度 $store_id = isset($this->params[ 'store_id' ]) ? $this->params[ 'store_id' ] : 0; // 默认门店 $store_model = new StoreModel(); $condition = [ [ 'site_id', "=", $this->site_id ], [ 'status', '=', 1 ], [ 'is_frozen', '=', 0 ] ]; $latlng = array ( 'lat' => $latitude, 'lng' => $longitude, ); $field = '*'; $list_result = $store_model->getLocationStoreList($condition, $field, $latlng); $list = $list_result[ 'data' ]; if (!empty($longitude) && !empty($latitude) && !empty($list)) { foreach ($list as $k => $item) { if ($item[ 'longitude' ] && $item[ 'latitude' ]) { $distance = getDistance((float) $item[ 'longitude' ], (float) $item[ 'latitude' ], (float) $longitude, (float) $latitude); $list[ $k ][ 'distance' ] = $distance / 1000; } else { $list[ $k ][ 'distance' ] = 0; } } // 按距离就近排序 array_multisort(array_column($list, 'distance'), SORT_ASC, $list); } // array_multisort(array_column($list, 'distance'), SORT_ASC, $list); $default_store_id = 0; if (!empty($list)) { $default_store_id = $list[ 0 ][ 'store_id' ]; } return $this->response($this->success([ 'list' => $list, 'store_id' => $default_store_id ])); } /** * 基础信息 * @return false|string */ public function info() { $store_id = isset($this->params[ 'store_id' ]) ? $this->params[ 'store_id' ] : 0; $latitude = isset($this->params[ 'latitude' ]) ? $this->params[ 'latitude' ] : null; // 纬度 $longitude = isset($this->params[ 'longitude' ]) ? $this->params[ 'longitude' ] : null; // 经度 if (empty($store_id)) { return $this->response($this->error('', 'REQUEST_STORE_ID')); } $condition = [ [ 'store_id', "=", $store_id ], [ 'site_id', "=", $this->site_id ], [ 'status', '=', 1 ] ]; $latlng = array ( 'lat' => $latitude, 'lng' => $longitude, ); $store_model = new StoreModel(); $field = 'store_id,store_name,telphone,store_image,site_id,address,full_address,longitude,latitude,open_date,shop_image'; if (!empty($latlng[ 'lat' ]) && !empty($latlng[ 'lng' ])) { $field .= ',FORMAT(st_distance ( point ( ' . $latlng[ 'lng' ] . ', ' . $latlng[ 'lat' ] . ' ), point ( longitude, latitude ) ) * 111195 / 1000, 2) as distance'; } $res = $store_model->getStoreInfo($condition, $field); if($res['data']['shop_image'] == ''){ $res['data']['shop_image'] = '/upload/common/images/store_bg.png'; } return $this->response($res); } /*** * */ public function adbanner(){ $res = [ [ 'img' => 'upload/common/images/zmxx_ad.png', 'height' => '', ] ]; $store_id = isset($this->params[ 'store_id' ]) ? $this->params[ 'store_id' ] : 0; $condition = [ [ 'store_id', "=", $store_id ], [ 'site_id', "=", $this->site_id ], [ 'status', '=', 1 ] ]; $store_model = new StoreModel(); $storeInfo = $store_model->getStoreInfo($condition); $banner_list = json_decode($storeInfo['data']['banner_list'],true); if(!empty($banner_list)){ $res = $banner_list; } return $this->response($this->success($res)); } }