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.
 
 
 
 

201 lines
8.2 KiB

  1. <?php
  2. if (ALLOW_ORIGIN)
  3. header("Access-Control-Allow-Origin:*");
  4. //require_once '../../Common/Mysql.php';
  5. $user_id = $_COOKIE['user_id'];//getUserId();
  6. if (!$user_id) {
  7. echo json_encode(array("code" => 1, "info" => "用户未登录"));
  8. exit ;
  9. }
  10. $currpage = isset($_POST['currpage'])?$_POST['currpage']:'1';
  11. $pagesize = isset($_POST['pagesize'])?$_POST['pagesize']:'1000';
  12. $list_start= ($currpage-1)*$pagesize;
  13. $condition='';
  14. if($_POST){
  15. $condition=array(); //定义条件数组
  16. //接受条件数据
  17. $time_style = isset($_POST['time_style'])?$_POST['time_style']:''; //timestyle=1 代表创建时间 =2 代表是出发时间
  18. $start_time=isset($_POST['start_time'])?$_POST['start_time']:'';
  19. $end_time=isset($_POST['end_time'])?$_POST['end_time']:'';
  20. $start_area=isset($_POST['start_area'])?$_POST['start_area']:'';
  21. $end_area=isset($_POST['end_area'])?$_POST['end_area']:'';
  22. $product_type=isset($_POST['product_type'])?$_POST['product_type']:''; //票种类 0.256.255.257 0为空 256穿梭巴士,255直通巴士
  23. $order_id=isset($_POST['order_id'])?$_POST['order_id']:''; //订单号 1,2,3, 1 为 订单号 2 为客户姓名 3 为客户手机号
  24. $order_condition=isset($_POST['condition'])?$_POST['condition']:'';
  25. if($time_style==1){
  26. empty($start_time)?null:$condition[]=' and a.create_time >= "'.$start_time.' 00:00:00"'; //创建时间条件筛选
  27. empty($end_time)?null:$condition[]=' and a.create_time <= "'.$end_time.' 23:59:00"';
  28. }elseif($time_style==2){
  29. empty($start_time)?null:$condition[]=' and a.run_date >= "'.$start_time.' 00:00:00"'; // 出发时间筛选
  30. empty($end_time)?null:$condition[]=' and a.run_date <= "'.$end_time.' 23:59:00"';
  31. }
  32. empty($start_area)?null:$condition[]=' and PROD_START_STATION_AREA_NAME like "%'.$start_area.'%" ';
  33. empty($end_area)?null:$condition[]=' and PROD_END_STATION_AREA_NAME like "%'.$end_area.'%" ';
  34. empty($product_type)?null:$condition[]=' and bus_type='.$product_type;
  35. if(!empty($order_condition)){
  36. if($order_id==1)
  37. $condition[]=' and a.PARENT_ORDER_ID='.$order_condition;
  38. if($order_id==2)
  39. $condition[]=' and a.customer_name = '.$order_condition;
  40. if($order_id=3)
  41. $condition[]=' and a.customer_mobile = '.$order_condition;
  42. }
  43. if(isset($_POST['order_status'])){
  44. $_POST['order_status']!=0?$condition[]=' and order_status='.$_POST['order_status']:null;
  45. }
  46. $condition= implode('', $condition); //订单状态条件 148 已取消 146 已出票 147已出行
  47. }
  48. //$order_status=isset($_POST['order_status'])?$condition[]=' and order_status='.$_POST['order_status']:null;
  49. //var_dump($condition);die;
  50. $pdo= conn();
  51. $sql="select a.order_id "
  52. . "from order_main as a "
  53. . "where a.PARENT_ORDER_ID=0 and CANCEL_FLAG=0 ";
  54. $result=$pdo->query($sql);
  55. $json=array();
  56. do {
  57. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  58. if ($rowset) {
  59. $json = $rowset;
  60. }
  61. } while ($result->nextRowset());
  62. foreach ($json as $v) {
  63. $json2[]=$v['order_id'];
  64. }
  65. $sql = "select DISTINCT PARENT_ORDER_ID"
  66. . " from order_main a left join OPERA_PRODUCT b on a.parent_prod_id = b. prod_id "//and main_create_user_id =".$user_id."
  67. . "where PARENT_ORDER_ID in(". implode(",", $json2).") $condition and order_prod_type = 82 order by a.create_time desc";//and PARENT_ORDER_ID = 203839
  68. //echo $sql;
  69. //die;
  70. $result_id=$pdo->query($sql);
  71. $json_id=array();
  72. $json=array();
  73. do {
  74. $rowset = $result_id -> fetchAll(PDO::FETCH_ASSOC);
  75. if ($rowset) {
  76. $json = $rowset;
  77. }
  78. } while ($result_id->nextRowset());
  79. if(empty($json)){
  80. $data = (array("code" => "0", "info" => "此条件下没有订单","list_count"=>0, "searchInfo" =>array()));
  81. echo json_encode($data);
  82. die;
  83. }
  84. foreach ($json as $v) {
  85. if(isset($v['PARENT_ORDER_ID']));
  86. $json_id[]=$v['PARENT_ORDER_ID'];
  87. }
  88. //条件筛选后的订单编号
  89. //echo $sql;
  90. //var_dump($json_id);die;
  91. $sql="select a.order_description,a.ORDER_PAY_MAIN_ID,a.order_id,a.customer_name,a.customer_mobile,a.order_price,a.order_status,a.create_time,a.prod_id "
  92. . "from order_main as a "
  93. . "where a.PARENT_ORDER_ID=0 ";//on a.order_id=b.order_id
  94. $result=$pdo->query($sql);
  95. $data=array();
  96. do {
  97. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  98. if ($rowset) {
  99. $data[] = $rowset; //
  100. }
  101. } while ($result->nextRowset());
  102. $order_info=array();
  103. foreach ($data[0] as $v) {
  104. $order_info[$v['order_id']]=$v; //价格手机 姓名 run_time pay_time
  105. }
  106. $array_order_desc=array();
  107. foreach ($data[0] as $v) {
  108. $arr_temp = explode('|',$v['order_description']);
  109. $arr=array();
  110. foreach ($arr_temp as $k=>$v2) {
  111. if(!empty($v2))
  112. $arr[]= explode (',', $v2);
  113. }
  114. if(mb_strpos($arr['0'][0], '往返')){
  115. $arr[0]['ifback']=1;
  116. $array_order_desc[$v['order_id']]=$arr; //订单票 * 数量
  117. }else{
  118. $arr[0]['ifback']=0;
  119. $array_order_desc[$v['order_id']]=$arr;
  120. }
  121. }
  122. //var_dump($array_order_desc);die;
  123. $sql3="select parent_order_id,run_date,run_time,PROD_START_STATION_AREA_NAME,PROD_START_STATION_RES_NAME,PROD_END_STATION_AREA_NAME,PROD_END_STATION_RES_NAME "
  124. . "from order_main "
  125. . "where parent_order_id in (". implode(",", $json_id).")";
  126. $result3=$pdo->query($sql3);
  127. $rowset3 = $result3 -> fetchAll(PDO::FETCH_ASSOC);
  128. foreach ($rowset3 as $v) {
  129. $station[$v['parent_order_id']]=$v;//上车站下车站 详情
  130. }
  131. //获取支付方式
  132. $sql2="select a.ORDER_ID,b.PAY_TYPE_ID_1,c.TYPE_NAME from (ORDER_MAIN a left join ORDER_PAY_DETAIL b on a.ORDER_PAY_MAIN_ID=b.pay_main_id)
  133. left join dict_type c on c.id=b.PAY_TYPE_ID_1 "
  134. . " where a.ORDER_ID in (". implode(",", $json_id).")";
  135. $result2=$pdo->query($sql2);
  136. do {
  137. $rowset2 = $result2 -> fetchAll(PDO::FETCH_ASSOC);
  138. if ($rowset2) {
  139. $pay_type[] = $rowset2;
  140. }
  141. } while ($result2->nextRowset());
  142. foreach ($pay_type[0] as $v) {
  143. $pay_type_arr[$v['ORDER_ID']]=$v['TYPE_NAME']; //支付方式
  144. }
  145. //支付状态
  146. $sql4="select a.ORDER_ID,a.order_status,c.TYPE_NAME from (ORDER_MAIN a left join ORDER_PAY_DETAIL b on a.ORDER_PAY_MAIN_ID=b.pay_main_id)
  147. left join dict_type c on c.id=a.ORDER_STATUS "
  148. . " where a.ORDER_ID in (". implode(",", $json_id).")";
  149. $result4=$pdo->query($sql4);
  150. do {
  151. $rowset4 = $result4 -> fetchAll(PDO::FETCH_ASSOC);
  152. if ($rowset4) {
  153. $order_sta[] = $rowset4;
  154. }
  155. } while ($result4->nextRowset());
  156. foreach ($order_sta[0] as $v) {
  157. $order_status[$v['ORDER_ID']]=$v['TYPE_NAME']; //订单的状态
  158. }
  159. $array_order_list=array();
  160. //echo count($pay_type_arr),'--', count($json_id);
  161. //var_dump($array_order_desc);die;
  162. foreach ($json_id as $v) {
  163. $tic='';
  164. foreach($array_order_desc[$v] as $v1){
  165. if( !isset($v1[2]) ) {
  166. continue;
  167. }
  168. $tic.= $v1[0].'×'.$v1[2].' ';
  169. if(isset($v1['ifback']))
  170. $ifback=$v1['ifback'];
  171. }
  172. $array_order_list[]=array(
  173. 'order_id' =>$v,
  174. 'create_time' =>$order_info[$v]['create_time'],
  175. 'product_info' =>$station[$v]['PROD_START_STATION_AREA_NAME'].'('.$station[$v]['PROD_START_STATION_RES_NAME'].')'.'-'.$station[$v]['PROD_END_STATION_AREA_NAME'].'('.$station[$v]['PROD_END_STATION_RES_NAME'].')'.' '.$tic,
  176. 'start_station_area' => $station[$v]['PROD_START_STATION_AREA_NAME'],
  177. 'start_station_name' => $station[$v]['PROD_START_STATION_RES_NAME'],
  178. 'end_station_area' => $station[$v]['PROD_END_STATION_AREA_NAME'],
  179. 'end_station_name' => $station[$v]['PROD_END_STATION_RES_NAME'],
  180. 'run_time' =>$station[$v]['run_date'].' '.$station[$v]['run_time'],
  181. 'customer_info'=>$order_info[$v]['customer_name'].' '.$order_info[$v]['customer_mobile'],
  182. 'order_pay' =>$order_info[$v]['order_price'],
  183. 'order_pay_type' =>$pay_type_arr[$v],
  184. 'order_status' => $order_status[$v],
  185. 'ifback' => $ifback
  186. );
  187. }
  188. $list_count= count($array_order_list);
  189. //echo $list_count;
  190. $array_order_list=array_slice($array_order_list, $list_start,$pagesize);
  191. $data = (array("code" => "0", "info" => "","list_count"=>$list_count, "searchInfo" =>$array_order_list));
  192. echo json_encode($data);