You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

197 lines
7.2 KiB

  1. <?php
  2. echo "<pre>";
  3. //低级POI数组
  4. $area_array = array();
  5. //以穿梭,直通区分的POI数组
  6. $area_type_array = array();
  7. //以id为索引的低级POI数组
  8. $area_id_array = array();
  9. //高级POI数组
  10. $area_id_parent255 = array();
  11. $area_id_parent256 = array();
  12. //站点信息数组
  13. $res_id255 = array();
  14. $res_id256 = array();
  15. //辅助数组
  16. $array_info = array();
  17. $area_name = array();
  18. //终极数组
  19. $final = array();
  20. $sql = "SELECT
  21. c.area_id,
  22. d.area_name,
  23. a.bus_type,
  24. c.res_id,
  25. c.res_name,
  26. e.parent_area_id_list,
  27. e.area_level
  28. FROM
  29. opera_product AS a,
  30. opera_product_station AS b,
  31. base_resource AS c,
  32. base_area AS d,
  33. base_area_view AS e
  34. WHERE
  35. a.prod_id = b.prod_id
  36. AND b.res_id = c.res_id
  37. AND c.area_id = d.id
  38. AND d.id = e.area_id
  39. AND a.prod_type = 81
  40. AND a.cancel_flag = 0
  41. GROUP BY
  42. c.res_id,
  43. a.bus_type,
  44. c.area_id
  45. ORDER BY
  46. c.area_id";
  47. $result=$pdo->query($sql);
  48. $area_array = $result->fetchAll(PDO::FETCH_ASSOC);
  49. writeLog($sql);
  50. foreach($area_array as $k => $v){
  51. $array_info = $v;
  52. unset($array_info['bus_type']);
  53. unset($array_info['res_id']);
  54. unset($array_info['res_name']);
  55. $area_parent = $v['parent_area_id_list'];
  56. $area_parent = explode('}{',$area_parent);
  57. $area_parent = str_replace('{','',$area_parent);
  58. $area_parent = str_replace('}','',$area_parent);
  59. $array_info['parent_area_id_list'] = $area_parent;
  60. //$area_id_array[$v['area_id']] = $v;
  61. if($v['bus_type'] == 0 || $v['bus_type'] == 255 ){
  62. $area_type_array[255][$v['area_id']] = $array_info;
  63. $area_type_array[255][$v['area_id']]['type'] = "area";
  64. if(!empty($area_parent[0])){
  65. $area_id_parent255 = array_merge($area_id_parent255,$area_parent);
  66. $res_id255[$v['res_id']]['area_id'] = $v['res_id'];
  67. $res_id255[$v['res_id']]['area_name'] = $v['res_name'];
  68. $res_id255[$v['res_id']]['type'] = "res";
  69. $res_id255[$v['res_id']]['parent_area_id'] = $array_info['area_id'];
  70. }
  71. }else{
  72. $area_type_array[256][$v['area_id']] = $array_info;
  73. $area_type_array[256][$v['area_id']]['type'] = "area";
  74. if(!empty($area_parent[0])){
  75. $area_id_parent256 = array_merge($area_id_parent256,$area_parent);
  76. $res_id256[$v['res_id']]['area_id'] = $v['res_id'];
  77. $res_id256[$v['res_id']]['area_name'] = $v['res_name'];
  78. $res_id256[$v['res_id']]['type'] = "res";
  79. $res_id256[$v['res_id']]['parent_area_id'] = $array_info['area_id'];
  80. }
  81. }
  82. }
  83. $area_id_parent255 = array_unique($area_id_parent255);
  84. asort($area_id_parent255);
  85. $area_id_parent255 = array_merge($area_id_parent255);
  86. $area_id_parent256 = array_unique($area_id_parent256);
  87. asort($area_id_parent256);
  88. $area_id_parent256 = array_merge($area_id_parent256);
  89. $sql = "select area_id,area_name,parent_area_id_list,area_level from base_area_view where area_id in (" . implode(",",$area_id_parent255) . ")";
  90. $result=$pdo->query($sql);
  91. $area_array_parent255 = $result->fetchAll(PDO::FETCH_ASSOC);
  92. foreach($area_array_parent255 as $k => $v)
  93. {
  94. $list_id = $v['parent_area_id_list'];
  95. $list = explode('}{',$list_id);
  96. $list = str_replace('{','',$list);
  97. $list = str_replace('}','',$list);
  98. $area_array_parent255[$k]['parent_area_id_list'] = $list;
  99. }
  100. $sql = "select area_id,area_name,parent_area_id_list,area_level from base_area_view where area_id in (" . implode(",",$area_id_parent256) . ")";
  101. $result=$pdo->query($sql);
  102. $area_array_parent256 = $result->fetchAll(PDO::FETCH_ASSOC);
  103. foreach($area_array_parent256 as $k => $v)
  104. {
  105. $list_id = $v['parent_area_id_list'];
  106. $list = explode('}{',$list_id);
  107. $list = str_replace('{','',$list);
  108. $list = str_replace('}','',$list);
  109. $area_array_parent256[$k]['parent_area_id_list'] = $list;
  110. }
  111. // print_r($area_array_parent255);die;
  112. // print_r($area_array_parent256);
  113. foreach($area_type_array as $area_type => $area_type_info){
  114. if($area_type == 255){
  115. foreach($area_array_parent255 as $v){
  116. if(!isset($area_type_info[$v['area_id']])){
  117. $area_type_array[$area_type][$v['area_id']] = $v;
  118. $area_type_array[$area_type][$v['area_id']]['type'] = 'area';
  119. }
  120. }
  121. ksort($area_type_array[$area_type]);
  122. }else{
  123. foreach($area_array_parent256 as $v){
  124. if(!isset($area_type_info[$v['area_id']])){
  125. $area_type_array[$area_type][$v['area_id']] = $v;
  126. $area_type_array[$area_type][$v['area_id']]['type'] = 'area';
  127. }
  128. }
  129. ksort($area_type_array[$area_type]);
  130. }
  131. foreach($area_type_array[$area_type] as $area_key => $area_value){
  132. if(count($area_value) > 0){
  133. foreach($area_value['parent_area_id_list'] as $key => $value){
  134. if(!empty($value)){
  135. $area_type_array[$area_type][$value]['son'][] = $area_value['area_id'];
  136. }
  137. }
  138. $area_type_array[$area_type][$area_key]['son'] = '';
  139. $area_type_array[$area_type][$area_key]['parent_area_id_list'] = implode(",",$area_type_array[$area_type][$area_key]['parent_area_id_list']);
  140. }
  141. }
  142. foreach($area_type_array[$area_type] as $k => $v){
  143. if($v['son'] != ''){
  144. $area_type_array[$area_type][$k]['son'] = implode(',',$v['son']);
  145. }else{
  146. unset($area_type_array[$area_type][$k]['son']);
  147. }
  148. }
  149. if($area_type == 255){
  150. foreach($res_id255 as $v){
  151. $area_name[] = $v['area_name'];
  152. }
  153. foreach($area_type_array[$area_type] as $k => $v){
  154. if(in_array($v['area_name'],$area_name)){
  155. unset($area_type_array[$area_type][$k]);
  156. }
  157. }
  158. $final[$area_type]['area'] = $area_type_array[$area_type];
  159. $final[$area_type]['res'] = $res_id255;
  160. }else{
  161. foreach($res_id256 as $v){
  162. $area_name[] = $v['area_name'];
  163. }
  164. foreach($area_type_array[$area_type] as $k => $v){
  165. if(in_array($v['area_name'],$area_name)){
  166. unset($area_type_array[$area_type][$k]);
  167. }
  168. }
  169. $final[$area_type]['area'] = $area_type_array[$area_type];
  170. $final[$area_type]['res'] = $res_id256;
  171. }
  172. }
  173. $array_final = $final;
  174. //set_memcache('ARY_LINE_POI', $area_type_array );
  175. ?>