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.
 
 
 
 

905 lines
32 KiB

  1. <?php
  2. /**
  3. *
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 张帅
  12. * PhpStorm site1.php
  13. * Create By 2016/12/1 14:15 $
  14. */
  15. header("Access-Control-Allow-Origin:*");
  16. $user_type = 0;
  17. $pdo=conn();
  18. $back = $_POST['back'];
  19. $operate = $_POST['operate'];
  20. $channel_id = isset($_COOKIE['org_id']) ? $_COOKIE['org_id'] : 0;
  21. //判断去程或返程 1去 2返
  22. if($back == 1){
  23. //判断触发事件
  24. if($operate == 'initial'){
  25. $run_id = $_POST['run_id'];
  26. $start_area_id = $_POST['start_area_id'];
  27. $end_area_id = $_POST['end_area_id'];
  28. $run = getGoRunDetail($run_id, $start_area_id, $end_area_id, $channel_id);
  29. }elseif($operate == 'start'){
  30. $run_id = $_POST['run_id'];
  31. $start_res_id = $_POST['start_res_id'];
  32. $end_area_id = $_POST['end_area_id'];
  33. $line_type = $_POST['line_type'];
  34. $run = getGoRunDetailByStart($run_id, $start_res_id, $end_area_id, $channel_id,$line_type);
  35. }else{
  36. $run_id = $_POST['run_id'];
  37. $start_res_id = $_POST['start_res_id'];
  38. $end_res_id = $_POST['end_res_id'];
  39. $line_type = $_POST['line_type'];
  40. $run = getGoRunDetailByEnd($run_id, $start_res_id, $end_res_id, $channel_id,$line_type);
  41. }
  42. }else{
  43. //判断触发事件
  44. if($operate == 'initial'){
  45. $go_run_id = $_POST['go_run_id'];
  46. $go_start_res_id = $_POST['go_start_res_id'];
  47. $go_end_res_id = $_POST['go_end_res_id'];
  48. $run_id = $_POST['run_id'];
  49. $start_area_id = $_POST['start_area_id'];
  50. $end_area_id = $_POST['end_area_id'];
  51. $run = getBackRunDetail($run_id, $start_area_id, $end_area_id, $channel_id,$go_run_id,$go_start_res_id,$go_end_res_id);
  52. }elseif($operate == 'start'){
  53. $go_run_id = $_POST['go_run_id'];
  54. $go_start_res_id = $_POST['go_start_res_id'];
  55. $go_end_res_id = $_POST['go_end_res_id'];
  56. $run_id = $_POST['run_id'];
  57. $start_res_id = $_POST['start_res_id'];
  58. $end_area_id = $_POST['end_area_id'];
  59. $line_type = $_POST['line_type'];
  60. $run = getBackRunDetailByStart($run_id, $start_res_id, $end_area_id, $channel_id,$line_type,$go_run_id,$go_start_res_id,$go_end_res_id);
  61. }else{
  62. $go_run_id = $_POST['go_run_id'];
  63. $go_start_res_id = $_POST['go_start_res_id'];
  64. $go_end_res_id = $_POST['go_end_res_id'];
  65. $run_id = $_POST['run_id'];
  66. $start_res_id = $_POST['start_res_id'];
  67. $end_res_id = $_POST['end_res_id'];
  68. $line_type = $_POST['line_type'];
  69. $run = getBackRunDetailByEnd($run_id, $start_res_id, $end_res_id, $channel_id,$line_type,$go_run_id,$go_start_res_id,$go_end_res_id);
  70. }
  71. }
  72. $json['code'] = '0';
  73. $json['info'] = '返回数据成功';
  74. $json['list'] = $run;
  75. echo json_encode($json);die;
  76. print_r($run);die;
  77. #region 去程的方法
  78. /**
  79. * Function Description:获取初始化数据
  80. * Function Name: getRunDetail
  81. * @param $run_id
  82. * @param $start_area_id
  83. * @param $end_area_id
  84. * @param $channel_id
  85. *
  86. * @return array|mixed|string
  87. *
  88. * @author 张帅
  89. */
  90. function getGoRunDetail($run_id, $start_area_id, $end_area_id, $channel_id)
  91. {
  92. //获取班次详情
  93. $run_info = getRunInfo($run_id);
  94. $poi = getPoiInfoArr();
  95. $poi_info = $poi['poi_info_array'];
  96. //print_r($poi_info);die;
  97. $run['run_id'] = $run_info['run_id'];
  98. $run['start_area_id'] = $start_area_id;
  99. $run['start_area_name'] = $poi_info[$start_area_id]['area_name'];
  100. $run['end_area_id'] = $end_area_id;
  101. $run['end_area_name'] = $poi_info[$end_area_id]['area_name'];
  102. $run['run_date'] = $run_info['run_date'];
  103. $run['run_time'] = $run_info['run_time'];
  104. $run['line_type'] = $run_info['line_type'];
  105. $line_type = $run['line_type'];
  106. //获取上车站点
  107. $start_res_arr = getStartStation($run_id, $start_area_id);
  108. $run['start_res_arr'] = $start_res_arr;
  109. //获取默认选中的上车站
  110. $start_res_id = $start_res_arr[0]['res_id'];
  111. $run['select_start_res']['res_id'] = $start_res_arr[0]['res_id'];
  112. $run['select_start_res']['res_name'] = $start_res_arr[0]['res_name'];
  113. $run['select_start_res']['res_time'] = $start_res_arr[0]['res_time'];
  114. //获取下车站点
  115. $end_res_arr = getEndStation($run_id, $start_res_id, $end_area_id);
  116. $run['end_res_arr'] = $end_res_arr;
  117. //获取默认选中的上车站
  118. $end_res_id = $end_res_arr[0]['res_id'];
  119. $run['select_end_res']['res_id'] = $end_res_arr[0]['res_id'];
  120. $run['select_end_res']['res_name'] = $end_res_arr[0]['res_name'];
  121. $run['select_end_res']['res_time'] = $end_res_arr[0]['res_time'];
  122. //获取票种信息
  123. $ticket_info = getTicketInfo($run_id, $start_res_id, $end_res_id,$channel_id,$line_type);
  124. $run['ticket_info'] = $ticket_info[0];
  125. return $run;
  126. }
  127. /**
  128. * Function Description:通过上车站点获取初始化数据
  129. * Function Name: getRunDetailByStart
  130. * @param $run_id
  131. * @param $start_res_id
  132. * @param $end_area_id
  133. * @param $channel_id
  134. *
  135. * @return array|mixed|string
  136. *
  137. * @author 张帅
  138. */
  139. function getGoRunDetailByStart($run_id, $start_res_id, $end_area_id, $channel_id,$line_type)
  140. {
  141. //获取下车站点
  142. $end_res_arr = getEndStation($run_id, $start_res_id, $end_area_id);
  143. $run['end_res_arr'] = $end_res_arr;
  144. //获取默认选中的上车站
  145. $end_res_id = $end_res_arr[0]['res_id'];
  146. $run['select_end_res']['res_id'] = $end_res_arr[0]['res_id'];
  147. $run['select_end_res']['res_name'] = $end_res_arr[0]['res_name'];
  148. $run['select_end_res']['res_time'] = $end_res_arr[0]['res_time'];
  149. //获取票种信息
  150. $ticket_info = getTicketInfo($run_id, $start_res_id, $end_res_id,$channel_id,$line_type);
  151. $run['ticket_info'] = $ticket_info[0];
  152. return $run;
  153. }
  154. /**
  155. * Function Description:通过下车站点获取初始化数据
  156. * Function Name: getRunDetailByEnd
  157. * @param $run_id
  158. * @param $start_res_id
  159. * @param $end_res_id
  160. * @param $channel_id
  161. *
  162. * @return array|mixed|string
  163. *
  164. * @author 张帅
  165. */
  166. function getGoRunDetailByEnd($run_id, $start_res_id, $end_res_id, $channel_id,$line_type)
  167. {
  168. //获取票种信息
  169. $ticket_info = getTicketInfo($run_id, $start_res_id, $end_res_id,$channel_id,$line_type);
  170. $run['ticket_info'] = $ticket_info[0];
  171. return $run;
  172. }
  173. #endregion
  174. /**
  175. * Function Description:获取返程初始化数据
  176. * Function Name: getRunDetail
  177. * @param $run_id
  178. * @param $start_area_id
  179. * @param $end_area_id
  180. * @param $channel_id
  181. *
  182. * @return array|mixed|string
  183. *
  184. * @author 张帅
  185. */
  186. function getBackRunDetail($run_id, $start_area_id, $end_area_id, $channel_id,$go_run_id,$go_start_res_id,$go_end_res_id)
  187. {
  188. //获取班次详情
  189. $run_info = getRunInfo($run_id);
  190. $poi = getPoiInfoArr();
  191. $poi_info = $poi['poi_info_array'];
  192. //print_r($poi_info);die;
  193. $run['run_id'] = $run_info['run_id'];
  194. $run['start_area_id'] = $start_area_id;
  195. $run['start_area_name'] = $poi_info[$start_area_id]['area_name'];
  196. $run['end_area_id'] = $end_area_id;
  197. $run['end_area_name'] = $poi_info[$end_area_id]['area_name'];
  198. $run['run_date'] = $run_info['run_date'];
  199. $run['run_time'] = $run_info['run_time'];
  200. $run['line_type'] = $run_info['line_type'];
  201. $line_type = $run['line_type'];
  202. //获取上车站点
  203. $start_res_arr = getStartStation($run_id, $start_area_id);
  204. $run['start_res_arr'] = $start_res_arr;
  205. //获取默认选中的上车站
  206. $start_res_id = $start_res_arr[0]['res_id'];
  207. $run['select_start_res']['res_id'] = $start_res_arr[0]['res_id'];
  208. $run['select_start_res']['res_name'] = $start_res_arr[0]['res_name'];
  209. $run['select_start_res']['res_time'] = $start_res_arr[0]['res_time'];
  210. //获取下车站点
  211. $end_res_arr = getEndStation($run_id, $start_res_id, $end_area_id);
  212. $run['end_res_arr'] = $end_res_arr;
  213. //获取默认选中的上车站
  214. $end_res_id = $end_res_arr[0]['res_id'];
  215. $run['select_end_res']['res_id'] = $end_res_arr[0]['res_id'];
  216. $run['select_end_res']['res_name'] = $end_res_arr[0]['res_name'];
  217. $run['select_end_res']['res_time'] = $end_res_arr[0]['res_time'];
  218. //获取票种信息
  219. $ticket_info = getBackTicketInfo($run_id, $start_res_id, $end_res_id,$channel_id,$line_type,$go_run_id,$go_start_res_id,$go_end_res_id);
  220. $run['ticket_info'] = $ticket_info[0];
  221. return $run;
  222. }
  223. /**
  224. * Function Description:通过上车站点获取初始化数据 --返程
  225. * Function Name: getRunDetailByStart
  226. * @param $run_id
  227. * @param $start_res_id
  228. * @param $end_area_id
  229. * @param $channel_id
  230. *
  231. * @return array|mixed|string
  232. *
  233. * @author 张帅
  234. */
  235. function getBackRunDetailByStart($run_id, $start_res_id, $end_area_id, $channel_id,$line_type,$go_run_id,$go_start_res_id,$go_end_res_id)
  236. {
  237. //获取下车站点
  238. $end_res_arr = getEndStation($run_id,$start_res_id, $end_area_id);
  239. $run['end_res_arr'] = $end_res_arr;
  240. //获取默认选中的上车站
  241. $end_res_id = $end_res_arr[0]['res_id'];
  242. $run['select_end_res']['res_id'] = $end_res_arr[0]['res_id'];
  243. $run['select_end_res']['res_name'] = $end_res_arr[0]['res_name'];
  244. $run['select_end_res']['res_time'] = $end_res_arr[0]['res_time'];
  245. //获取票种信息
  246. $ticket_info = getBackTicketInfo($run_id, $start_res_id, $end_res_id,$channel_id,$line_type,$go_run_id,$go_start_res_id,$go_end_res_id);
  247. $run['ticket_info'] = $ticket_info[0];
  248. return $run;
  249. }
  250. /**
  251. * Function Description:通过下车站点获取初始化数据 --返程
  252. * Function Name: getRunDetailByEnd
  253. * @param $run_id
  254. * @param $start_res_id
  255. * @param $end_res_id
  256. * @param $channel_id
  257. *
  258. * @return array|mixed|string
  259. *
  260. * @author 张帅
  261. */
  262. function getBackRunDetailByEnd($run_id, $start_res_id, $end_res_id, $channel_id,$line_type,$go_run_id,$go_start_res_id,$go_end_res_id)
  263. {
  264. //获取票种信息
  265. // $ticket_info = getTicketInfo($run_id, $start_res_id, $end_res_id,$channel_id,$line_type,$go_run_id,$go_start_res_id,$go_end_res_id);
  266. $ticket_info = getBackTicketInfo($run_id, $start_res_id, $end_res_id,$channel_id,$line_type,$go_run_id,$go_start_res_id,$go_end_res_id);
  267. $run['ticket_info'] = $ticket_info[0];
  268. return $run;
  269. }
  270. /**
  271. * Function Description:获取班次信息详情
  272. * Function Name: getRunInfo
  273. * @param $run_id
  274. *
  275. * @return mixed
  276. *
  277. * @author 张帅
  278. */
  279. function getRunInfo($run_id)
  280. {
  281. global $pdo;
  282. $sql = 'SELECT
  283. r.run_id,r.run_date,r.run_time,l.line_name,l.line_code,l.line_id,l.line_type
  284. FROM
  285. run_main AS r,
  286. opera_line AS l
  287. WHERE
  288. r.prod_id = l.line_id
  289. AND r.run_id = ' . $run_id . '
  290. AND l.cancel_flag = 0
  291. AND l.is_onsale = 1
  292. AND l.if_disabled = 0
  293. AND r.run_status = 138
  294. LIMIT 1';
  295. $result = $pdo->query($sql);
  296. $run_info = $result->fetchAll(PDO::FETCH_ASSOC);
  297. return $run_info[0];
  298. }
  299. /**
  300. * Function Description:获取上车站点数据
  301. * Function Name: getStartStation
  302. * @param $run_id
  303. * @param $start_area_id
  304. *
  305. * @return array
  306. *
  307. * @author 张帅
  308. */
  309. function getStartStation($run_id, $start_area_id)
  310. {
  311. global $pdo;
  312. $sql = 'SELECT
  313. run_prod.start_station_res_id as res_id,
  314. (SELECT res_name FROM base_resource WHERE res_id = run_prod.start_station_res_id LIMIT 1) as res_name,
  315. (SELECT start_time from run_station where run_id = run_prod.run_id and station_res_id = run_prod.start_station_res_id LIMIT 1) as res_time
  316. FROM
  317. run_prod
  318. LEFT JOIN run_station as rs ON rs.run_id = run_prod.run_id AND rs.station_res_id = run_prod.start_station_res_id
  319. WHERE
  320. run_prod.run_id = ' . $run_id . '
  321. AND run_prod.start_station_area_id = ' . $start_area_id . '
  322. AND run_prod.cancel_flag = 0
  323. AND rs.station_inout_type <> 114
  324. AND (SELECT ticket_type FROM opera_tickets WHERE ticket_id = run_prod.prod_id AND cancel_flag = 0) = 1
  325. GROUP BY run_prod.start_station_res_id';
  326. $result = $pdo->query($sql);
  327. $start_station = $result->fetchAll(PDO::FETCH_ASSOC);
  328. $user_id =$_COOKIE['user_id'];
  329. $status = 0;
  330. if($user_id == 141){
  331. foreach ($start_station as $k => $v) {
  332. if($v['res_id'] == 9680){
  333. $status = 1;
  334. $station_arr = $v;
  335. }
  336. }
  337. }elseif($user_id == 121){
  338. foreach ($start_station as $k => $v) {
  339. if ($v['res_id'] == 9321) {
  340. $status = 1;
  341. $station_arr = $v;
  342. }
  343. }
  344. }
  345. if($status == 1){
  346. $start_station = array();
  347. $start_station[0] = $station_arr;
  348. }
  349. return $start_station;
  350. }
  351. /**
  352. * Function Description:获取下车站点数据
  353. * Function Name: getEndStation
  354. * @param $run_id
  355. * @param $run_id
  356. * @param $start_res_id
  357. * @param $end_area_id
  358. *
  359. * @return array
  360. *
  361. * @author 张帅
  362. */
  363. function getEndStation($run_id, $start_res_id, $end_area_id)
  364. {
  365. global $pdo;
  366. $sql = 'SELECT
  367. run_prod.end_station_res_id as res_id,
  368. (SELECT res_name FROM base_resource WHERE res_id = run_prod.end_station_res_id LIMIT 1) as res_name,
  369. (SELECT start_time from run_station where run_id = run_prod.run_id and station_res_id = run_prod.end_station_res_id LIMIT 1) as res_time
  370. FROM
  371. run_prod
  372. LEFT JOIN run_station as rs ON rs.run_id = run_prod.run_id AND rs.station_res_id = run_prod.end_station_res_id
  373. WHERE
  374. run_prod.run_id = ' . $run_id . '
  375. AND run_prod.end_station_area_id = ' . $end_area_id . '
  376. AND run_prod.cancel_flag = 0
  377. AND rs.station_inout_type <> 114
  378. AND run_prod.start_station_res_id = ' . $start_res_id . '
  379. AND (SELECT ticket_type FROM opera_tickets WHERE ticket_id = run_prod.prod_id AND cancel_flag = 0) = 1
  380. GROUP BY run_prod.end_station_res_id';
  381. $result = $pdo->query($sql);
  382. $end_station = $result->fetchAll(PDO::FETCH_ASSOC);
  383. $user_id =$_COOKIE['user_id'];
  384. $status = 0;
  385. if($user_id == 141){
  386. foreach ($end_station as $k => $v) {
  387. if($v['res_id'] == 9680){
  388. $status = 1;
  389. $station_arr = $v;
  390. }
  391. }
  392. }elseif($user_id == 121){
  393. foreach ($end_station as $k => $v) {
  394. if ($v['res_id'] == 9321) {
  395. $status = 1;
  396. $station_arr = $v;
  397. }
  398. }
  399. }
  400. if($status == 1){
  401. $end_station = array();
  402. $end_station[0] = $station_arr;
  403. }
  404. return $end_station;
  405. }
  406. /**
  407. * Function Description:获取票种信息
  408. * Function Name: getTicketInfo
  409. * @param $run_id
  410. * @param $start_res_id
  411. * @param $end_res_id
  412. *
  413. * @return array
  414. *
  415. * @author 张帅
  416. */
  417. function getTicketInfo($run_id, $start_res_id, $end_res_id,$channel_id,$line_type)
  418. {
  419. global $pdo;
  420. $sql = "SELECT
  421. ticket_id,seat_type,
  422. (SELECT type_name FROM dict_type WHERE id = seat_type LIMIT 1) AS seat_type_name,
  423. human_type,
  424. (SELECT type_name FROM dict_type WHERE id = human_type LIMIT 1) AS human_type_name,
  425. prod_price, cus_price,
  426. (
  427. SELECT
  428. min(total_count - saled_count)
  429. FROM
  430. run_stock
  431. WHERE
  432. run_id = " . $run_id . "
  433. AND cancel_flag = 0
  434. AND seq_id >= (SELECT seq_id FROM run_stock WHERE run_id = " . $run_id . " AND cancel_flag = 0 AND res_id = " . $start_res_id . " AND seat_type = opera_tickets.seat_type limit 1)
  435. AND seq_id < (SELECT seq_id FROM run_stock WHERE run_id = " . $run_id . " AND cancel_flag = 0 AND res_id = " . $end_res_id . " AND seat_type = opera_tickets.seat_type limit 1)
  436. AND seat_type = opera_tickets.seat_type
  437. ) AS stock
  438. FROM
  439. opera_tickets
  440. WHERE
  441. ticket_type = 1
  442. AND ticket_id IN (
  443. SELECT
  444. prod_id
  445. FROM
  446. run_prod
  447. WHERE
  448. run_id = " . $run_id . "
  449. AND start_station_res_id = " . $start_res_id . "
  450. AND end_station_res_id = " . $end_res_id . "
  451. )
  452. AND cancel_flag = 0";
  453. $result = $pdo->query($sql);
  454. $ticket_info = $result->fetchAll(PDO::FETCH_ASSOC);
  455. if (count($ticket_info) == 0) {
  456. return array();
  457. }
  458. foreach ($ticket_info as $k => $v) {
  459. $sale_type = getTicketChannelSaleType($channel_id, $v['ticket_id'], $line_type);//获取销售类型
  460. if ($sale_type)//如果该销售方式被关掉
  461. {
  462. if ($sale_type['sale_type'] == "177") {
  463. if ($sale_type['price'] == '0') {
  464. $ticket_info[$k]['price'] = $v['prod_price'];
  465. } else {
  466. $ticket_info[$k]['price'] = $sale_type['price'];
  467. }
  468. } else {
  469. $ticket_info[$k]['price'] = $v['cus_price'];
  470. }
  471. //$ticket_info[$k]['price'] = $v['cus_price'];//暂时全部都是销售价格
  472. } else {
  473. unset($ticket_info[$k]);
  474. }
  475. }
  476. return $ticket_info;
  477. }
  478. /**
  479. * 获取返程票种详情
  480. */
  481. function getBackTicketInfo($back_run_id, $back_start_res_id, $back_end_res_id,$channel_id,$line_type,$go_run_id,$go_start_res_id,$go_end_res_id){
  482. global $pdo;
  483. $go_ticket_info = getTicketInfo($go_run_id,$go_start_res_id,$go_end_res_id,$channel_id,$line_type);
  484. $back_ticket_info = getTicketInfo($back_run_id, $back_start_res_id, $back_end_res_id,$channel_id,$line_type);
  485. foreach ($go_ticket_info as $k => $v) {
  486. $go_ticket_array[$v['seat_type'] . "-" . $v['human_type']] = $v;
  487. $ticket_array_id[] = $v['ticket_id'];
  488. }
  489. foreach ($back_ticket_info as $k => $v) {
  490. $back_ticket_array[$v['seat_type'] . "-" . $v['human_type']] = $v;
  491. $ticket_array_id[] = $v['ticket_id'];
  492. }
  493. //获取促销优惠
  494. $sql = "SELECT
  495. ticket_id,
  496. off_value
  497. FROM
  498. opera_tickets_discount
  499. WHERE
  500. ticket_id IN (" . implode(",", $ticket_array_id) . ")
  501. AND supplier_id = " . $channel_id . "
  502. AND is_onsale = 1
  503. AND cancel_flag = 0
  504. AND discount_type = 332
  505. AND discount_day_type = 0
  506. GROUP BY ticket_id";
  507. $result = $pdo->query($sql);
  508. $discount_info = $result->fetchAll(PDO::FETCH_ASSOC);
  509. $discount_info_array = array();
  510. if (count($discount_info) > 0) {
  511. foreach ($discount_info as $k => $v) {
  512. $discount_info_array[$v['ticket_id']] = $v['off_value'];
  513. }
  514. }
  515. foreach ($go_ticket_array as $k => $v) {
  516. if (isset($back_ticket_array[$k])) {
  517. $go_discount = '0';
  518. if (isset($discount_info_array[$go_ticket_array[$k]['ticket_id']])) {
  519. $go_discount = $discount_info_array[$go_ticket_array[$k]['ticket_id']];
  520. }
  521. $back_discount = '0';
  522. if (isset($discount_info_array[$back_ticket_array[$k]['ticket_id']])) {
  523. $back_discount = $discount_info_array[$back_ticket_array[$k]['ticket_id']];
  524. }
  525. $ticket_one = array(
  526. 'go_run_id' => $go_run_id,
  527. 'go_ticket_id' => $go_ticket_array[$k]['ticket_id'],
  528. 'go_price' => $go_ticket_array[$k]['price'],
  529. 'go_discount_price' => $go_ticket_array[$k]['price'] - $go_discount,
  530. 'go_discount' => $go_discount,
  531. 'go_stock' => $go_ticket_array[$k]['stock'],
  532. 'back_run_id' => $back_run_id,
  533. 'back_ticket_id' => $back_ticket_array[$k]['ticket_id'],
  534. 'back_price' => $back_ticket_array[$k]['price'],
  535. 'back_discount_price' => $back_ticket_array[$k]['price'] - $back_discount,
  536. 'back_discount' => $back_discount,
  537. 'back_stock' => $back_ticket_array[$k]['stock'],
  538. 'seat_type' => $go_ticket_array[$k]['seat_type'],
  539. 'seat_type_name' => $go_ticket_array[$k]['seat_type_name'],
  540. 'human_type' => $go_ticket_array[$k]['human_type'],
  541. 'human_type_name' => $go_ticket_array[$k]['human_type_name'],
  542. 'price' => $go_ticket_array[$k]['price'] + $back_ticket_array[$k]['price'] - $go_discount - $back_discount,
  543. 'stock' => min($go_ticket_array[$k]['stock'], $back_ticket_array[$k]['stock'])
  544. );
  545. $ticket_array[] = $ticket_one;
  546. }
  547. }
  548. return $ticket_array;
  549. }
  550. /**
  551. * Function Description:获取渠道价
  552. * Function Name: getTicketChannelSaleType
  553. * @param $channel_id
  554. * @param $ticket_id
  555. * @param $line_type
  556. *
  557. * @return bool
  558. *
  559. * @author 张帅
  560. */
  561. function getTicketChannelSaleType($channel_id, $ticket_id, $line_type)
  562. {
  563. global $pdo;
  564. $channel_id = $_COOKIE['org_id'];
  565. $sql = "select supplier_name from base_supplier WHERE id = " . $channel_id . " and cancel_flag = 0";
  566. $result = $pdo->query($sql);
  567. $supplier_count = $result->fetchAll(PDO::FETCH_ASSOC);
  568. if(count($supplier_count) == 0){
  569. $channel_id = 39;
  570. }
  571. $sql = "SELECT
  572. sale_type,
  573. '0' as price
  574. FROM
  575. base_supplier_sale as a
  576. WHERE
  577. NOT EXISTS
  578. (
  579. SELECT
  580. supplier_id
  581. FROM
  582. opera_tickets_distrib
  583. WHERE
  584. supplier_id = a.supplier_id
  585. AND ticket_id = " . $ticket_id . "
  586. AND cancel_flag = 0
  587. )
  588. AND supplier_id = " . $channel_id . "
  589. AND parent_type = 310
  590. AND product_type IN (" . $line_type . ", 0)
  591. AND cancel_flag = 0
  592. UNION ALL
  593. SELECT
  594. sale_type,
  595. prod_price as price
  596. FROM
  597. opera_tickets_distrib
  598. WHERE
  599. supplier_id = " . $channel_id . "
  600. AND ticket_id = " . $ticket_id . "
  601. AND authority_status = 1
  602. AND cancel_flag = 0";
  603. $result = $pdo->query($sql);
  604. $sale_type = $result->fetchAll(PDO::FETCH_ASSOC);
  605. if (count($sale_type) == 0) {
  606. return false;
  607. }
  608. $sale_type = $sale_type[0];
  609. return $sale_type;
  610. }
  611. #region 站点详情
  612. //------------------------------------------------------------------------------------------------------------------------------------------------------------
  613. /**
  614. * 站点详情
  615. */
  616. /**
  617. * Function Description:获取所有线路中开始POI-结束POI的连接关系
  618. * Function Name: getPoiId
  619. *
  620. * @return mixed
  621. *
  622. * @author 张帅
  623. */
  624. function getPoiId()
  625. {
  626. global $pdo;
  627. $sql = 'SELECT
  628. start_area,
  629. end_area,
  630. line_type
  631. FROM
  632. (
  633. SELECT
  634. SUBSTRING_INDEX(SUBSTRING_INDEX(b.start_area, \',\', sequence.help_topic_id),\',\' ,-1) AS start_area,
  635. SUBSTRING_INDEX(SUBSTRING_INDEX(b.end_area, \',\', sequence1.help_topic_id),\',\' ,-1) AS end_area,
  636. line_type
  637. FROM
  638. mysql.help_topic as sequence,
  639. mysql.help_topic as sequence1,
  640. (
  641. SELECT @id := @id +1 as id,
  642. if(length(start_parent)=0,start_area_id,concat(start_area_id,\',\',start_parent)) as start_area,
  643. if(length(end_parent)=0,end_area_id,concat(end_area_id,\',\',end_parent)) as end_area,
  644. line_type
  645. FROM (
  646. SELECT distinct
  647. t.start_station_area_id as start_area_id,
  648. replace(substring(v1.parent_area_id_list,2,length(v1.parent_area_id_list)-2),\'}{\',\',\') AS start_parent,
  649. t.end_station_area_id as end_area_id,
  650. replace(substring(v2.parent_area_id_list,2,length(v2.parent_area_id_list)-2),\'}{\',\',\') AS end_parent,
  651. l.line_type
  652. FROM
  653. opera_line AS l,
  654. opera_tickets AS t,
  655. base_area_view as v1,
  656. base_area_view as v2,
  657. base_area as a1,
  658. base_area as a2
  659. WHERE
  660. l.line_id = t.line_id
  661. and v1.area_id = t.start_station_area_id
  662. and v2.area_id = t.end_station_area_id
  663. and a1.id = t.start_station_area_id
  664. and a2.id = t.end_station_area_id
  665. and a1.cancel_flag = 0
  666. and a2.cancel_flag = 0
  667. AND l.cancel_flag = 0
  668. AND l.if_disabled = 0
  669. AND l.line_type in(255,256)
  670. AND l.is_onsale = 1
  671. AND t.cancel_flag = 0
  672. AND t.start_station_area_id != 0
  673. AND t.end_station_area_id != 0
  674. ) a,
  675. (select @id:= 0) as i
  676. ) b
  677. WHERE
  678. sequence.help_topic_id BETWEEN 1 AND ( SELECT 1 + LENGTH(b.start_area) - LENGTH(REPLACE(b.start_area, \',\', \'\')))
  679. AND sequence1.help_topic_id BETWEEN 1 AND ( SELECT 1 + LENGTH(b.end_area) - LENGTH(REPLACE(b.end_area, \',\', \'\')))
  680. GROUP BY
  681. SUBSTRING_INDEX(SUBSTRING_INDEX(b.start_area, \',\', sequence.help_topic_id),\',\' ,-1),
  682. SUBSTRING_INDEX(SUBSTRING_INDEX(b.end_area, \',\', sequence1.help_topic_id),\',\' ,-1),
  683. line_type
  684. )as tb';
  685. $result = $pdo->query($sql);
  686. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  687. return $rowset;
  688. }
  689. /**
  690. * Function Description:获取poi详情
  691. * Function Name: getPoiInfo
  692. * @param $poi_id
  693. *
  694. * @return array
  695. *
  696. * @author 张帅
  697. */
  698. function getPoiInfoDb($poi_id)
  699. {
  700. global $pdo;
  701. $sql = 'SELECT
  702. a.id as area_id,
  703. a.area_name,
  704. a.poi_type,
  705. REPLACE(substring(v.parent_area_id_list,2,length(v.parent_area_id_list)-2),\'}{\',\',\') AS parent_area_id,
  706. REPLACE(REPLACE(substring(v.parent_area_name_list,2),\'}{\',\',\'),\'}\',\'\') AS parent_area_name,
  707. v.area_level
  708. FROM
  709. base_area AS a,
  710. base_area_view AS v
  711. WHERE
  712. a.id = v.area_id
  713. AND a.cancel_flag = 0
  714. AND a.id in (' . $poi_id . ')';
  715. $result = $pdo->query($sql);
  716. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  717. return $rowset;
  718. }
  719. /**
  720. * Function Description:获取站点详情
  721. * Function Name: getPoiInfoArr
  722. *
  723. * @return array|mixed
  724. *
  725. * @author 张帅
  726. */
  727. function getPoiInfoArr()
  728. {
  729. $result = get_memcache('FX_POI_ARR_LIST');
  730. if ($result) {
  731. return $result;
  732. }
  733. //1.获取POIid数组
  734. $poi_id = getPoiIdArr();
  735. //2.收集所有的poi_id
  736. $area_id_array = array();
  737. foreach ($poi_id as $key => $value) {
  738. if (!isset($area_id_array[$value['start_area']])) {
  739. $area_id_array[$value['start_area']] = $value['start_area'];
  740. }
  741. if (!isset($area_id_array[$value['end_area']])) {
  742. $area_id_array[$value['end_area']] = $value['end_area'];
  743. }
  744. }
  745. $poi_id = array_merge($poi_id);
  746. //3.根据poi_id获取poi详细信息
  747. if (count($area_id_array) > 0) {
  748. $poi_info_array1 = getPoiInfo($area_id_array);
  749. } else {
  750. $poi_info_array1 = array();
  751. }
  752. foreach ($poi_info_array1 as $key => $vel){
  753. $poi_info_array[$vel['area_id']] = $vel;
  754. }
  755. //4.根据线路类型及上下车类型对poi分组
  756. $poi_line_inout = getPoiByLineInout($poi_id);
  757. $result['poi_id'] = $poi_id;
  758. $result['poi_info_array'] = $poi_info_array;
  759. $result['poi_line_inout'] = $poi_line_inout;
  760. set_memcache('FX_POI_ARR_LIST', $result, 3600);
  761. return $result;
  762. }
  763. /**
  764. * Function Description:获取poi站点数组
  765. * Function Name: getPoiIdArr
  766. *
  767. * @return array
  768. *
  769. * @author 张帅
  770. */
  771. function getPoiIdArr()
  772. {
  773. $poi_array = getPoiId();
  774. return $poi_array;
  775. }
  776. /**
  777. * Function Description:获取poi详细信息
  778. * Function Name: getPoiInfo
  779. * @param $area_id_array
  780. *
  781. * @return array
  782. *
  783. * @author 张帅
  784. */
  785. function getPoiInfo($area_id_array)
  786. {
  787. $area_id_array = implode(',', $area_id_array);
  788. //1.获取POI的详细信息
  789. $poi_array = getPoiInfoDb($area_id_array);
  790. //2.整理poi数组
  791. $poi_info_array = array();
  792. foreach ($poi_array as $key => $vel) {
  793. $poi_info_array[$vel['area_id']] = $vel;
  794. }
  795. //3.整理poi的父子关系
  796. foreach ($poi_info_array as $key => $vel) {
  797. if (!empty($vel['parent_area_id'])) {
  798. $parent_id_arr = explode(',', $vel['parent_area_id']);
  799. $parent_name_arr = explode(',', $vel['parent_area_name']);
  800. $parent_area_arr = array();
  801. foreach ($parent_id_arr as $k => $v) {
  802. $parent_area_arr[$k]['area_id'] = $v;
  803. $parent_area_arr[$k]['area_name'] = $parent_name_arr[$k];
  804. $poi_info_array[$v]['son_area_id'][$key] = $key;
  805. }
  806. $poi_info_array[$key]['parent_area_arr'] = $parent_area_arr;
  807. } else {
  808. $poi_info_array[$key]['parent_area_arr'] = array();
  809. }
  810. }
  811. foreach ($poi_info_array as $key => $vel) {
  812. if (!isset($vel['son_area_id'])) {
  813. $poi_info_array[$key]['son_area_id'] = '';
  814. } else {
  815. $poi_info_array[$key]['son_area_id'] = implode(',', $vel['son_area_id']);
  816. }
  817. }
  818. return $poi_info_array;
  819. }
  820. /**
  821. * Function Description:根据线路类型及上下车类型对poi分组
  822. * Function Name: getPoiByLineInout
  823. * @param $poi_id
  824. *
  825. * @return mixed
  826. *
  827. * @author 张帅
  828. */
  829. function getPoiByLineInout($poi_id)
  830. {
  831. $poi_group = array();
  832. foreach ($poi_id as $k => $v) {
  833. if (!isset($poi_group[$v['line_type']]['start_area'][$v['start_area']])) {
  834. $poi_group[$v['line_type']]['start_area'][$v['start_area']] = $v['start_area'];
  835. }
  836. if (!isset($poi_group[$v['line_type']]['end_area'][$v['end_area']])) {
  837. $poi_group[$v['line_type']]['end_area'][$v['end_area']] = $v['end_area'];
  838. }
  839. }
  840. return $poi_group;
  841. }
  842. #endregion