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.
 
 
 
 

262 lines
10 KiB

  1. <?php
  2. header("Access-Control-Allow-Origin:*");
  3. //载入配置文件和连接数据库
  4. require_once 'Common/Mysql.php';
  5. //1.获取POIid数组
  6. $poi_id = getPoiIdArr();
  7. //2.收集所有的poi_id
  8. $area_id_array = array();
  9. foreach ($poi_id as $key => $value) {
  10. if (!isset($area_id_array[$value['start_area']])) {
  11. $area_id_array[$value['start_area']] = $value['start_area'];
  12. }
  13. if (!isset($area_id_array[$value['end_area']])) {
  14. $area_id_array[$value['end_area']] = $value['end_area'];
  15. }
  16. }
  17. $poi_id = array_merge($poi_id);
  18. //3.根据poi_id获取poi详细信息
  19. if (count($area_id_array) > 0) {
  20. $poi_info_array1 = getPoiInfo($area_id_array);
  21. } else {
  22. $poi_info_array1 = array();
  23. }
  24. foreach ($poi_info_array1 as $key => $vel){
  25. $poi_info_array[$vel['area_id']] = $vel;
  26. }
  27. //4.根据线路类型及上下车类型对poi分组
  28. $poi_line_inout = getPoiByLineInout($poi_id);
  29. $result['poi_id'] = $poi_id;
  30. $result['poi_info_array'] = $poi_info_array;
  31. $result['poi_line_inout'] = $poi_line_inout;
  32. set_memcache('FX_POI_ARR_LIST', $result, 3600);
  33. exit();
  34. function getPoiIdArr()
  35. {
  36. $poi_array = getPoiId();
  37. return $poi_array;
  38. }
  39. function getPoiId()
  40. {
  41. $pdo = conn();
  42. $sql = 'SELECT
  43. start_area,
  44. end_area,
  45. line_type
  46. FROM
  47. (
  48. SELECT
  49. SUBSTRING_INDEX(SUBSTRING_INDEX(b.start_area, \',\', sequence.help_topic_id),\',\' ,-1) AS start_area,
  50. SUBSTRING_INDEX(SUBSTRING_INDEX(b.end_area, \',\', sequence1.help_topic_id),\',\' ,-1) AS end_area,
  51. line_type
  52. FROM
  53. (select help_topic_id from mysql.help_topic where help_topic_id between 1 and 20 ) as sequence,
  54. (select help_topic_id from mysql.help_topic where help_topic_id between 1 and 20 )as sequence1,
  55. (
  56. SELECT @id := @id +1 as id,
  57. if(length(start_parent)=0,start_area_id,concat(start_area_id,\',\',start_parent)) as start_area,
  58. if(length(end_parent)=0,end_area_id,concat(end_area_id,\',\',end_parent)) as end_area,
  59. line_type
  60. FROM (
  61. SELECT distinct
  62. t.start_station_area_id as start_area_id,
  63. replace(substring(v1.parent_area_id_list,2,length(v1.parent_area_id_list)-2),\'}{\',\',\') AS start_parent,
  64. t.end_station_area_id as end_area_id,
  65. replace(substring(v2.parent_area_id_list,2,length(v2.parent_area_id_list)-2),\'}{\',\',\') AS end_parent,
  66. l.line_type
  67. FROM
  68. opera_line AS l,
  69. opera_tickets AS t,
  70. base_area_view as v1,
  71. base_area_view as v2,
  72. base_area as a1,
  73. base_area as a2
  74. WHERE
  75. l.line_id = t.line_id
  76. and v1.area_id = t.start_station_area_id
  77. and v2.area_id = t.end_station_area_id
  78. and a1.id = t.start_station_area_id
  79. and a2.id = t.end_station_area_id
  80. and a1.cancel_flag = 0
  81. and a2.cancel_flag = 0
  82. AND l.cancel_flag = 0
  83. AND l.if_disabled = 0
  84. AND l.line_type in(255,256)
  85. AND l.is_onsale = 1
  86. AND t.cancel_flag = 0
  87. AND t.start_station_area_id != 0
  88. AND t.end_station_area_id != 0
  89. ) a,
  90. (select @id:= 0) as i
  91. ) b
  92. WHERE
  93. sequence.help_topic_id BETWEEN 1 AND ( SELECT 1 + LENGTH(b.start_area) - LENGTH(REPLACE(b.start_area, \',\', \'\')))
  94. AND sequence1.help_topic_id BETWEEN 1 AND ( SELECT 1 + LENGTH(b.end_area) - LENGTH(REPLACE(b.end_area, \',\', \'\')))
  95. GROUP BY
  96. SUBSTRING_INDEX(SUBSTRING_INDEX(b.start_area, \',\', sequence.help_topic_id),\',\' ,-1),
  97. SUBSTRING_INDEX(SUBSTRING_INDEX(b.end_area, \',\', sequence1.help_topic_id),\',\' ,-1),
  98. line_type
  99. )as tb';
  100. $result = $pdo->query($sql);
  101. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  102. return $rowset;
  103. }
  104. function getPoiByLineInout($poi_id)
  105. {
  106. $poi_group = array();
  107. foreach ($poi_id as $k => $v) {
  108. if (!isset($poi_group[$v['line_type']]['start_area'][$v['start_area']])) {
  109. $poi_group[$v['line_type']]['start_area'][$v['start_area']] = $v['start_area'];
  110. }
  111. if (!isset($poi_group[$v['line_type']]['end_area'][$v['end_area']])) {
  112. $poi_group[$v['line_type']]['end_area'][$v['end_area']] = $v['end_area'];
  113. }
  114. }
  115. return $poi_group;
  116. }
  117. function getPoiByLineType($bus_type,$inout_type)
  118. {
  119. //1.读取站点基础信息缓存
  120. $poi = getPoiInfoArr();
  121. $poi_arr = $poi['poi_line_inout'][$bus_type];
  122. $poi_info = $poi['poi_info_array'];
  123. $poi_result = array();
  124. //2.填充poi信息
  125. foreach ($poi_arr as $key => $vel) {
  126. foreach ($vel as $k => $v) {
  127. $poi_one['area_id'] = $poi_info[$v]['area_id'];
  128. $poi_one['area_name'] = $poi_info[$v]['area_name'];
  129. $poi_one['area_level'] = $poi_info[$v]['area_level'];
  130. $poi_result[$key][$poi_one['area_level']][$k] = $poi_one;
  131. }
  132. }
  133. //3.排序
  134. foreach ($poi_result as $key => $vel){
  135. foreach ($vel as $k => $v) {
  136. ksort($v);
  137. $poi_result[$key][$k] = $v;
  138. $vel[$k] = $v;
  139. }
  140. ksort($vel);
  141. $poi_result[$key] = $vel;
  142. }
  143. foreach ($poi_result as $key => $vel){
  144. $poi_sort = array();
  145. foreach ($vel as $k => $v) {
  146. foreach ($v as $k1 => $v1){
  147. $poi_sort[] = $v1;
  148. }
  149. }
  150. $poi_result[$key] = $poi_sort;
  151. }
  152. //4.获取可查询站点的权限
  153. if($inout_type == 'in'){
  154. $list1 = $poi_result['start_area'];
  155. }else{
  156. $list1 = $poi_result['end_area'];
  157. }
  158. $user_id = $_COOKIE['user_id'];
  159. global $hotel_authority;
  160. if ($bus_type == '256' && isset($hotel_authority[$user_id])) {
  161. if (is_array($hotel_authority[$user_id])) {
  162. foreach ($hotel_authority[$user_id] as $v) {
  163. if(isset($poi_info[$v])){
  164. $area_one['area_id'] = $v;
  165. $area_one['area_name'] = $poi_info[$v]['area_name'];
  166. $list[] = $area_one;
  167. }
  168. }
  169. } else {
  170. if(isset($poi_info[$hotel_authority[$user_id]])) {
  171. $area_one['area_id'] = $hotel_authority[$user_id];
  172. $area_one['area_name'] = $poi_info[$hotel_authority[$user_id]]['area_name'];
  173. $list[] = $area_one;
  174. }
  175. }
  176. $area_one['area_id'] = 3240;
  177. $area_one['area_name'] = $poi_info[3240]['area_name'];
  178. $list[] = $area_one;
  179. $area_one['area_id'] = 100437;
  180. $area_one['area_name'] = $poi_info[100437]['area_name'];
  181. $list[] = $area_one;
  182. } else {
  183. $list = $list1;
  184. }
  185. return $list;
  186. }
  187. function getPoiInfo($area_id_array)
  188. {
  189. $area_id_array = implode(',', $area_id_array);
  190. //1.获取POI的详细信息
  191. $poi_array = getPoiInfoDb($area_id_array);
  192. //2.整理poi数组
  193. $poi_info_array = array();
  194. foreach ($poi_array as $key => $vel) {
  195. $poi_info_array[$vel['area_id']] = $vel;
  196. }
  197. //3.整理poi的父子关系
  198. foreach ($poi_info_array as $key => $vel) {
  199. if (!empty($vel['parent_area_id'])) {
  200. $parent_id_arr = explode(',', $vel['parent_area_id']);
  201. $parent_name_arr = explode(',', $vel['parent_area_name']);
  202. $parent_area_arr = array();
  203. foreach ($parent_id_arr as $k => $v) {
  204. $parent_area_arr[$k]['area_id'] = $v;
  205. $parent_area_arr[$k]['area_name'] = $parent_name_arr[$k];
  206. $poi_info_array[$v]['son_area_id'][$key] = $key;
  207. }
  208. $poi_info_array[$key]['parent_area_arr'] = $parent_area_arr;
  209. } else {
  210. $poi_info_array[$key]['parent_area_arr'] = array();
  211. }
  212. }
  213. foreach ($poi_info_array as $key => $vel) {
  214. if (!isset($vel['son_area_id'])) {
  215. $poi_info_array[$key]['son_area_id'] = '';
  216. } else {
  217. $poi_info_array[$key]['son_area_id'] = implode(',', $vel['son_area_id']);
  218. }
  219. }
  220. return $poi_info_array;
  221. }
  222. function getPoiInfoDb($poi_id)
  223. {
  224. $pdo = conn();
  225. $sql = 'SELECT
  226. a.id as area_id,
  227. a.area_name,
  228. a.poi_type,
  229. REPLACE(substring(v.parent_area_id_list,2,length(v.parent_area_id_list)-2),\'}{\',\',\') AS parent_area_id,
  230. REPLACE(REPLACE(substring(v.parent_area_name_list,2),\'}{\',\',\'),\'}\',\'\') AS parent_area_name,
  231. v.area_level
  232. FROM
  233. base_area AS a,
  234. base_area_view AS v
  235. WHERE
  236. a.id = v.area_id
  237. AND a.cancel_flag = 0
  238. AND a.id in (' . $poi_id . ')';
  239. $result = $pdo->query($sql);
  240. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  241. return $rowset;
  242. }
  243. ?>