|
- <?php
- require_once '../st-xm/Common/Mysql.php';
- header("Access-Control-Allow-Origin:*");
- //error_reporting('E_ALL & ~E_NOTICE');
- date_default_timezone_set('Asia/Shanghai');
- $today = date('Y-m-d');
- $tomorrow = date('Y-m-d', strtotime('+1 day'));
- $nextWeek = date('Y-m-d', strtotime('+1 week'));
- $nextMonth = date('Y-m-d', strtotime("+1 month"));
-
- $today_x = date('Ym');
- $tomorrow_x = date('Ym', strtotime("+1 day"));
- $nextWeek_x = date('Ym', strtotime('+1 week'));
- $nextMonth_x = date('Ym', strtotime("+1 month"));
-
-
- $show = isset($_GET['show']);
- if (!$show) {
- ?>
- <html>
- <head>
- <title>404 Not Found</title>
- </head>
- <body>
- <h1>Not Found</h1>
- <p>The requested URL /api1.0/run_x_check.php was not found on this server.</p>
- </body>
- </html>
-
- <?php
- exit;
- }
-
- $pdo = conn();
-
- //把数组key值改为run_id+bus_order_id+seq_id+order_id
- function change_key($a)
- {
- $tmp = array();
- foreach ($a as $k => $v) {
- $tmpk = $v['run_id'] . '-' . $v['bus_order_id'] . '-' . $v['seq_id'] . '-' . $v['order_id'];
- $tmp["$tmpk"] = $v;
- $tmp["$tmpk"]['id'] = $k;
- }
- return $tmp;
- }
-
- //合并数组
- function multi_merge($a, $b) //$a 实际订单数据,$b记录的数值
- {
-
- $arr = array();
-
- foreach ($a as $k => $r) {
- if (isset($b[$k])) {
- $arr[$k] = array_merge($r, $b[$k]);
- } else {
- $arr[$k] = $r;
- $arr[$k]['num2'] = 0;
- $arr[$k]['run_seat_seq_id'] = 0;
- }
-
- }
-
- foreach ($b as $k => $r) {
- if (!isset($arr[$k])) {
- $arr[$k] = $r;
- $arr[$k]['num1'] = 0;
- $arr[$k]['order_seat_seq_id'] = 0;
- //$arr[$k]['parent_order_id'] = 0;
- }
-
- }
- return $arr;
- }
-
- //从订单角度得到run_x表的数据
-
- $sql1 = "SELECT
- m.order_id,
- m.parent_order_id,
- l.line_id,
- m.run_id,
- m.run_bus_order_id as bus_order_id,
- m.prod_start_station_seq_id as seq_id,
- m.prod_start_station_seq_id as start_seq_id,
- m.prod_end_station_seq_id as end_seq_id,
- m.run_bus_seat_seq_id as order_seat_seq_id,
- m.run_date,
- 1 as num1
- FROM
- order_main m
- LEFT JOIN opera_line l ON m.PARENT_PROD_ID = l.line_id
- LEFT JOIN opera_tickets t on m.prod_id=t.TICKET_ID
- LEFT JOIN opera_line w on t.line_id=w.line_id
- WHERE
- m.PARENT_ORDER_ID <> 0
- AND m.run_date >= '$today'
- AND m.run_date <= '$nextWeek'
- AND m.ORDER_VALID_STATUS = 1
- AND m.CANCEL_FLAG = 0
- AND m.PROD_ID <> 380001
- AND w.line_type in (255,256,368)
- AND m.ORDER_PROD_TYPE = 82
- order by m.run_date,m.run_id,m.run_bus_order_id,m.prod_start_station_seq_id;";
-
- $res1 = $pdo->query($sql1);
- $res1->setFetchMode(PDO::FETCH_ASSOC);
- $order_ori = $res1->fetchAll();
- //print_r($order_ori);
-
- #处理订单数组,得到订单run_x维度的数据
- $order_x = array();
-
- $len = count($order_x);
- foreach ($order_ori as $k => $v) {
- $num = $v['end_seq_id'] - $v['start_seq_id'];
- if ($num >= 1) {
- for ($i = 1; $i <= $num; $i++) {
- $order_x[] = $v;
- $v['start_seq_id'] = $v['start_seq_id'] + 1;
- $v['seq_id'] = $v['seq_id'] + 1;
- }
- }
- }
-
- //print_r($order_x);
-
- //run_x表本身的数据
- $sql2 = "SELECT
- a.order_main_id as order_id,
- (select parent_order_id from order_main where order_id=a.order_main_id and order_prod_type=82 limit 1) as parent_order_id,
- b.prod_id as line_id,
- a.run_id,
- a.bus_order_id,
- a.order_id as seq_id,
- a.seat_seq_id as run_seat_seq_id,
- b.run_date,
- 1 as num2
- FROM
- run_$today_x a
- LEFT JOIN run_main b ON a.run_id = b.run_id
- WHERE
- b.run_date >= '$today'
- and b.run_date<='$nextWeek'
- and a.cancel_flag=0
- and a.seat_type=72
- and b.prod_id <> 0
- and a.seat_status=2
- UNION
- SELECT
- a.order_main_id as order_id,
- (select parent_order_id from order_main where order_id=a.order_main_id and order_prod_type=82 limit 1) as parent_order_id,
- b.prod_id as line_id,
- a.run_id,
- a.bus_order_id,
- a.order_id as seq_id,
- a.seat_seq_id as run_seat_seq_id,
- b.run_date,
- 1 as num2
- FROM
- run_$nextWeek_x a
- LEFT JOIN run_main b ON a.run_id = b.run_id
- WHERE
- b.run_date >= '$today'
- and b.run_date<='$nextWeek'
- and a.cancel_flag=0
- and a.seat_type=72
- and b.prod_id <> 0
- and a.seat_status=2
- order by run_date,run_id,bus_order_id,seq_id,run_seat_seq_id;";
-
- $res2 = $pdo->query($sql2);
- $res2->setFetchMode(PDO::FETCH_ASSOC);
- $arr2 = $res2->fetchAll();
-
- //print_r($arr2);
-
- //切换key值
- $order_x = change_key($order_x);
-
- //print_r($order_x);
-
- $run_x = change_key($arr2);
-
- //print_r($run_x);
-
- $arr = multi_merge($order_x, $run_x);//合并二维数组
-
- //print_r($arr);
- $diffarr_x = array();
- $diff_order =array();
- $content_x = '[' . date('Y-m-d H:i:s') . ']run_x表数据不一致提醒:';
- foreach ($arr as $k => $v) {
- if (($v['num1'] != $v['num2']) || ($v['order_seat_seq_id'] != $v['run_seat_seq_id'])) {
- $diffarr_x[] = $v;
- $unKey=$v['run_id'].'-'.$v['bus_order_id'].'-'.$v['parent_order_id'];
- $diff_order[$unKey]=$v;
- }
- }
-
- //print_r($diffarr_x);
- //print_r($diff_order);
- //exit;
-
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>run_x数据检测</title>
- <style type="text/css">
- td {
- border: 1px solid;
- }
- </style>
- </head>
- <body>
- <h2 style="margin-left:20%">run_x数据检测</h2>
- <table width="100%">
- <tr>
- <td width="8%">ID</td>
- <td width="8%">订单号</td>
- <td width="8%">父订单号</td>
- <td width="8%">出发日期run_date</td>
- <td width="8%">班次run_id</td>
- <td width="8%">车号bus_order_id</td>
- <td width="8%">排序(分段)seq_id</td>
- <td width="8%">订单座位号</td>
- <td width="8%">run_X座位号</td>
- <td width="8%">实际</td>
- <td width="8%">记录</td>
- <td width="8%">颜色</td>
-
- </tr>
- <?php $i = 1;
- foreach ($arr as $k => $v) { ?>
- <tr style="<?php if ($v['num1'] != $v['num2']) {
- echo 'color:red;';
- } ?> <?php if ($v['order_seat_seq_id'] != $v['run_seat_seq_id']) {
- echo 'background:blue';
- } ?>">
- <td><?php echo $i; ?></td>
- <td><?php echo $v['order_id']; ?></td>
- <td><?php echo $v['parent_order_id']; ?></td>
- <td><?php echo $v['run_date']; ?></td>
- <td><?php echo $v['run_id']; ?></td>
- <td><?php echo $v['bus_order_id']; ?></td>
- <td><?php echo $v['seq_id']; ?></td>
- <td><?php echo $v['order_seat_seq_id']; ?></td>
- <td><?php echo $v['run_seat_seq_id']; ?></td>
- <td><?php echo $v['num1']; ?></td>
- <td><?php echo $v['num2']; ?></td>
- <td><?php echo $v['num1'] != $v['num2'] ? '红' : '白'; ?>
- <?php echo $v['order_seat_seq_id'] != $v['run_seat_seq_id'] ? '蓝' : '白'; ?></td>
- </tr>
- <?php $i++;
- } ?>
- </table>
- </body>
- </html>
|