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.
 
 
 
 

200 lines
6.8 KiB

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