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.
 
 
 
 
 

135 lines
5.1 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Steven
  5. * Date: 2016/8/25
  6. * Time: 20:18
  7. * 根据出发地、目的地、日期获取班次信息
  8. */
  9. header("Access-Control-Allow-Origin:*");
  10. date_default_timezone_set('PRC');
  11. require_once __DIR__.'/common.php';
  12. class runList extends virtifyUsers
  13. {
  14. public function getRunList($PAGE, $PAGE_SIZE, $RUN_DATE, $RUN_LINE)
  15. {
  16. $pdo = conn();
  17. $pdo1 = conn();
  18. if($RUN_DATE==date("Y-m-d",time()))
  19. {
  20. $RUN_DATE=date("Y-m-d H:i",time());
  21. }else
  22. {
  23. $RUN_DATE=date('Y-m-d H:i',strtotime($RUN_DATE));
  24. }
  25. $sql = "CALL SP_CHOICE_KICKET('1','" . $PAGE . "','" . $PAGE_SIZE . "','','','" . $RUN_DATE . "','','" . $RUN_LINE . "')";
  26. if (is_object($pdo)) {
  27. $stmt = $pdo->query($sql);
  28. $i = 1;
  29. if ($stmt) {
  30. $data['code'] = '0';
  31. $data['info'] = '';
  32. do {
  33. $rowset = $stmt->fetchAll(PDO::FETCH_ASSOC);
  34. if ($i == 1) {
  35. $data['currpage'] = $rowset[0]['currpage'];
  36. $data['total_page'] = $rowset[0]['total_page'];
  37. $data['total'] = $rowset[0]['total'];
  38. $data['page_size'] = $rowset[0]['page_size'];
  39. } else if ($i == 2) {
  40. $ticket = array();
  41. foreach ($rowset as $k => $v) { //遍历班次,车次,库存相加,班次归类。
  42. $ticket_info = $v;
  43. if (!isset($ticket[$v['run_id']])) {
  44. $ticket[$v['run_id']] = $ticket_info;
  45. $sql = "select prod_id from opera_product where parent_id = " . $ticket[$v['run_id']]['prod_id'] . " and ticket_mark = 1 and cancel_flag = 0";
  46. $result = $pdo1->query($sql);
  47. $ticket_id = $result->fetchAll(PDO::FETCH_ASSOC);
  48. $result->closeCursor();
  49. $ticket[$v['run_id']]['ticket_id'] = $ticket_id[0]['prod_id'];
  50. } else {
  51. $ticket[$v['run_id']]['stock'] += $v['stock'];
  52. }
  53. $ticket = array_values($ticket);
  54. }
  55. $data['total'] = count($ticket);
  56. $data['total_page'] = ceil(count($ticket) / $data['page_size']);
  57. $tic_tem =array();
  58. foreach ($ticket as $v) {
  59. if($v['prod_id'] == 449860 ||$v['prod_id'] == 449865 ){
  60. $v['line_name'] = "元通浦口线";
  61. $v['need_time'] = "3小时10分钟";
  62. }else if($v['prod_id'] == 450037 || $v['prod_id'] == 450036 ) {
  63. $v['line_name'] = "南站仙林线";
  64. $v['need_time'] = "3小时10分钟";
  65. }else if( $v['prod_id'] == 450539 ) {
  66. $v['line_name'] = "南京淮安线";
  67. $v['need_time'] = "3小时40分钟";
  68. }else {
  69. $v['line_name'] = "淮安南京线";
  70. $v['need_time'] = "3小时40分钟";
  71. }
  72. $tic_tem[] = $v;
  73. }
  74. $data['ticket'] = $tic_tem;
  75. } else {
  76. }
  77. $i++;
  78. } while ($stmt->nextRowset());
  79. } else {
  80. $data['code'] = '1';
  81. $data['info'] = '查询失败';
  82. }
  83. if ($stmt) {
  84. $stmt->closeCursor();
  85. }
  86. }
  87. if (is_array($data)) {
  88. return $data;
  89. }
  90. }
  91. }
  92. $RUN_LINE = $_POST['start_area'];
  93. $PAGE = isset($_POST['page']) ? $_POST['page'] : 1;
  94. $PAGE_SIZE = isset($_POST['page_size']) ? $_POST['page_size'] : 5;
  95. $RUN_DATE = isset($_POST['startDate']) ? $_POST['startDate'] : date('Y-m-d', time());
  96. if (!$RUN_LINE) {
  97. return false;
  98. }
  99. if($RUN_LINE =='nj'){
  100. $RUN_LINE = array(449860,450036);
  101. } else if($RUN_LINE =='nt'){
  102. $RUN_LINE = array(449865,450037);
  103. }else if($RUN_LINE =='njha'){
  104. $RUN_LINE = array(450539);
  105. }else {
  106. $RUN_LINE = array(450544);
  107. }
  108. $runList = new runList();
  109. $data_t = array();
  110. foreach($RUN_LINE as $v){
  111. $res = $runList->getRunList($PAGE, $PAGE_SIZE, $RUN_DATE, $v);
  112. $data_t = array_merge($data_t,$res['ticket']);
  113. }
  114. $arr_t = array();
  115. $i = 1;
  116. foreach ($data_t as $k=>$v) {
  117. if(!isset($arr_t[$v['start_time']])){
  118. $arr_t[$v['start_time']] = $v;
  119. }else{
  120. $arr_t[$v['start_time'] . ':0' . $i] = $v;
  121. $i++;
  122. }
  123. }
  124. ksort($arr_t);
  125. $data_t = array_values($arr_t);
  126. echo json_encode(array('code'=>'0','info'=>'','ticket'=>$data_t));