1, "iflogin" => 1, "info" => "用户未登录")); exit; } $area = $_POST['area_name']; $bus_type = $_POST['bus_type']; $inout_type = isset($_POST['inout_type']) ? $_POST['inout_type'] : "in"; //获取全部poi $list = getPoiByLineType($bus_type,$inout_type); if (!empty($area)) { $area_array_line = array(); foreach ($list as $k => $v) { if (strpos($v['area_name'], $area) !== false) { $area_array_line[] = $v; } } $list = $area_array_line; } $code = 0; $info = $CODE[0]; $json = array(); $json['code'] = $code; $json['info'] = $info; $json['list'] = $list; echo json_encode($json); /** * Function Description:获取所有线路中开始POI-结束POI的连接关系 * Function Name: getPoiId * * @return mixed * * @author 张帅 */ function getPoiId() { global $pdo; $sql = 'SELECT start_area, end_area, line_type FROM ( SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(b.start_area, \',\', sequence.help_topic_id),\',\' ,-1) AS start_area, SUBSTRING_INDEX(SUBSTRING_INDEX(b.end_area, \',\', sequence1.help_topic_id),\',\' ,-1) AS end_area, line_type FROM (select help_topic_id from mysql.help_topic where help_topic_id between 1 and 20 ) as sequence, (select help_topic_id from mysql.help_topic where help_topic_id between 1 and 20 )as sequence1, ( SELECT @id := @id +1 as id, if(length(start_parent)=0,start_area_id,concat(start_area_id,\',\',start_parent)) as start_area, if(length(end_parent)=0,end_area_id,concat(end_area_id,\',\',end_parent)) as end_area, line_type FROM ( SELECT distinct t.start_station_area_id as start_area_id, replace(substring(v1.parent_area_id_list,2,length(v1.parent_area_id_list)-2),\'}{\',\',\') AS start_parent, t.end_station_area_id as end_area_id, replace(substring(v2.parent_area_id_list,2,length(v2.parent_area_id_list)-2),\'}{\',\',\') AS end_parent, l.line_type FROM opera_line AS l, opera_tickets AS t, base_area_view as v1, base_area_view as v2, base_area as a1, base_area as a2 WHERE l.line_id = t.line_id and v1.area_id = t.start_station_area_id and v2.area_id = t.end_station_area_id and a1.id = t.start_station_area_id and a2.id = t.end_station_area_id and a1.cancel_flag = 0 and a2.cancel_flag = 0 AND l.cancel_flag = 0 AND l.if_disabled = 0 AND l.line_type in(255,256) AND l.is_onsale = 1 AND t.cancel_flag = 0 AND t.start_station_area_id != 0 AND t.end_station_area_id != 0 ) a, (select @id:= 0) as i ) b WHERE sequence.help_topic_id BETWEEN 1 AND ( SELECT 1 + LENGTH(b.start_area) - LENGTH(REPLACE(b.start_area, \',\', \'\'))) AND sequence1.help_topic_id BETWEEN 1 AND ( SELECT 1 + LENGTH(b.end_area) - LENGTH(REPLACE(b.end_area, \',\', \'\'))) GROUP BY SUBSTRING_INDEX(SUBSTRING_INDEX(b.start_area, \',\', sequence.help_topic_id),\',\' ,-1), SUBSTRING_INDEX(SUBSTRING_INDEX(b.end_area, \',\', sequence1.help_topic_id),\',\' ,-1), line_type )as tb'; $result = $pdo->query($sql); $rowset = $result->fetchAll(PDO::FETCH_ASSOC); return $rowset; } /** * Function Description:获取poi详情 * Function Name: getPoiInfo * @param $poi_id * * @return array * * @author 张帅 */ function getPoiInfoDb($poi_id) { global $pdo; $sql = 'SELECT a.id as area_id, a.area_name, a.poi_type, REPLACE(substring(v.parent_area_id_list,2,length(v.parent_area_id_list)-2),\'}{\',\',\') AS parent_area_id, REPLACE(REPLACE(substring(v.parent_area_name_list,2),\'}{\',\',\'),\'}\',\'\') AS parent_area_name, v.area_level FROM base_area AS a, base_area_view AS v WHERE a.id = v.area_id AND a.cancel_flag = 0 AND a.id in (' . $poi_id . ')'; $result = $pdo->query($sql); $rowset = $result->fetchAll(PDO::FETCH_ASSOC); return $rowset; } /** * Function Description:获取站点详情 * Function Name: getPoiInfoArr * * @return array|mixed * * @author 张帅 */ function getPoiInfoArr() { $result = get_memcache('FX_POI_ARR_LIST'); if ($result) { return $result; } //1.获取POIid数组 $poi_id = getPoiIdArr(); //2.收集所有的poi_id $area_id_array = array(); foreach ($poi_id as $key => $value) { if (!isset($area_id_array[$value['start_area']])) { $area_id_array[$value['start_area']] = $value['start_area']; } if (!isset($area_id_array[$value['end_area']])) { $area_id_array[$value['end_area']] = $value['end_area']; } } $poi_id = array_merge($poi_id); //3.根据poi_id获取poi详细信息 if (count($area_id_array) > 0) { $poi_info_array1 = getPoiInfo($area_id_array); } else { $poi_info_array1 = array(); } foreach ($poi_info_array1 as $key => $vel){ $poi_info_array[$vel['area_id']] = $vel; } //4.根据线路类型及上下车类型对poi分组 $poi_line_inout = getPoiByLineInout($poi_id); $result['poi_id'] = $poi_id; $result['poi_info_array'] = $poi_info_array; $result['poi_line_inout'] = $poi_line_inout; set_memcache('FX_POI_ARR_LIST', $result, 3600); return $result; } /** * Function Description:获取poi站点数组 * Function Name: getPoiIdArr * * @return array * * @author 张帅 */ function getPoiIdArr() { $poi_array = getPoiId(); return $poi_array; } /** * Function Description:获取poi详细信息 * Function Name: getPoiInfo * @param $area_id_array * * @return array * * @author 张帅 */ function getPoiInfo($area_id_array) { $area_id_array = implode(',', $area_id_array); //1.获取POI的详细信息 $poi_array = getPoiInfoDb($area_id_array); //2.整理poi数组 $poi_info_array = array(); foreach ($poi_array as $key => $vel) { $poi_info_array[$vel['area_id']] = $vel; } //3.整理poi的父子关系 foreach ($poi_info_array as $key => $vel) { if (!empty($vel['parent_area_id'])) { $parent_id_arr = explode(',', $vel['parent_area_id']); $parent_name_arr = explode(',', $vel['parent_area_name']); $parent_area_arr = array(); foreach ($parent_id_arr as $k => $v) { $parent_area_arr[$k]['area_id'] = $v; $parent_area_arr[$k]['area_name'] = $parent_name_arr[$k]; $poi_info_array[$v]['son_area_id'][$key] = $key; } $poi_info_array[$key]['parent_area_arr'] = $parent_area_arr; } else { $poi_info_array[$key]['parent_area_arr'] = array(); } } foreach ($poi_info_array as $key => $vel) { if (!isset($vel['son_area_id'])) { $poi_info_array[$key]['son_area_id'] = ''; } else { $poi_info_array[$key]['son_area_id'] = implode(',', $vel['son_area_id']); } } return $poi_info_array; } /** * Function Description:根据线路类型及上下车类型对poi分组 * Function Name: getPoiByLineInout * @param $poi_id * * @return mixed * * @author 张帅 */ function getPoiByLineInout($poi_id) { $poi_group = array(); foreach ($poi_id as $k => $v) { if (!isset($poi_group[$v['line_type']]['start_area'][$v['start_area']])) { $poi_group[$v['line_type']]['start_area'][$v['start_area']] = $v['start_area']; } if (!isset($poi_group[$v['line_type']]['end_area'][$v['end_area']])) { $poi_group[$v['line_type']]['end_area'][$v['end_area']] = $v['end_area']; } } return $poi_group; } /** * Function Description:根据线路类型及上下车类型对poi分组 * Function Name: getPoiByLineInout * @param $poi_id * * @return mixed * * @author 张帅 */ function getPoiByLineType($bus_type,$inout_type) { //1.读取站点基础信息缓存 $poi = getPoiInfoArr(); $poi_arr = $poi['poi_line_inout'][$bus_type]; $poi_info = $poi['poi_info_array']; $poi_result = array(); //2.填充poi信息 foreach ($poi_arr as $key => $vel) { foreach ($vel as $k => $v) { $poi_one['area_id'] = $poi_info[$v]['area_id']; $poi_one['area_name'] = $poi_info[$v]['area_name']; $poi_one['area_level'] = $poi_info[$v]['area_level']; $poi_result[$key][$poi_one['area_level']][$k] = $poi_one; } } //3.排序 foreach ($poi_result as $key => $vel){ foreach ($vel as $k => $v) { ksort($v); $poi_result[$key][$k] = $v; $vel[$k] = $v; } ksort($vel); $poi_result[$key] = $vel; } foreach ($poi_result as $key => $vel){ $poi_sort = array(); foreach ($vel as $k => $v) { foreach ($v as $k1 => $v1){ $poi_sort[] = $v1; } } $poi_result[$key] = $poi_sort; } //4.获取可查询站点的权限 if($inout_type == 'in'){ $list1 = $poi_result['start_area']; }else{ $list1 = $poi_result['end_area']; } $user_id = $_COOKIE['user_id']; global $hotel_authority; if ($bus_type == '256' && isset($hotel_authority[$user_id])) { if (is_array($hotel_authority[$user_id])) { foreach ($hotel_authority[$user_id] as $v) { if(isset($poi_info[$v])){ $area_one['area_id'] = $v; $area_one['area_name'] = $poi_info[$v]['area_name']; $list[] = $area_one; } } } else { if(isset($poi_info[$hotel_authority[$user_id]])) { $area_one['area_id'] = $hotel_authority[$user_id]; $area_one['area_name'] = $poi_info[$hotel_authority[$user_id]]['area_name']; $list[] = $area_one; } } $area_one['area_id'] = 3240; $area_one['area_name'] = $poi_info[3240]['area_name']; $list[] = $area_one; $area_one['area_id'] = 100437; $area_one['area_name'] = $poi_info[100437]['area_name']; $list[] = $area_one; } else { $list = $list1; } return $list; } ?>