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;