Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

262 rader
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. AND m.AGENT_LEVEL = 1
  92. order by m.run_date,m.run_id,m.run_bus_order_id,m.prod_start_station_seq_id;";
  93. $res1 = $pdo->query($sql1);
  94. $res1->setFetchMode(PDO::FETCH_ASSOC);
  95. $order_ori = $res1->fetchAll();
  96. //print_r($order_ori);
  97. #处理订单数组,得到订单run_x维度的数据
  98. $order_x = array();
  99. $len = count($order_x);
  100. foreach ($order_ori as $k => $v) {
  101. $num = $v['end_seq_id'] - $v['start_seq_id'];
  102. if ($num >= 1) {
  103. for ($i = 1; $i <= $num; $i++) {
  104. $order_x[] = $v;
  105. $v['start_seq_id'] = $v['start_seq_id'] + 1;
  106. $v['seq_id'] = $v['seq_id'] + 1;
  107. }
  108. }
  109. }
  110. //print_r($order_x);
  111. //run_x表本身的数据
  112. $sql2 = "SELECT
  113. a.order_main_id as order_id,
  114. (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,
  115. b.prod_id as line_id,
  116. a.run_id,
  117. a.bus_order_id,
  118. a.order_id as seq_id,
  119. a.seat_seq_id as run_seat_seq_id,
  120. b.run_date,
  121. 1 as num2
  122. FROM
  123. run_$today_x a
  124. LEFT JOIN run_main b ON a.run_id = b.run_id
  125. WHERE
  126. b.run_date >= '$today'
  127. and b.run_date<='$nextWeek'
  128. and a.cancel_flag=0
  129. and a.seat_type=72
  130. and b.prod_id <> 0
  131. and a.seat_status=2
  132. UNION
  133. SELECT
  134. a.order_main_id as order_id,
  135. (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,
  136. b.prod_id as line_id,
  137. a.run_id,
  138. a.bus_order_id,
  139. a.order_id as seq_id,
  140. a.seat_seq_id as run_seat_seq_id,
  141. b.run_date,
  142. 1 as num2
  143. FROM
  144. run_$nextWeek_x a
  145. LEFT JOIN run_main b ON a.run_id = b.run_id
  146. WHERE
  147. b.run_date >= '$today'
  148. and b.run_date<='$nextWeek'
  149. and a.cancel_flag=0
  150. and a.seat_type=72
  151. and b.prod_id <> 0
  152. and a.seat_status=2
  153. order by run_date,run_id,bus_order_id,seq_id,run_seat_seq_id;";
  154. $res2 = $pdo->query($sql2);
  155. $res2->setFetchMode(PDO::FETCH_ASSOC);
  156. $arr2 = $res2->fetchAll();
  157. //print_r($arr2);
  158. //切换key值
  159. $order_x = change_key($order_x);
  160. //print_r($order_x);
  161. $run_x = change_key($arr2);
  162. //print_r($run_x);
  163. $arr = multi_merge($order_x, $run_x);//合并二维数组
  164. //print_r($arr);
  165. $diffarr_x = array();
  166. $diff_order =array();
  167. $content_x = '[' . date('Y-m-d H:i:s') . ']run_x表数据不一致提醒:';
  168. foreach ($arr as $k => $v) {
  169. if (($v['num1'] != $v['num2']) || ($v['order_seat_seq_id'] != $v['run_seat_seq_id'])) {
  170. $diffarr_x[] = $v;
  171. $unKey=$v['run_id'].'-'.$v['bus_order_id'].'-'.$v['parent_order_id'];
  172. $diff_order[$unKey]=$v;
  173. }
  174. }
  175. //print_r($diffarr_x);
  176. //print_r($diff_order);
  177. //exit;
  178. ?>
  179. <!DOCTYPE html>
  180. <html>
  181. <head>
  182. <meta charset="UTF-8">
  183. <title>run_x数据检测</title>
  184. <style type="text/css">
  185. td {
  186. border: 1px solid;
  187. }
  188. </style>
  189. </head>
  190. <body>
  191. <h2 style="margin-left:20%">run_x数据检测</h2>
  192. <table width="100%">
  193. <tr>
  194. <td width="8%">ID</td>
  195. <td width="8%">订单号</td>
  196. <td width="8%">父订单号</td>
  197. <td width="8%">出发日期run_date</td>
  198. <td width="8%">班次run_id</td>
  199. <td width="8%">车号bus_order_id</td>
  200. <td width="8%">排序(分段)seq_id</td>
  201. <td width="8%">订单座位号</td>
  202. <td width="8%">run_X座位号</td>
  203. <td width="8%">实际</td>
  204. <td width="8%">记录</td>
  205. <td width="8%">颜色</td>
  206. </tr>
  207. <?php $i = 1;
  208. foreach ($arr as $k => $v) { ?>
  209. <tr style="<?php if ($v['num1'] != $v['num2']) {
  210. echo 'color:red;';
  211. } ?> <?php if ($v['order_seat_seq_id'] != $v['run_seat_seq_id']) {
  212. echo 'background:blue';
  213. } ?>">
  214. <td><?php echo $i; ?></td>
  215. <td><?php echo $v['order_id']; ?></td>
  216. <td><?php echo $v['parent_order_id']; ?></td>
  217. <td><?php echo $v['run_date']; ?></td>
  218. <td><?php echo $v['run_id']; ?></td>
  219. <td><?php echo $v['bus_order_id']; ?></td>
  220. <td><?php echo $v['seq_id']; ?></td>
  221. <td><?php echo $v['order_seat_seq_id']; ?></td>
  222. <td><?php echo $v['run_seat_seq_id']; ?></td>
  223. <td><?php echo $v['num1']; ?></td>
  224. <td><?php echo $v['num2']; ?></td>
  225. <td><?php echo $v['num1'] != $v['num2'] ? '红' : '白'; ?>
  226. <?php echo $v['order_seat_seq_id'] != $v['run_seat_seq_id'] ? '蓝' : '白'; ?></td>
  227. </tr>
  228. <?php $i++;
  229. } ?>
  230. </table>
  231. </body>
  232. </html>