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.
 
 
 
 

261 lines
7.0 KiB

  1. <?php
  2. require_once '../st-xm/Common/Mysql.php';
  3. header("Access-Control-Allow-Origin:*");
  4. //error_reporting('E_ALL & ~E_NOTICE');
  5. date_default_timezone_set('Asia/Shanghai');
  6. $today = date('Y-m-d');
  7. $tomorrow = date('Y-m-d', strtotime('+1 day'));
  8. $nextWeek = date('Y-m-d', strtotime('+1 week'));
  9. $nextMonth = date('Y-m-d', strtotime("+1 month"));
  10. $today_x = date('Ym');
  11. $tomorrow_x = date('Ym', strtotime("+1 day"));
  12. $nextWeek_x = date('Ym', strtotime('+1 week'));
  13. $nextMonth_x = date('Ym', strtotime("+1 month"));
  14. $show = isset($_GET['show']);
  15. if (!$show) {
  16. ?>
  17. <html>
  18. <head>
  19. <title>404 Not Found</title>
  20. </head>
  21. <body>
  22. <h1>Not Found</h1>
  23. <p>The requested URL /api1.0/run_x_check.php was not found on this server.</p>
  24. </body>
  25. </html>
  26. <?php
  27. exit;
  28. }
  29. $pdo = conn();
  30. //把数组key值改为run_id+bus_order_id+seq_id+order_id
  31. function change_key($a)
  32. {
  33. $tmp = array();
  34. foreach ($a as $k => $v) {
  35. $tmpk = $v['run_id'] . '-' . $v['bus_order_id'] . '-' . $v['seq_id'] . '-' . $v['order_id'];
  36. $tmp["$tmpk"] = $v;
  37. $tmp["$tmpk"]['id'] = $k;
  38. }
  39. return $tmp;
  40. }
  41. //合并数组
  42. function multi_merge($a, $b) //$a 实际订单数据,$b记录的数值
  43. {
  44. $arr = array();
  45. foreach ($a as $k => $r) {
  46. if (isset($b[$k])) {
  47. $arr[$k] = array_merge($r, $b[$k]);
  48. } else {
  49. $arr[$k] = $r;
  50. $arr[$k]['num2'] = 0;
  51. $arr[$k]['run_seat_seq_id'] = 0;
  52. }
  53. }
  54. foreach ($b as $k => $r) {
  55. if (!isset($arr[$k])) {
  56. $arr[$k] = $r;
  57. $arr[$k]['num1'] = 0;
  58. $arr[$k]['order_seat_seq_id'] = 0;
  59. //$arr[$k]['parent_order_id'] = 0;
  60. }
  61. }
  62. return $arr;
  63. }
  64. //从订单角度得到run_x表的数据
  65. $sql1 = "SELECT
  66. m.order_id,
  67. m.parent_order_id,
  68. l.line_id,
  69. m.run_id,
  70. m.run_bus_order_id as bus_order_id,
  71. m.prod_start_station_seq_id as seq_id,
  72. m.prod_start_station_seq_id as start_seq_id,
  73. m.prod_end_station_seq_id as end_seq_id,
  74. m.run_bus_seat_seq_id as order_seat_seq_id,
  75. m.run_date,
  76. 1 as num1
  77. FROM
  78. order_main m
  79. LEFT JOIN opera_line l ON m.PARENT_PROD_ID = l.line_id
  80. LEFT JOIN opera_tickets t on m.prod_id=t.TICKET_ID
  81. LEFT JOIN opera_line w on t.line_id=w.line_id
  82. WHERE
  83. m.PARENT_ORDER_ID <> 0
  84. AND m.run_date >= '$today'
  85. AND m.run_date <= '$nextWeek'
  86. AND m.ORDER_VALID_STATUS = 1
  87. AND m.CANCEL_FLAG = 0
  88. AND m.PROD_ID <> 380001
  89. AND w.line_type in (255,256,368)
  90. AND m.ORDER_PROD_TYPE = 82
  91. order by m.run_date,m.run_id,m.run_bus_order_id,m.prod_start_station_seq_id;";
  92. $res1 = $pdo->query($sql1);
  93. $res1->setFetchMode(PDO::FETCH_ASSOC);
  94. $order_ori = $res1->fetchAll();
  95. //print_r($order_ori);
  96. #处理订单数组,得到订单run_x维度的数据
  97. $order_x = array();
  98. $len = count($order_x);
  99. foreach ($order_ori as $k => $v) {
  100. $num = $v['end_seq_id'] - $v['start_seq_id'];
  101. if ($num >= 1) {
  102. for ($i = 1; $i <= $num; $i++) {
  103. $order_x[] = $v;
  104. $v['start_seq_id'] = $v['start_seq_id'] + 1;
  105. $v['seq_id'] = $v['seq_id'] + 1;
  106. }
  107. }
  108. }
  109. //print_r($order_x);
  110. //run_x表本身的数据
  111. $sql2 = "SELECT
  112. a.order_main_id as order_id,
  113. (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,
  114. b.prod_id as line_id,
  115. a.run_id,
  116. a.bus_order_id,
  117. a.order_id as seq_id,
  118. a.seat_seq_id as run_seat_seq_id,
  119. b.run_date,
  120. 1 as num2
  121. FROM
  122. run_$today_x a
  123. LEFT JOIN run_main b ON a.run_id = b.run_id
  124. WHERE
  125. b.run_date >= '$today'
  126. and b.run_date<='$nextWeek'
  127. and a.cancel_flag=0
  128. and a.seat_type=72
  129. and b.prod_id <> 0
  130. and a.seat_status=2
  131. UNION
  132. SELECT
  133. a.order_main_id as order_id,
  134. (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,
  135. b.prod_id as line_id,
  136. a.run_id,
  137. a.bus_order_id,
  138. a.order_id as seq_id,
  139. a.seat_seq_id as run_seat_seq_id,
  140. b.run_date,
  141. 1 as num2
  142. FROM
  143. run_$nextWeek_x a
  144. LEFT JOIN run_main b ON a.run_id = b.run_id
  145. WHERE
  146. b.run_date >= '$today'
  147. and b.run_date<='$nextWeek'
  148. and a.cancel_flag=0
  149. and a.seat_type=72
  150. and b.prod_id <> 0
  151. and a.seat_status=2
  152. order by run_date,run_id,bus_order_id,seq_id,run_seat_seq_id;";
  153. $res2 = $pdo->query($sql2);
  154. $res2->setFetchMode(PDO::FETCH_ASSOC);
  155. $arr2 = $res2->fetchAll();
  156. //print_r($arr2);
  157. //切换key值
  158. $order_x = change_key($order_x);
  159. //print_r($order_x);
  160. $run_x = change_key($arr2);
  161. //print_r($run_x);
  162. $arr = multi_merge($order_x, $run_x);//合并二维数组
  163. //print_r($arr);
  164. $diffarr_x = array();
  165. $diff_order =array();
  166. $content_x = '[' . date('Y-m-d H:i:s') . ']run_x表数据不一致提醒:';
  167. foreach ($arr as $k => $v) {
  168. if (($v['num1'] != $v['num2']) || ($v['order_seat_seq_id'] != $v['run_seat_seq_id'])) {
  169. $diffarr_x[] = $v;
  170. $unKey=$v['run_id'].'-'.$v['bus_order_id'].'-'.$v['parent_order_id'];
  171. $diff_order[$unKey]=$v;
  172. }
  173. }
  174. //print_r($diffarr_x);
  175. //print_r($diff_order);
  176. //exit;
  177. ?>
  178. <!DOCTYPE html>
  179. <html>
  180. <head>
  181. <meta charset="UTF-8">
  182. <title>run_x数据检测</title>
  183. <style type="text/css">
  184. td {
  185. border: 1px solid;
  186. }
  187. </style>
  188. </head>
  189. <body>
  190. <h2 style="margin-left:20%">run_x数据检测</h2>
  191. <table width="100%">
  192. <tr>
  193. <td width="8%">ID</td>
  194. <td width="8%">订单号</td>
  195. <td width="8%">父订单号</td>
  196. <td width="8%">出发日期run_date</td>
  197. <td width="8%">班次run_id</td>
  198. <td width="8%">车号bus_order_id</td>
  199. <td width="8%">排序(分段)seq_id</td>
  200. <td width="8%">订单座位号</td>
  201. <td width="8%">run_X座位号</td>
  202. <td width="8%">实际</td>
  203. <td width="8%">记录</td>
  204. <td width="8%">颜色</td>
  205. </tr>
  206. <?php $i = 1;
  207. foreach ($arr as $k => $v) { ?>
  208. <tr style="<?php if ($v['num1'] != $v['num2']) {
  209. echo 'color:red;';
  210. } ?> <?php if ($v['order_seat_seq_id'] != $v['run_seat_seq_id']) {
  211. echo 'background:blue';
  212. } ?>">
  213. <td><?php echo $i; ?></td>
  214. <td><?php echo $v['order_id']; ?></td>
  215. <td><?php echo $v['parent_order_id']; ?></td>
  216. <td><?php echo $v['run_date']; ?></td>
  217. <td><?php echo $v['run_id']; ?></td>
  218. <td><?php echo $v['bus_order_id']; ?></td>
  219. <td><?php echo $v['seq_id']; ?></td>
  220. <td><?php echo $v['order_seat_seq_id']; ?></td>
  221. <td><?php echo $v['run_seat_seq_id']; ?></td>
  222. <td><?php echo $v['num1']; ?></td>
  223. <td><?php echo $v['num2']; ?></td>
  224. <td><?php echo $v['num1'] != $v['num2'] ? '红' : '白'; ?>
  225. <?php echo $v['order_seat_seq_id'] != $v['run_seat_seq_id'] ? '蓝' : '白'; ?></td>
  226. </tr>
  227. <?php $i++;
  228. } ?>
  229. </table>
  230. </body>
  231. </html>