|
- <?php
- /**
- * Created by PhpStorm.
- * User: Steven
- * Date: 2016/8/25
- * Time: 20:18
- * 根据出发地、目的地、日期获取班次信息
- */
- header("Access-Control-Allow-Origin:*");
- date_default_timezone_set('PRC');
- require_once __DIR__.'/common.php';
-
- class runList extends virtifyUsers
- {
- public function getRunList($PAGE, $PAGE_SIZE, $RUN_DATE, $RUN_LINE)
- {
- $pdo = conn();
- $pdo1 = conn();
- if($RUN_DATE==date("Y-m-d",time()))
- {
- $RUN_DATE=date("Y-m-d H:i",time());
- }else
- {
- $RUN_DATE=date('Y-m-d H:i',strtotime($RUN_DATE));
- }
- $sql = "CALL SP_CHOICE_KICKET('1','" . $PAGE . "','" . $PAGE_SIZE . "','','','" . $RUN_DATE . "','','" . $RUN_LINE . "')";
- if (is_object($pdo)) {
- $stmt = $pdo->query($sql);
- $i = 1;
- if ($stmt) {
- $data['code'] = '0';
- $data['info'] = '';
- do {
- $rowset = $stmt->fetchAll(PDO::FETCH_ASSOC);
- if ($i == 1) {
- $data['currpage'] = $rowset[0]['currpage'];
- $data['total_page'] = $rowset[0]['total_page'];
- $data['total'] = $rowset[0]['total'];
- $data['page_size'] = $rowset[0]['page_size'];
- } else if ($i == 2) {
- $ticket = array();
- foreach ($rowset as $k => $v) { //遍历班次,车次,库存相加,班次归类。
- $ticket_info = $v;
- if (!isset($ticket[$v['run_id']])) {
-
- $ticket[$v['run_id']] = $ticket_info;
- $sql = "select prod_id from opera_product where parent_id = " . $ticket[$v['run_id']]['prod_id'] . " and ticket_mark = 1 and cancel_flag = 0";
- $result = $pdo1->query($sql);
- $ticket_id = $result->fetchAll(PDO::FETCH_ASSOC);
- $result->closeCursor();
- $ticket[$v['run_id']]['ticket_id'] = $ticket_id[0]['prod_id'];
-
- } else {
- $ticket[$v['run_id']]['stock'] += $v['stock'];
- }
- $ticket = array_values($ticket);
- }
- $data['total'] = count($ticket);
- $data['total_page'] = ceil(count($ticket) / $data['page_size']);
- $tic_tem =array();
- foreach ($ticket as $v) {
- if($v['prod_id'] == 449860 ||$v['prod_id'] == 449865 ){
- $v['line_name'] = "元通浦口线";
- $v['need_time'] = "3小时10分钟";
- }else if($v['prod_id'] == 450037 || $v['prod_id'] == 450036 ) {
- $v['line_name'] = "南站仙林线";
- $v['need_time'] = "3小时10分钟";
- }else if( $v['prod_id'] == 450539 ) {
- $v['line_name'] = "南京淮安线";
- $v['need_time'] = "3小时40分钟";
- }else {
- $v['line_name'] = "淮安南京线";
- $v['need_time'] = "3小时40分钟";
- }
- $tic_tem[] = $v;
- }
- $data['ticket'] = $tic_tem;
- } else {
- }
- $i++;
- } while ($stmt->nextRowset());
- } else {
- $data['code'] = '1';
- $data['info'] = '查询失败';
- }
- if ($stmt) {
- $stmt->closeCursor();
- }
- }
- if (is_array($data)) {
- return $data;
- }
- }
- }
-
- $RUN_LINE = $_POST['start_area'];
- $PAGE = isset($_POST['page']) ? $_POST['page'] : 1;
- $PAGE_SIZE = isset($_POST['page_size']) ? $_POST['page_size'] : 5;
- $RUN_DATE = isset($_POST['startDate']) ? $_POST['startDate'] : date('Y-m-d', time());
- if (!$RUN_LINE) {
- return false;
- }
-
- if($RUN_LINE =='nj'){
- $RUN_LINE = array(449860,450036);
-
- } else if($RUN_LINE =='nt'){
- $RUN_LINE = array(449865,450037);
- }else if($RUN_LINE =='njha'){
- $RUN_LINE = array(450539);
- }else {
- $RUN_LINE = array(450544);
- }
-
- $runList = new runList();
- $data_t = array();
- foreach($RUN_LINE as $v){
- $res = $runList->getRunList($PAGE, $PAGE_SIZE, $RUN_DATE, $v);
- $data_t = array_merge($data_t,$res['ticket']);
- }
- $arr_t = array();
- $i = 1;
- foreach ($data_t as $k=>$v) {
- if(!isset($arr_t[$v['start_time']])){
- $arr_t[$v['start_time']] = $v;
- }else{
- $arr_t[$v['start_time'] . ':0' . $i] = $v;
- $i++;
- }
- }
- ksort($arr_t);
- $data_t = array_values($arr_t);
- echo json_encode(array('code'=>'0','info'=>'','ticket'=>$data_t));
|