|
- <?php
- echo "<pre>";
- //低级POI数组
- $area_array = array();
-
- //以穿梭,直通区分的POI数组
- $area_type_array = array();
-
- //以id为索引的低级POI数组
- $area_id_array = array();
-
- //高级POI数组
- $area_id_parent255 = array();
- $area_id_parent256 = array();
-
- //站点信息数组
- $res_id255 = array();
- $res_id256 = array();
-
- //辅助数组
- $array_info = array();
- $area_name = array();
-
- //终极数组
- $final = array();
-
- $sql = "SELECT
- c.area_id,
- d.area_name,
- a.bus_type,
- c.res_id,
- c.res_name,
- e.parent_area_id_list,
- e.area_level
- FROM
- opera_product AS a,
- opera_product_station AS b,
- base_resource AS c,
- base_area AS d,
- base_area_view AS e
- WHERE
- a.prod_id = b.prod_id
- AND b.res_id = c.res_id
- AND c.area_id = d.id
- AND d.id = e.area_id
- AND a.prod_type = 81
- AND a.cancel_flag = 0
- GROUP BY
- c.res_id,
- a.bus_type,
- c.area_id
- ORDER BY
- c.area_id";
-
- $result=$pdo->query($sql);
-
- $area_array = $result->fetchAll(PDO::FETCH_ASSOC);
- writeLog($sql);
-
- foreach($area_array as $k => $v){
- $array_info = $v;
- unset($array_info['bus_type']);
- unset($array_info['res_id']);
- unset($array_info['res_name']);
-
- $area_parent = $v['parent_area_id_list'];
- $area_parent = explode('}{',$area_parent);
- $area_parent = str_replace('{','',$area_parent);
- $area_parent = str_replace('}','',$area_parent);
-
- $array_info['parent_area_id_list'] = $area_parent;
- //$area_id_array[$v['area_id']] = $v;
- if($v['bus_type'] == 0 || $v['bus_type'] == 255 ){
- $area_type_array[255][$v['area_id']] = $array_info;
- $area_type_array[255][$v['area_id']]['type'] = "area";
- if(!empty($area_parent[0])){
- $area_id_parent255 = array_merge($area_id_parent255,$area_parent);
- $res_id255[$v['res_id']]['area_id'] = $v['res_id'];
- $res_id255[$v['res_id']]['area_name'] = $v['res_name'];
- $res_id255[$v['res_id']]['type'] = "res";
- $res_id255[$v['res_id']]['parent_area_id'] = $array_info['area_id'];
- }
-
- }else{
- $area_type_array[256][$v['area_id']] = $array_info;
- $area_type_array[256][$v['area_id']]['type'] = "area";
- if(!empty($area_parent[0])){
- $area_id_parent256 = array_merge($area_id_parent256,$area_parent);
- $res_id256[$v['res_id']]['area_id'] = $v['res_id'];
- $res_id256[$v['res_id']]['area_name'] = $v['res_name'];
- $res_id256[$v['res_id']]['type'] = "res";
- $res_id256[$v['res_id']]['parent_area_id'] = $array_info['area_id'];
- }
- }
-
- }
-
- $area_id_parent255 = array_unique($area_id_parent255);
- asort($area_id_parent255);
- $area_id_parent255 = array_merge($area_id_parent255);
-
- $area_id_parent256 = array_unique($area_id_parent256);
- asort($area_id_parent256);
- $area_id_parent256 = array_merge($area_id_parent256);
-
-
- $sql = "select area_id,area_name,parent_area_id_list,area_level from base_area_view where area_id in (" . implode(",",$area_id_parent255) . ")";
- $result=$pdo->query($sql);
- $area_array_parent255 = $result->fetchAll(PDO::FETCH_ASSOC);
- foreach($area_array_parent255 as $k => $v)
- {
- $list_id = $v['parent_area_id_list'];
- $list = explode('}{',$list_id);
- $list = str_replace('{','',$list);
- $list = str_replace('}','',$list);
- $area_array_parent255[$k]['parent_area_id_list'] = $list;
- }
-
- $sql = "select area_id,area_name,parent_area_id_list,area_level from base_area_view where area_id in (" . implode(",",$area_id_parent256) . ")";
- $result=$pdo->query($sql);
- $area_array_parent256 = $result->fetchAll(PDO::FETCH_ASSOC);
- foreach($area_array_parent256 as $k => $v)
- {
- $list_id = $v['parent_area_id_list'];
- $list = explode('}{',$list_id);
- $list = str_replace('{','',$list);
- $list = str_replace('}','',$list);
- $area_array_parent256[$k]['parent_area_id_list'] = $list;
- }
- // print_r($area_array_parent255);die;
- // print_r($area_array_parent256);
- foreach($area_type_array as $area_type => $area_type_info){
- if($area_type == 255){
- foreach($area_array_parent255 as $v){
- if(!isset($area_type_info[$v['area_id']])){
- $area_type_array[$area_type][$v['area_id']] = $v;
- $area_type_array[$area_type][$v['area_id']]['type'] = 'area';
- }
- }
- ksort($area_type_array[$area_type]);
- }else{
- foreach($area_array_parent256 as $v){
- if(!isset($area_type_info[$v['area_id']])){
- $area_type_array[$area_type][$v['area_id']] = $v;
- $area_type_array[$area_type][$v['area_id']]['type'] = 'area';
- }
- }
- ksort($area_type_array[$area_type]);
- }
- foreach($area_type_array[$area_type] as $area_key => $area_value){
- if(count($area_value) > 0){
- foreach($area_value['parent_area_id_list'] as $key => $value){
- if(!empty($value)){
- $area_type_array[$area_type][$value]['son'][] = $area_value['area_id'];
- }
- }
- $area_type_array[$area_type][$area_key]['son'] = '';
- $area_type_array[$area_type][$area_key]['parent_area_id_list'] = implode(",",$area_type_array[$area_type][$area_key]['parent_area_id_list']);
- }
- }
-
- foreach($area_type_array[$area_type] as $k => $v){
- if($v['son'] != ''){
- $area_type_array[$area_type][$k]['son'] = implode(',',$v['son']);
- }else{
- unset($area_type_array[$area_type][$k]['son']);
- }
- }
- if($area_type == 255){
- foreach($res_id255 as $v){
- $area_name[] = $v['area_name'];
- }
- foreach($area_type_array[$area_type] as $k => $v){
- if(in_array($v['area_name'],$area_name)){
- unset($area_type_array[$area_type][$k]);
- }
- }
- $final[$area_type]['area'] = $area_type_array[$area_type];
- $final[$area_type]['res'] = $res_id255;
- }else{
- foreach($res_id256 as $v){
- $area_name[] = $v['area_name'];
- }
- foreach($area_type_array[$area_type] as $k => $v){
- if(in_array($v['area_name'],$area_name)){
- unset($area_type_array[$area_type][$k]);
- }
- }
- $final[$area_type]['area'] = $area_type_array[$area_type];
- $final[$area_type]['res'] = $res_id256;
- }
- }
- $array_final = $final;
-
- //set_memcache('ARY_LINE_POI', $area_type_array );
-
- ?>
|