25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

194 lines
4.7 KiB

  1. <?php
  2. require_once '../st-xm/Common/Mysql.php';
  3. header("Access-Control-Allow-Origin:*");
  4. //二维数组去除重复
  5. function array_unique_fb($array2D)
  6. {
  7. foreach ($array2D as $v)
  8. {
  9. $v = join(",",$v); //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
  10. $temp[] = $v;
  11. }
  12. $temp = array_unique($temp); //去掉重复的字符串,也就是重复的一维数组
  13. foreach ($temp as $k => $v)
  14. {
  15. $array = explode(",",$v); //再将拆开的数组重新组装
  16. $temp2[$k]['line_id']=$array[0];
  17. $temp2[$k]['run_id']=$array[1];
  18. $temp2[$k]['run_date']=$array[2];
  19. $temp2[$k]['seq_id']=$array[3];
  20. $temp2[$k]['num1']=$array[4];
  21. }
  22. return $temp2;
  23. }
  24. //把数组key值改为run_id+seq_id
  25. function change_key($a)
  26. {
  27. $tmp = array();
  28. foreach ($a as $k => $v) {
  29. $tmpk = $v['run_id'] . '-' . $v['seq_id'];
  30. $tmp["$tmpk"] = $v;
  31. $tmp["$tmpk"]['id'] = $k;
  32. }
  33. return $tmp;
  34. }
  35. //合并数组
  36. function multi_merge($a, $b) //$a 实际订单数据,$b记录的数值
  37. {
  38. $arr = array();
  39. foreach ($a as $k => $r) {
  40. if (isset($b[$k])) {
  41. $arr[$k] = array_merge($r, $b[$k]);
  42. } else {
  43. $arr[$k] = $r;
  44. $arr[$k]['num2'] = 0;
  45. }
  46. }
  47. foreach ($b as $k => $r) {
  48. if (!isset($arr[$k])) {
  49. $arr[$k] = $r;
  50. $arr[$k]['num1'] = 0;
  51. }
  52. }
  53. return $arr;
  54. }
  55. $pdo = conn1();
  56. //从订单角度得到run_stock表的数据
  57. $sql1 = "SELECT
  58. l.line_id,
  59. m.run_id,
  60. m.prod_start_station_seq_id,
  61. m.prod_end_station_seq_id,
  62. m.run_date,
  63. count(m.order_id) as num1
  64. FROM
  65. order_main m
  66. LEFT JOIN opera_line l ON m.PARENT_PROD_ID = l.line_id
  67. LEFT JOIN opera_tickets t on m.prod_id=t.TICKET_ID
  68. LEFT JOIN opera_line w on t.line_id=w.line_id
  69. WHERE
  70. m.PARENT_ORDER_ID <> 0
  71. AND m.run_date >= '2017-02-05'
  72. AND m.ORDER_VALID_STATUS = 1
  73. AND m.CANCEL_FLAG = 0
  74. AND m.PROD_ID <> 380001
  75. AND w.line_type in (255,256)
  76. AND m.ORDER_PROD_TYPE = 82
  77. group by run_id,prod_start_station_seq_id,prod_end_station_seq_id
  78. order by m.run_date,m.run_id,m.prod_start_station_seq_id;";
  79. $res1 = $pdo->query($sql1);
  80. $res1->setFetchMode(PDO::FETCH_ASSOC);
  81. $arr1 = $res1->fetchAll();
  82. //run_stock表本身的数据
  83. $sql2 = "SELECT
  84. b.prod_id as line_id,
  85. b.run_id,
  86. a.seq_id,
  87. b.run_date,
  88. a.saled_count as num2
  89. FROM
  90. run_stock a
  91. LEFT JOIN run_main b ON a.run_id = b.run_id
  92. WHERE
  93. b.run_date >= '2017-02-05'
  94. and a.CANCEL_FLAG=0
  95. and a.SEAT_TYPE=72
  96. AND b.PROD_ID <> 0
  97. and (select sum(SALED_COUNT) as co from run_stock where run_id=b.run_id and CANCEL_FLAG=0)>0
  98. order by b.run_date,b.run_id;";
  99. $res2 = $pdo->query($sql2);
  100. $res2->setFetchMode(PDO::FETCH_ASSOC);
  101. $arr2 = $res2->fetchAll();
  102. #对arr1做处理,根据分段合并数据
  103. function merge($a,$b){
  104. $arr=array();
  105. foreach($b as $k=>$v){
  106. //$tmp=$v['run_id'].'-'.$v['prod_end_station_seq_id'];
  107. $num=0;
  108. foreach($a as $k2=>$v2){
  109. if($v['run_id']==$v2['run_id']){
  110. if($v['seq_id']>=$v2['prod_start_station_seq_id']&&$v['seq_id']<$v2['prod_end_station_seq_id']){
  111. $num+=$v2['num1'];
  112. }
  113. }
  114. }
  115. $arr[$k]['line_id']=$v['line_id'];
  116. $arr[$k]['run_id']=$v['run_id'];
  117. $arr[$k]['run_date']=$v['run_date'];
  118. $arr[$k]['seq_id']=$v['seq_id'];
  119. $arr[$k]['num1']=$num;
  120. }
  121. return array_unique_fb($arr);//二维数组去重
  122. }
  123. $arr1=merge($arr1,$arr2);
  124. /*print_r($arr1);
  125. print_r($arr3);
  126. exit;*/
  127. //切换key值
  128. $arr1 = change_key($arr1);
  129. //print_r($arr1);
  130. $arr2 = change_key($arr2);
  131. /*print_r($arr1);
  132. print_r($arr2);
  133. exit;*/
  134. $arr = multi_merge($arr1, $arr2);//合并二维数组
  135. ?>
  136. <!DOCTYPE html>
  137. <html>
  138. <head>
  139. <meta charset="UTF-8">
  140. <title>run_stock数据检测</title>
  141. <style type="text/css">
  142. td {
  143. border: 1px solid;
  144. }
  145. </style>
  146. </head>
  147. <body>
  148. <h2 style="margin-left:20%">run_stock数据检测</h2>
  149. <table width="60%">
  150. <tr>
  151. <td width="10%">ID</td>
  152. <td width="10%">出发日期run_date</td>
  153. <td width="10%">班次run_id</td>
  154. <td width="10%">排序(分段)seq_id</td>
  155. <td width="10%">实际订单数量</td>
  156. <td width="10%">记录已售数量</td>
  157. </tr>
  158. <?php $i = 1;
  159. foreach ($arr as $k => $v) { ?>
  160. <tr style="<?php if ($v['num1'] != $v['num2']) {
  161. echo 'color:red';
  162. } ?>">
  163. <td><?php echo $i; ?></td>
  164. <td><?php echo $v['run_date']; ?></td>
  165. <td><?php echo $v['run_id']; ?></td>
  166. <td><?php echo $v['seq_id']; ?></td>
  167. <td><?php echo $v['num1']; ?></td>
  168. <td><?php echo $v['num2']; ?></td>
  169. </tr>
  170. <?php $i++;
  171. } ?>
  172. </table>
  173. </body>
  174. </html>