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.
 
 
 
 

361 lines
12 KiB

  1. <?php
  2. header("Access-Control-Allow-Origin:*");
  3. //载入配置文件和连接数据库
  4. //获取地名
  5. $user_id = $_COOKIE['user_id'];
  6. if (!$user_id) {
  7. echo json_encode(array("code" => 1, "iflogin" => 1, "info" => "用户未登录"));
  8. exit;
  9. }
  10. $area = $_POST['area_name'];
  11. $bus_type = $_POST['bus_type'];
  12. $inout_type = isset($_POST['inout_type']) ? $_POST['inout_type'] : "in";
  13. //获取全部poi
  14. $list = getPoiByLineType($bus_type,$inout_type);
  15. if (!empty($area)) {
  16. $area_array_line = array();
  17. foreach ($list as $k => $v) {
  18. if (strpos($v['area_name'], $area) !== false) {
  19. $area_array_line[] = $v;
  20. }
  21. }
  22. $list = $area_array_line;
  23. }
  24. $code = 0;
  25. $info = $CODE[0];
  26. $json = array();
  27. $json['code'] = $code;
  28. $json['info'] = $info;
  29. $json['list'] = $list;
  30. echo json_encode($json);
  31. /**
  32. * Function Description:获取所有线路中开始POI-结束POI的连接关系
  33. * Function Name: getPoiId
  34. *
  35. * @return mixed
  36. *
  37. * @author 张帅
  38. */
  39. function getPoiId()
  40. {
  41. global $pdo;
  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. /**
  105. * Function Description:获取poi详情
  106. * Function Name: getPoiInfo
  107. * @param $poi_id
  108. *
  109. * @return array
  110. *
  111. * @author 张帅
  112. */
  113. function getPoiInfoDb($poi_id)
  114. {
  115. global $pdo;
  116. $sql = 'SELECT
  117. a.id as area_id,
  118. a.area_name,
  119. a.poi_type,
  120. REPLACE(substring(v.parent_area_id_list,2,length(v.parent_area_id_list)-2),\'}{\',\',\') AS parent_area_id,
  121. REPLACE(REPLACE(substring(v.parent_area_name_list,2),\'}{\',\',\'),\'}\',\'\') AS parent_area_name,
  122. v.area_level
  123. FROM
  124. base_area AS a,
  125. base_area_view AS v
  126. WHERE
  127. a.id = v.area_id
  128. AND a.cancel_flag = 0
  129. AND a.id in (' . $poi_id . ')';
  130. $result = $pdo->query($sql);
  131. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  132. return $rowset;
  133. }
  134. /**
  135. * Function Description:获取站点详情
  136. * Function Name: getPoiInfoArr
  137. *
  138. * @return array|mixed
  139. *
  140. * @author 张帅
  141. */
  142. function getPoiInfoArr()
  143. {
  144. $result = get_memcache('FX_POI_ARR_LIST');
  145. if ($result) {
  146. return $result;
  147. }
  148. //1.获取POIid数组
  149. $poi_id = getPoiIdArr();
  150. //2.收集所有的poi_id
  151. $area_id_array = array();
  152. foreach ($poi_id as $key => $value) {
  153. if (!isset($area_id_array[$value['start_area']])) {
  154. $area_id_array[$value['start_area']] = $value['start_area'];
  155. }
  156. if (!isset($area_id_array[$value['end_area']])) {
  157. $area_id_array[$value['end_area']] = $value['end_area'];
  158. }
  159. }
  160. $poi_id = array_merge($poi_id);
  161. //3.根据poi_id获取poi详细信息
  162. if (count($area_id_array) > 0) {
  163. $poi_info_array1 = getPoiInfo($area_id_array);
  164. } else {
  165. $poi_info_array1 = array();
  166. }
  167. foreach ($poi_info_array1 as $key => $vel){
  168. $poi_info_array[$vel['area_id']] = $vel;
  169. }
  170. //4.根据线路类型及上下车类型对poi分组
  171. $poi_line_inout = getPoiByLineInout($poi_id);
  172. $result['poi_id'] = $poi_id;
  173. $result['poi_info_array'] = $poi_info_array;
  174. $result['poi_line_inout'] = $poi_line_inout;
  175. set_memcache('FX_POI_ARR_LIST', $result, 3600);
  176. return $result;
  177. }
  178. /**
  179. * Function Description:获取poi站点数组
  180. * Function Name: getPoiIdArr
  181. *
  182. * @return array
  183. *
  184. * @author 张帅
  185. */
  186. function getPoiIdArr()
  187. {
  188. $poi_array = getPoiId();
  189. return $poi_array;
  190. }
  191. /**
  192. * Function Description:获取poi详细信息
  193. * Function Name: getPoiInfo
  194. * @param $area_id_array
  195. *
  196. * @return array
  197. *
  198. * @author 张帅
  199. */
  200. function getPoiInfo($area_id_array)
  201. {
  202. $area_id_array = implode(',', $area_id_array);
  203. //1.获取POI的详细信息
  204. $poi_array = getPoiInfoDb($area_id_array);
  205. //2.整理poi数组
  206. $poi_info_array = array();
  207. foreach ($poi_array as $key => $vel) {
  208. $poi_info_array[$vel['area_id']] = $vel;
  209. }
  210. //3.整理poi的父子关系
  211. foreach ($poi_info_array as $key => $vel) {
  212. if (!empty($vel['parent_area_id'])) {
  213. $parent_id_arr = explode(',', $vel['parent_area_id']);
  214. $parent_name_arr = explode(',', $vel['parent_area_name']);
  215. $parent_area_arr = array();
  216. foreach ($parent_id_arr as $k => $v) {
  217. $parent_area_arr[$k]['area_id'] = $v;
  218. $parent_area_arr[$k]['area_name'] = $parent_name_arr[$k];
  219. $poi_info_array[$v]['son_area_id'][$key] = $key;
  220. }
  221. $poi_info_array[$key]['parent_area_arr'] = $parent_area_arr;
  222. } else {
  223. $poi_info_array[$key]['parent_area_arr'] = array();
  224. }
  225. }
  226. foreach ($poi_info_array as $key => $vel) {
  227. if (!isset($vel['son_area_id'])) {
  228. $poi_info_array[$key]['son_area_id'] = '';
  229. } else {
  230. $poi_info_array[$key]['son_area_id'] = implode(',', $vel['son_area_id']);
  231. }
  232. }
  233. return $poi_info_array;
  234. }
  235. /**
  236. * Function Description:根据线路类型及上下车类型对poi分组
  237. * Function Name: getPoiByLineInout
  238. * @param $poi_id
  239. *
  240. * @return mixed
  241. *
  242. * @author 张帅
  243. */
  244. function getPoiByLineInout($poi_id)
  245. {
  246. $poi_group = array();
  247. foreach ($poi_id as $k => $v) {
  248. if (!isset($poi_group[$v['line_type']]['start_area'][$v['start_area']])) {
  249. $poi_group[$v['line_type']]['start_area'][$v['start_area']] = $v['start_area'];
  250. }
  251. if (!isset($poi_group[$v['line_type']]['end_area'][$v['end_area']])) {
  252. $poi_group[$v['line_type']]['end_area'][$v['end_area']] = $v['end_area'];
  253. }
  254. }
  255. return $poi_group;
  256. }
  257. /**
  258. * Function Description:根据线路类型及上下车类型对poi分组
  259. * Function Name: getPoiByLineInout
  260. * @param $poi_id
  261. *
  262. * @return mixed
  263. *
  264. * @author 张帅
  265. */
  266. function getPoiByLineType($bus_type,$inout_type)
  267. {
  268. //1.读取站点基础信息缓存
  269. $poi = getPoiInfoArr();
  270. $poi_arr = $poi['poi_line_inout'][$bus_type];
  271. $poi_info = $poi['poi_info_array'];
  272. $poi_result = array();
  273. //2.填充poi信息
  274. foreach ($poi_arr as $key => $vel) {
  275. foreach ($vel as $k => $v) {
  276. $poi_one['area_id'] = $poi_info[$v]['area_id'];
  277. $poi_one['area_name'] = $poi_info[$v]['area_name'];
  278. $poi_one['area_level'] = $poi_info[$v]['area_level'];
  279. $poi_result[$key][$poi_one['area_level']][$k] = $poi_one;
  280. }
  281. }
  282. //3.排序
  283. foreach ($poi_result as $key => $vel){
  284. foreach ($vel as $k => $v) {
  285. ksort($v);
  286. $poi_result[$key][$k] = $v;
  287. $vel[$k] = $v;
  288. }
  289. ksort($vel);
  290. $poi_result[$key] = $vel;
  291. }
  292. foreach ($poi_result as $key => $vel){
  293. $poi_sort = array();
  294. foreach ($vel as $k => $v) {
  295. foreach ($v as $k1 => $v1){
  296. $poi_sort[] = $v1;
  297. }
  298. }
  299. $poi_result[$key] = $poi_sort;
  300. }
  301. //4.获取可查询站点的权限
  302. if($inout_type == 'in'){
  303. $list1 = $poi_result['start_area'];
  304. }else{
  305. $list1 = $poi_result['end_area'];
  306. }
  307. $user_id = $_COOKIE['user_id'];
  308. global $hotel_authority;
  309. if ($bus_type == '256' && isset($hotel_authority[$user_id])) {
  310. if (is_array($hotel_authority[$user_id])) {
  311. foreach ($hotel_authority[$user_id] as $v) {
  312. if(isset($poi_info[$v])){
  313. $area_one['area_id'] = $v;
  314. $area_one['area_name'] = $poi_info[$v]['area_name'];
  315. $list[] = $area_one;
  316. }
  317. }
  318. } else {
  319. if(isset($poi_info[$hotel_authority[$user_id]])) {
  320. $area_one['area_id'] = $hotel_authority[$user_id];
  321. $area_one['area_name'] = $poi_info[$hotel_authority[$user_id]]['area_name'];
  322. $list[] = $area_one;
  323. }
  324. }
  325. $area_one['area_id'] = 3240;
  326. $area_one['area_name'] = $poi_info[3240]['area_name'];
  327. $list[] = $area_one;
  328. $area_one['area_id'] = 100437;
  329. $area_one['area_name'] = $poi_info[100437]['area_name'];
  330. $list[] = $area_one;
  331. } else {
  332. $list = $list1;
  333. }
  334. return $list;
  335. }
  336. ?>