No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

744 líneas
21 KiB

  1. <?php
  2. require_once __DIR__ . '/../st-xm/Common/Mysql.php';
  3. header("Access-Control-Allow-Origin:*");
  4. header("Content-type: text/html; charset=utf-8");
  5. //班次信息总体监测(包括run_bus,run_prod,run_stock)
  6. date_default_timezone_set('Asia/Shanghai');
  7. $today = date('Y-m-d');
  8. $tomorrow = date('Y-m-d', strtotime('+1 day'));
  9. $afterTomorrow = date('Y-m-d', strtotime('+2 day'));
  10. $afterTomorrow_x = date('Ym', strtotime('+2 day'));
  11. $nextMonth = date('Y-m-d', strtotime("+1 month"));
  12. $nextWeek = date('Y-m-d', strtotime('+1 week'));
  13. $nextWeek_x = date('Ym', strtotime('+1 week'));
  14. $pdo = conn();
  15. //自定义发送短信接口sendCheckMsg
  16. function sendCheckMessage($phones, $user_name, $content, $order_id)
  17. {
  18. $send_data = array();
  19. $send_data["cdkey"] = "8SDK-EMY-6699-RISUM";
  20. $send_data["password"] = "175348";
  21. $send_data["phone"] = $phones;
  22. $send_data["message"] = '【蜘蛛行】' . $content;
  23. //$url='http://www.mxtong.net.cn/GateWay/Services.asmx/DirectSend?UserID=995596&Account=alert&Password=zzcx8888&Phones='.$phones.'&Content='.$content.'【蜘蛛行】&SendTime=&SendType=1&PostFixNumber=';
  24. $url = 'http://hprpt2.eucp.b2m.cn:8080/sdkproxy/sendsms.action';
  25. $response = httpRequest($url, $send_data);
  26. $pattern = "/\<error\>([-0-9]*?)\<\/error\>/";
  27. preg_match($pattern, $response, $match);
  28. $error_code = $match[1];
  29. return $error_code;
  30. }
  31. //----run_bus监测
  32. #region 1 run_bus
  33. //把数组key值改为run_id+bus_order_id
  34. function change_key_bus($a)
  35. {
  36. $tmp = array();
  37. foreach ($a as $k => $v) {
  38. $tmpk = $v['run_id'] . '-' . $v['bus_order_id'];
  39. $tmp["$tmpk"] = $v;
  40. $tmp["$tmpk"]['id'] = $k;
  41. }
  42. return $tmp;
  43. }
  44. //合并数组
  45. function multi_merge_bus($a, $b)
  46. {
  47. $arr_bus = array();
  48. foreach ($a as $k => $r) {
  49. if (isset($b[$k])) {
  50. $arr_bus[$k] = array_merge($r, $b[$k]);
  51. } else {
  52. $arr_bus[$k] = $r;
  53. $arr_bus[$k]['num2'] = 0;
  54. }
  55. }
  56. foreach ($b as $k => $r) {
  57. if (!isset($arr_bus[$k])) {
  58. $arr_bus[$k] = $r;
  59. $arr_bus[$k]['num1'] = 0;
  60. }
  61. }
  62. return $arr_bus;
  63. }
  64. //从订单角度得到run_bus表的数据
  65. $sql_bus1 = "SELECT
  66. l.line_id,
  67. m.run_id,
  68. m.RUN_BUS_ORDER_ID bus_order_id,
  69. m.run_date,
  70. count(m.order_id) as num1
  71. FROM
  72. order_main m
  73. LEFT JOIN opera_line l ON m.PARENT_PROD_ID = l.line_id
  74. LEFT JOIN opera_tickets t on m.prod_id=t.TICKET_ID
  75. LEFT JOIN opera_line w on t.line_id=w.line_id
  76. WHERE
  77. m.PARENT_ORDER_ID <> 0
  78. AND m.run_date >= '$today'
  79. AND m.run_date <= '$nextMonth'
  80. AND m.ORDER_VALID_STATUS = 1
  81. AND m.CANCEL_FLAG = 0
  82. AND m.PROD_ID <> 380001
  83. and m.run_bus_order_id<>0
  84. AND w.line_type in (255,256,368)
  85. AND m.ORDER_PROD_TYPE = 82
  86. AND m.AGENT_LEVEL = 1
  87. group by run_id,bus_order_id
  88. order by m.run_date;";
  89. $res1 = $pdo->query($sql_bus1);
  90. $res1->setFetchMode(PDO::FETCH_ASSOC);
  91. $arr_bus1 = $res1->fetchAll();
  92. $res1->closeCursor();
  93. $sql_bus2 = "SELECT
  94. b.prod_id as line_id,
  95. b.run_id,
  96. a.bus_order_id,
  97. b.run_date,
  98. a.SEAT_COUNT,
  99. a.saled_count as num2
  100. FROM
  101. run_bus a
  102. LEFT JOIN run_main b ON a.run_id = b.run_id
  103. WHERE
  104. b.run_date >= '$today'
  105. and b.run_date <= '$nextMonth'
  106. and a.CANCEL_FLAG=0
  107. and a.SALED_COUNT<>0
  108. AND b.PROD_ID <> 0
  109. and b.prod_id<>451479
  110. order by b.run_date;";
  111. $res2 = $pdo->query($sql_bus2);
  112. $res2->setFetchMode(PDO::FETCH_ASSOC);
  113. $arr_bus2 = $res2->fetchAll();
  114. $res2->closeCursor();
  115. //切换key值
  116. $arr_bus1 = change_key_bus($arr_bus1);
  117. $arr_bus2 = change_key_bus($arr_bus2);
  118. $arr_bus = multi_merge_bus($arr_bus1, $arr_bus2);
  119. //得到不对应的数据
  120. $diffarr_bus = array();
  121. $content_bus = '[' . date('Y-m-d H:i:s') . ']run_bus表数据不一致提醒:';
  122. foreach ($arr_bus as $k => $v) {
  123. if ($v['num1'] != $v['num2']) {
  124. $diffarr_bus[] = $v;
  125. }
  126. }
  127. //将数据插入到run_info_check表里
  128. $inset_bus_sql = "INSERT INTO run_check_log (
  129. run_table,
  130. line_id,
  131. run_id,
  132. extra_id,
  133. create_time,
  134. run_date,
  135. real_num,
  136. record_num
  137. )
  138. VALUES";
  139. $value_bus_sql = '';
  140. foreach ($diffarr_bus as $k => $v) {
  141. $value_bus_sql .= "('run_bus'," . $v['line_id'] . "," . $v['run_id'] . "," . $v['bus_order_id'] . ",now(),'" . $v['run_date'] . "'," . $v['num1'] . "," . $v['num2'] . "),";
  142. }
  143. $value_bus_sql = rtrim($value_bus_sql, ',');
  144. $inset_bus_sql .= $value_bus_sql;
  145. if ($value_bus_sql) { //如果有数据,插入到数据表run_check_log
  146. $afr = $pdo->exec($inset_bus_sql);
  147. }
  148. //整合短信发送内容
  149. foreach ($diffarr_bus as $k => $v) {
  150. $content_bus .= '【<' . ($k + 1) . '>,run_id:' . $v['run_id'] . ',bus_order_id:' . $v['bus_order_id'] . ',实际订单数:' . $v['num1'] . ',记录数:' . $v['num2'] . '】';
  151. }
  152. $content_bus .= '. ';
  153. if (empty($diffarr_bus)) {
  154. $content_bus = '';
  155. }
  156. #endregion
  157. //---run_prod监测
  158. #region 2 run_prod
  159. //把数组key值改为run_id+prod_id
  160. function change_key_prod($a)
  161. {
  162. $tmp = array();
  163. foreach ($a as $k => $v) {
  164. $tmpk = $v['run_id'] . '-' . $v['prod_id'];
  165. $tmp["$tmpk"] = $v;
  166. $tmp["$tmpk"]['id'] = $k;
  167. }
  168. return $tmp;
  169. }
  170. //合并数组
  171. function multi_merge_prod($a, $b)
  172. {
  173. $arr_prod = array();
  174. foreach ($a as $k => $r) {
  175. if (isset($b[$k])) {
  176. $arr_prod[$k] = array_merge($r, $b[$k]);
  177. } else {
  178. $arr_prod[$k] = $r;
  179. $arr_prod[$k]['num2'] = 0;
  180. }
  181. }
  182. foreach ($b as $k => $r) {
  183. if (!isset($arr_prod[$k])) {
  184. $arr_prod[$k] = $r;
  185. $arr_prod[$k]['num1'] = 0;
  186. }
  187. }
  188. return $arr_prod;
  189. }
  190. //从订单角度得到run_prod表的数据
  191. $sql_prod1 = "SELECT
  192. l.line_id,
  193. m.run_id,
  194. m.prod_id,
  195. m.run_date,
  196. count(m.order_id) as num1
  197. FROM
  198. order_main m
  199. LEFT JOIN opera_line l ON m.PARENT_PROD_ID = l.line_id
  200. LEFT JOIN opera_tickets t on m.prod_id=t.TICKET_ID
  201. LEFT JOIN opera_line w on t.line_id=w.line_id
  202. WHERE
  203. m.PARENT_ORDER_ID <> 0
  204. AND m.run_date >= '$today'
  205. AND m.run_date <= '$nextMonth'
  206. AND m.ORDER_VALID_STATUS = 1
  207. AND m.CANCEL_FLAG = 0
  208. AND m.PROD_ID <> 380001
  209. AND w.line_type in (255,256,368)
  210. AND m.ORDER_PROD_TYPE = 82
  211. AND m.AGENT_LEVEL = 1
  212. group by run_id,prod_id
  213. order by m.run_date;";
  214. $res1 = $pdo->query($sql_prod1);
  215. $res1->setFetchMode(PDO::FETCH_ASSOC);
  216. $arr_prod1 = $res1->fetchAll();
  217. $res1->closeCursor();
  218. //run_prod表本身的数据
  219. $sql_prod2 = "SELECT
  220. b.prod_id as line_id,
  221. b.run_id,
  222. a.prod_id,
  223. b.run_date,
  224. a.saled_count as num2
  225. FROM
  226. run_prod a
  227. LEFT JOIN run_main b ON a.run_id = b.run_id
  228. WHERE
  229. b.run_date >= '$today'
  230. and b.run_date <= '$nextMonth'
  231. and a.SALED_COUNT<>0
  232. AND b.PROD_ID <> 0
  233. order by b.run_date;";
  234. $res2 = $pdo->query($sql_prod2);
  235. $res2->setFetchMode(PDO::FETCH_ASSOC);
  236. $arr_prod2 = $res2->fetchAll();
  237. $res2->closeCursor();
  238. //切换key值
  239. $arr_prod1 = change_key_prod($arr_prod1);
  240. $arr_prod2 = change_key_prod($arr_prod2);
  241. $arr_prod = multi_merge_prod($arr_prod1, $arr_prod2);
  242. //得到不对应的数据
  243. $diffarr_prod = array();
  244. $content_prod = '[' . date('Y-m-d H:i:s') . ']run_prod表数据不一致提醒:';
  245. foreach ($arr_prod as $k => $v) {
  246. if ($v['num1'] != $v['num2']) {
  247. $diffarr_prod[] = $v;
  248. }
  249. }
  250. //将数据插入到run_info_check表里
  251. $inset_prod_sql = "INSERT INTO run_check_log (
  252. run_table,
  253. line_id,
  254. run_id,
  255. extra_id,
  256. create_time,
  257. run_date,
  258. real_num,
  259. record_num
  260. )
  261. VALUES";
  262. $value_prod_sql = '';
  263. foreach ($diffarr_prod as $k => $v) {
  264. $value_prod_sql .= "('run_prod'," . $v['line_id'] . "," . $v['run_id'] . "," . $v['prod_id'] . ",now(),'" . $v['run_date'] . "'," . $v['num1'] . "," . $v['num2'] . "),";
  265. }
  266. $value_prod_sql = rtrim($value_prod_sql, ',');
  267. $inset_prod_sql .= $value_prod_sql;
  268. if ($value_prod_sql) { //如果有数据,插入到数据表run_check_log
  269. $afr = $pdo->exec($inset_prod_sql);
  270. }
  271. //print_r($diffarr_prod);
  272. //整合短信发送内容
  273. foreach ($diffarr_prod as $k => $v) {
  274. $content_prod .= '【<' . ($k + 1) . '>,run_id:' . $v['run_id'] . ',prod_id:' . $v['prod_id'] . ',实际订单数:' . $v['num1'] . ',记录数:' . $v['num2'] . '】';
  275. }
  276. $content_prod .= '. ';
  277. if (empty($diffarr_prod)) {
  278. $content_prod = '';
  279. }
  280. #endregion
  281. //---run_stock监测
  282. #region 3 run_stock
  283. //二维数组去除重复
  284. function array_unique_fb_stock($array2D)
  285. {
  286. foreach ($array2D as $v) {
  287. $v = join(",", $v); //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
  288. $temp[] = $v;
  289. }
  290. $temp = array_unique($temp); //去掉重复的字符串,也就是重复的一维数组
  291. foreach ($temp as $k => $v) {
  292. $array = explode(",", $v); //再将拆开的数组重新组装
  293. $temp2[$k]['line_id'] = $array[0];
  294. $temp2[$k]['run_id'] = $array[1];
  295. $temp2[$k]['run_date'] = $array[2];
  296. $temp2[$k]['seq_id'] = $array[3];
  297. $temp2[$k]['num1'] = $array[4];
  298. }
  299. return $temp2;
  300. }
  301. //把数组key值改为run_id+seq_id
  302. function change_key_stock($a)
  303. {
  304. $tmp = array();
  305. foreach ($a as $k => $v) {
  306. $tmpk = $v['run_id'] . '-' . $v['seq_id'];
  307. $tmp["$tmpk"] = $v;
  308. $tmp["$tmpk"]['id'] = $k;
  309. }
  310. return $tmp;
  311. }
  312. //合并数组
  313. function multi_merge_stock($a, $b) //$a 实际订单数据,$b记录的数值
  314. {
  315. $arr_stock = array();
  316. foreach ($a as $k => $r) {
  317. if (isset($b[$k])) {
  318. $arr_stock[$k] = array_merge($r, $b[$k]);
  319. } else {
  320. $arr_stock[$k] = $r;
  321. $arr_stock[$k]['num2'] = 0;
  322. }
  323. }
  324. foreach ($b as $k => $r) {
  325. if (!isset($arr_stock[$k])) {
  326. $arr_stock[$k] = $r;
  327. $arr_stock[$k]['num1'] = 0;
  328. }
  329. }
  330. return $arr_stock;
  331. }
  332. //从订单角度得到run_stock表的数据(这里去除游运巴士线路的run_stock检测 line_id:451902)
  333. $sql_stock1 = "SELECT
  334. l.line_id,
  335. m.run_id,
  336. m.prod_start_station_seq_id,
  337. m.prod_end_station_seq_id,
  338. m.run_date,
  339. count(m.order_id) as num1
  340. FROM
  341. order_main m
  342. LEFT JOIN opera_line l ON m.PARENT_PROD_ID = l.line_id
  343. LEFT JOIN opera_tickets t on m.prod_id=t.TICKET_ID
  344. LEFT JOIN opera_line w on t.line_id=w.line_id
  345. WHERE
  346. m.PARENT_ORDER_ID <> 0
  347. AND m.run_date >= '$today'
  348. AND m.run_date <= '$nextMonth'
  349. AND m.ORDER_VALID_STATUS = 1
  350. AND m.CANCEL_FLAG = 0
  351. AND m.PROD_ID <> 380001
  352. AND m.PARENT_PROD_ID <> 451902
  353. AND w.line_type in (255,256,368)
  354. AND m.ORDER_PROD_TYPE = 82
  355. AND m.AGENT_LEVEL = 1
  356. group by run_id,prod_start_station_seq_id,prod_end_station_seq_id
  357. order by m.run_date,m.run_id,m.prod_start_station_seq_id;";
  358. $res1 = $pdo->query($sql_stock1);
  359. $res1->setFetchMode(PDO::FETCH_ASSOC);
  360. $arr_stock1 = $res1->fetchAll();
  361. $res1->closeCursor();
  362. //run_stock表本身的数据
  363. $sql_stock2 = "SELECT
  364. b.prod_id as line_id,
  365. b.run_id,
  366. a.seq_id,
  367. b.run_date,
  368. a.saled_count as num2
  369. FROM
  370. run_stock a
  371. LEFT JOIN run_main b ON a.run_id = b.run_id
  372. WHERE
  373. b.run_date >= '$today'
  374. and b.run_date <= '$nextMonth'
  375. and a.CANCEL_FLAG=0
  376. and a.SEAT_TYPE=72
  377. AND b.PROD_ID <> 0
  378. AND b.PROD_ID <> 451902
  379. and (select sum(SALED_COUNT) as co from run_stock where run_id=b.run_id and CANCEL_FLAG=0)>0
  380. order by b.run_date,b.run_id;";
  381. $res2 = $pdo->query($sql_stock2);
  382. $res2->setFetchMode(PDO::FETCH_ASSOC);
  383. $arr_stock2 = $res2->fetchAll();
  384. $res2->closeCursor();
  385. #对arr1做处理,根据分段合并数据
  386. function merge_stock($a, $b)
  387. {
  388. $arr_stock = array();
  389. foreach ($b as $k => $v) {
  390. //$tmp=$v['run_id'].'-'.$v['prod_end_station_seq_id'];
  391. $num = 0;
  392. foreach ($a as $k2 => $v2) {
  393. if ($v['run_id'] == $v2['run_id']) {
  394. if ($v['seq_id'] >= $v2['prod_start_station_seq_id'] && $v['seq_id'] < $v2['prod_end_station_seq_id']) {
  395. $num += $v2['num1'];
  396. }
  397. }
  398. }
  399. $arr_stock[$k]['line_id'] = $v['line_id'];
  400. $arr_stock[$k]['run_id'] = $v['run_id'];
  401. $arr_stock[$k]['run_date'] = $v['run_date'];
  402. $arr_stock[$k]['seq_id'] = $v['seq_id'];
  403. $arr_stock[$k]['num1'] = $num;
  404. }
  405. return array_unique_fb_stock($arr_stock);//二维数组去重
  406. }
  407. $arr_stock1 = merge_stock($arr_stock1, $arr_stock2);
  408. //切换key值
  409. $arr_stock1 = change_key_stock($arr_stock1);
  410. //print_r($arr_stock1);
  411. $arr_stock2 = change_key_stock($arr_stock2);
  412. $arr_stock = multi_merge_stock($arr_stock1, $arr_stock2);//合并二维数组
  413. //得到不对应的数据
  414. $diffarr_stock = array();
  415. $content_stock = '[' . date('Y-m-d H:i:s') . ']run_stock表数据不一致提醒:';
  416. foreach ($arr_stock as $k => $v) {
  417. if ($v['num1'] != $v['num2']) {
  418. $diffarr_stock[] = $v;
  419. }
  420. }
  421. //将数据插入到run_info_check表里
  422. $inset_stock_sql = "INSERT INTO run_check_log (
  423. run_table,
  424. line_id,
  425. run_id,
  426. extra_id,
  427. create_time,
  428. run_date,
  429. real_num,
  430. record_num
  431. )
  432. VALUES";
  433. $value_stock_sql = '';
  434. foreach ($diffarr_stock as $k => $v) {
  435. $value_stock_sql .= "('run_stock'," . $v['line_id'] . "," . $v['run_id'] . "," . $v['seq_id'] . ",now(),'" . $v['run_date'] . "'," . $v['num1'] . "," . $v['num2'] . "),";
  436. }
  437. $value_stock_sql = rtrim($value_stock_sql, ',');
  438. $inset_stock_sql .= $value_stock_sql;
  439. if ($value_stock_sql) { //如果有数据,插入到数据表run_check_log
  440. $afr = $pdo->exec($inset_stock_sql);
  441. }
  442. //print_r($diffarr_stock);
  443. //整合短信发送内容
  444. foreach ($diffarr_stock as $k => $v) {
  445. $content_stock .= '【<' . ($k + 1) . '>,run_id:' . $v['run_id'] . ',排序seq_id:' . $v['seq_id'] . ',实际订单数:' . $v['num1'] . ',记录数:' . $v['num2'] . '】';
  446. }
  447. $content_stock .= '. ';
  448. if (empty($diffarr_stock)) {
  449. $content_stock = '';
  450. }
  451. #endregion
  452. #region 4 run_x 数据检测
  453. $today_x = date('Ym');
  454. $tomorrow_x = date('Ym', strtotime("+1 day"));
  455. //把数组key值改为run_id+bus_order_id+seq_id+order_id
  456. function change_key_x($a)
  457. {
  458. $tmp = array();
  459. foreach ($a as $k => $v) {
  460. $tmpk = $v['run_id'] . '-' . $v['bus_order_id'] . '-' . $v['seq_id'] . '-' . $v['order_id'];
  461. $tmp["$tmpk"] = $v;
  462. $tmp["$tmpk"]['id'] = $k;
  463. }
  464. return $tmp;
  465. }
  466. //合并数组
  467. function multi_merge_x($a, $b) //$a 实际订单数据,$b记录的数值
  468. {
  469. $arr = array();
  470. foreach ($a as $k => $r) {
  471. if (isset($b[$k])) {
  472. $arr[$k] = array_merge($r, $b[$k]);
  473. } else {
  474. $arr[$k] = $r;
  475. $arr[$k]['num2'] = 0;
  476. $arr[$k]['run_seat_seq_id'] = 0;
  477. }
  478. }
  479. foreach ($b as $k => $r) {
  480. if (!isset($arr[$k])) {
  481. $arr[$k] = $r;
  482. $arr[$k]['num1'] = 0;
  483. $arr[$k]['order_seat_seq_id'] = 0;
  484. //$arr[$k]['parent_order_id'] = 0;
  485. }
  486. }
  487. return $arr;
  488. }
  489. //从订单角度得到run_x表的数据(这里去除游运巴士线路的run_x检测 line_id:451902)
  490. $sql1 = "SELECT
  491. m.order_id,
  492. m.parent_order_id,
  493. l.line_id,
  494. m.run_id,
  495. m.run_bus_order_id as bus_order_id,
  496. m.prod_start_station_seq_id as seq_id,
  497. m.prod_start_station_seq_id as start_seq_id,
  498. m.prod_end_station_seq_id as end_seq_id,
  499. m.run_bus_seat_seq_id as order_seat_seq_id,
  500. m.run_date,
  501. 1 as num1
  502. FROM
  503. order_main m
  504. LEFT JOIN opera_line l ON m.PARENT_PROD_ID = l.line_id
  505. LEFT JOIN opera_tickets t on m.prod_id=t.TICKET_ID
  506. LEFT JOIN opera_line w on t.line_id=w.line_id
  507. WHERE
  508. m.PARENT_ORDER_ID <> 0
  509. AND m.run_date >= '$today'
  510. AND m.run_date <= '$afterTomorrow'
  511. AND m.ORDER_VALID_STATUS = 1
  512. AND m.CANCEL_FLAG = 0
  513. AND m.PROD_ID <> 380001
  514. AND m.PARENT_PROD_ID <> 451902
  515. AND w.line_type in (255,256,368)
  516. AND m.ORDER_PROD_TYPE = 82
  517. AND m.AGENT_LEVEL = 1
  518. order by m.run_date,m.run_id,m.run_bus_order_id,m.prod_start_station_seq_id;";
  519. $res4 = $pdo->query($sql1);
  520. $res4->setFetchMode(PDO::FETCH_ASSOC);
  521. $order_ori = $res4->fetchAll();
  522. //print_r($order_ori);
  523. #处理订单数组,得到订单run_x维度的数据
  524. $order_x = array();
  525. $len = count($order_x);
  526. foreach ($order_ori as $k => $v) {
  527. $num = $v['end_seq_id'] - $v['start_seq_id'];
  528. if ($num >= 1) {
  529. for ($i = 1; $i <= $num; $i++) {
  530. $order_x[] = $v;
  531. $v['start_seq_id'] = $v['start_seq_id'] + 1;
  532. $v['seq_id'] = $v['seq_id'] + 1;
  533. }
  534. }
  535. }
  536. //print_r($order_x);
  537. //run_x表本身的数据
  538. $sql2 = "SELECT
  539. a.order_main_id as order_id,
  540. (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,
  541. b.prod_id as line_id,
  542. a.run_id,
  543. a.bus_order_id,
  544. a.order_id as seq_id,
  545. a.seat_seq_id as run_seat_seq_id,
  546. b.run_date,
  547. 1 as num2
  548. FROM
  549. run_$today_x a
  550. LEFT JOIN run_main b ON a.run_id = b.run_id
  551. WHERE
  552. b.run_date >= '$today'
  553. and b.run_date<='$afterTomorrow'
  554. and a.cancel_flag=0
  555. and a.seat_type=72
  556. and b.prod_id <> 0
  557. and b.prod_id <> 451902
  558. and a.seat_status=2
  559. UNION
  560. SELECT
  561. a.order_main_id as order_id,
  562. (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,
  563. b.prod_id as line_id,
  564. a.run_id,
  565. a.bus_order_id,
  566. a.order_id as seq_id,
  567. a.seat_seq_id as run_seat_seq_id,
  568. b.run_date,
  569. 1 as num2
  570. FROM
  571. run_$afterTomorrow_x a
  572. LEFT JOIN run_main b ON a.run_id = b.run_id
  573. WHERE
  574. b.run_date >= '$today'
  575. and b.run_date<='$afterTomorrow'
  576. and a.cancel_flag=0
  577. and a.seat_type=72
  578. and b.prod_id <> 0
  579. and b.prod_id <> 451902
  580. and a.seat_status=2
  581. order by run_date,run_id,bus_order_id,seq_id,run_seat_seq_id;";
  582. $res5 = $pdo->query($sql2);
  583. $res5->setFetchMode(PDO::FETCH_ASSOC);
  584. $arr2 = $res5->fetchAll();
  585. //切换key值
  586. $order_x = change_key_x($order_x);
  587. $run_x = change_key_x($arr2);
  588. $arr_run_x = multi_merge_x($order_x, $run_x);//合并二维数组
  589. //得到不对应的数据并按整合
  590. $diffarr_x = array();
  591. $diff_order = array();
  592. foreach ($arr_run_x as $k => $v) {
  593. if (($v['num1'] != $v['num2']) || ($v['order_seat_seq_id'] != $v['run_seat_seq_id'])) {
  594. $diffarr_x[] = $v;
  595. $unKey = $v['run_id'] . '-' . $v['bus_order_id'] . '-' . $v['parent_order_id'];
  596. $diff_order[$unKey] = $v;
  597. }
  598. }
  599. //将数据插入到run_info_check表里
  600. $inset_x_sql = "INSERT INTO run_check_log (
  601. run_table,
  602. line_id,
  603. run_id,
  604. extra_id,
  605. create_time,
  606. run_date,
  607. real_num,
  608. record_num
  609. )
  610. VALUES";
  611. $value_x_sql = '';
  612. foreach ($diff_order as $k => $v) {
  613. $value_x_sql .= "('run_x'," . $v['line_id'] . "," . $v['run_id'] . "," . $v['parent_order_id'] . ",now(),'" . $v['run_date'] . "'," . $v['num1'] . "," . $v['num2'] . "),";
  614. }
  615. $value_x_sql = rtrim($value_x_sql, ',');
  616. $inset_x_sql .= $value_x_sql;
  617. if ($value_x_sql) { //如果有数据,插入到数据表run_check_log
  618. $afr = $pdo->exec($inset_x_sql);
  619. }
  620. //整合短信发送内容
  621. $content_run_x = '[' . date('Y-m-d H:i:s') . ']run_x表数据不一致提醒:';
  622. $i = 1;
  623. foreach ($diff_order as $k => $v) {
  624. $content_run_x .= '【<' . ($i) . '>,run_id:' . $v['run_id'] . ',bus_order_id:' . $v['bus_order_id'] . ',主订单号:' . $v['parent_order_id'] . '】';
  625. $i++;
  626. }
  627. if (empty($diffarr_x)) {
  628. $content_run_x = '';
  629. }
  630. #endregion
  631. if (empty($diffarr_bus) && empty($diffarr_prod) && empty($diffarr_stock) && empty($diffarr_x)) {
  632. exit('数据一致!');
  633. }
  634. //发送短信sendTelMessage($phones,$user_name,$content_stock,$order_id) qius13816608252 loumn18616307052 wenyl15753206507
  635. //$phones = '13816608252,15203408170,15753206507';
  636. $phones = '13816608252,18616307052,15753206507';
  637. $show = isset($_GET['show']);
  638. if ($show) {
  639. print_r($content_bus);
  640. print_r($content_prod);
  641. print_r($content_stock);
  642. print_r($diffarr_x);
  643. print_r($diff_order);
  644. }
  645. //发送短信
  646. if (!$show) {
  647. $final_content = $content_bus . $content_prod . $content_stock . $content_run_x;
  648. $response = sendCheckMessage($phones, '比特', $final_content, 0);
  649. //print_r($final_content);
  650. var_dump($response);
  651. }