|
- <?php
- /**
- * Created by PhpStorm.
- * User: Steven
- * Date: 2016/8/25
- * Time: 20:18
- * 根据出发地、目的地、日期获取班次信息
- */
- 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']);
- $data['ticket'] = $ticket;
- } else {
- }
- $i++;
- } while ($stmt->nextRowset());
- } else {
- $data['code'] = '1';
- $data['info'] = '查询失败';
- }
- if ($stmt) {
- $stmt->closeCursor();
- }
- }
- if (is_array($data)) {
- return json_encode($data);
- }
- }
- }
-
- $RUN_LINE = $_POST['prod_id'];
- $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;
- }
- $runList = new runList();
- $res = $runList->getRunList($PAGE, $PAGE_SIZE, $RUN_DATE, $RUN_LINE);
- echo $res;
-
-
|