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.
 
 
 
 

316 lines
12 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. $order_from_org_id = $_COOKIE['org_id'];
  7. $top_org_id = $_COOKIE['top_org_id'];
  8. if (!$user_id) {
  9. echo json_encode(array("code" => 1,"iflogin"=>1, "info" => "用户未登录"));
  10. exit ;
  11. }
  12. $currpage = isset($_POST['currpage'])?$_POST['currpage']:'1';
  13. $pagesize = isset($_POST['pagesize'])?$_POST['pagesize']:'10';
  14. $list_start= ($currpage-1)*$pagesize;
  15. $condition='';
  16. if($_POST){
  17. $condition=array(); //定义条件数组
  18. //接受条件数据
  19. $time_style = isset($_POST['time_style'])?$_POST['time_style']:''; //timestyle=1 代表创建时间 =2 代表是出发时间
  20. //$start_time=isset($_POST['start_time'])?$_POST['start_time']:'';
  21. $start_time=isset($_POST['start_time'])?$_POST['start_time']>'2016-09-01'?$_POST['start_time']:'2016-09-01':'2016-09-01';
  22. $end_time=isset($_POST['end_time'])?$_POST['end_time']:'';
  23. $start_area=isset($_POST['start_area'])?$_POST['start_area']:'';
  24. $end_area=isset($_POST['end_area'])?$_POST['end_area']:'';
  25. $product_type=isset($_POST['product_type'])?$_POST['product_type']:''; //票种类 0.256.255.257 0为空 256穿梭巴士,255直通巴士
  26. $order_id=isset($_POST['order_id'])?$_POST['order_id']:''; //订单号 1,2,3, 1 为 订单号 2 为客户姓名 3 为客户手机号
  27. $order_condition=isset($_POST['condition'])?$_POST['condition']:'';
  28. if($time_style==1){
  29. empty($start_time)?null:$condition[]=' and a.create_time >= "'.$start_time.' 00:00:01"'; //创建时间条件筛选
  30. empty($end_time)?null:$condition[]=' and a.create_time <= "'.$end_time.' 23:59:00"';
  31. }elseif($time_style==2){
  32. empty($start_time)?null:$condition[]=' and a.run_date >= "'.$start_time.'"'; // 出发时间筛选
  33. empty($end_time)?null:$condition[]=' and a.run_date <= "'.$end_time.'"';
  34. }
  35. empty($start_area)?null:$condition[]=' and PROD_START_STATION_AREA_NAME like "%'.$start_area.'%" ';
  36. empty($end_area)?null:$condition[]=' and PROD_END_STATION_AREA_NAME like "%'.$end_area.'%" ';
  37. if($product_type==257){
  38. $condition[]=' and order_prod_type in (258,259) ';
  39. }else{
  40. empty($product_type)?null:$condition[]=' and bus_type='.$product_type;
  41. }
  42. if($order_id==1 || $order_id==2 || $order_id==3 ){
  43. if($order_id==1)
  44. $condition[]=' and a.PARENT_ORDER_ID like "%'.$order_condition.'%"';
  45. if($order_id==2)
  46. $condition[]=' and a.customer_name like "%'.$order_condition.'%"';
  47. if($order_id==3)
  48. $condition[]=' and a.customer_mobile like "%'.$order_condition.'%"';
  49. }
  50. $condition2='';
  51. if(isset($_POST['order_status'])){
  52. $_POST['order_status']!=0?$condition2=' and order_status='.$_POST['order_status']:null;
  53. }
  54. $condition= implode('', $condition); //订单状态条件 148 已取消 146 已出票 147已出行
  55. }
  56. if($user_id>=65 && $user_id<=113 && $user_id !=106 && $user_id !=107 ){
  57. $start_time="and a.create_time >= '2016-09-01 00:00:01'";
  58. }else{
  59. $start_time='';
  60. }
  61. //echo $condition;die;
  62. //$order_status=isset($_POST['order_status'])?$condition[]=' and order_status='.$_POST['order_status']:null;
  63. //var_dump($condition);die;
  64. $pdo= conn();
  65. $sql="select a.order_id "
  66. . "from order_main as a "
  67. . "where a.PARENT_ORDER_ID=0 and ORDER_BOOK_STATUS=1 and CANCEL_FLAG=0 and outside_sale_org_id =".$order_from_org_id." $condition2 ";
  68. $result=$pdo->query($sql);
  69. $json=array();
  70. do {
  71. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  72. if ($rowset) {
  73. $json = $rowset;
  74. }
  75. } while ($result->nextRowset());
  76. if(empty($json)){
  77. $data = (array("code" => "0", "info" => "此条件下没有订单","list_count"=>0, "searchInfo" =>array()));
  78. echo json_encode($data);
  79. die;
  80. }
  81. foreach ($json as $v) {
  82. $json2[]=$v['order_id'];
  83. }
  84. $sql = "select DISTINCT PARENT_ORDER_ID,bus_type "
  85. . " from order_main a left join OPERA_PRODUCT b on a.parent_prod_id = b. prod_id "//and main_create_user_id =".$user_id."
  86. . "where PARENT_ORDER_ID in(". implode(",", $json2).") ".$start_time." order by a.create_time desc";//and PARENT_ORDER_ID = 203839
  87. //echo $sql;
  88. //die;
  89. $result_id=$pdo->query($sql);
  90. $json_id=array();
  91. $json=array();
  92. do {
  93. $rowset = $result_id -> fetchAll(PDO::FETCH_ASSOC);
  94. if ($rowset) {
  95. $json = $rowset;
  96. }
  97. } while ($result_id->nextRowset());
  98. //var_dump($json);die;
  99. if(empty($json)){
  100. $data = (array("code" => "0", "info" => "此条件下没有订单","list_count"=>0, "searchInfo" =>array()));
  101. echo json_encode($data);
  102. die;
  103. }
  104. foreach ($json as $v) {
  105. if(isset($v['PARENT_ORDER_ID']));
  106. $json_id[]=$v['PARENT_ORDER_ID'];
  107. $bus_type[$v['PARENT_ORDER_ID']] = $v['bus_type'];
  108. }
  109. //条件筛选后的订单编号
  110. //echo $sql;
  111. //var_dump($json_id);die;
  112. $sql="select a.prod_name,a.order_prod_type,a.order_description,a.ORDER_PAY_MAIN_ID,a.order_id,a.customer_name,a.customer_mobile,a.customer_id_type,a.customer_id_no,a.order_price,a.order_status,a.create_time,a.prod_id "
  113. . "from order_main as a "
  114. . "where a.PARENT_ORDER_ID=0 ";//on a.order_id=b.order_id
  115. $result=$pdo->query($sql);
  116. $data=array();
  117. do {
  118. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  119. if ($rowset) {
  120. $data[] = $rowset; //
  121. }
  122. } while ($result->nextRowset());
  123. $order_info=array();
  124. foreach ($data[0] as $v) {
  125. $order_info[$v['order_id']]=$v; //价格手机 姓名 run_time pay_time
  126. }
  127. $array_order_desc=array();
  128. foreach ($data[0] as $v) {
  129. $arr_temp = explode('|',$v['order_description']);
  130. $arr=array();
  131. foreach ($arr_temp as $k=>$v2) {
  132. if(!empty($v2))
  133. $arr[]= explode (',', $v2);
  134. }
  135. $array_order_desc[$v['order_id']]=$arr;
  136. }
  137. //var_dump($array_order_desc);die;
  138. $sql3="select parent_order_id,PROD_START_STATION_DATE as run_date,PROD_START_STATION_TIME as run_time,PROD_START_STATION_AREA_NAME,PROD_START_STATION_RES_NAME,PROD_END_STATION_AREA_NAME,PROD_END_STATION_RES_NAME "
  139. . "from order_main "
  140. . "where parent_order_id in (". implode(",", $json_id).")";
  141. $result3=$pdo->query($sql3);
  142. $rowset3 = $result3 -> fetchAll(PDO::FETCH_ASSOC);
  143. foreach ($rowset3 as $v) {
  144. $station[$v['parent_order_id']]=$v;//上车站下车站 详情
  145. }
  146. //获取支付方式
  147. $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)
  148. left join dict_type c on c.id=b.PAY_TYPE_ID_1 "
  149. . " where a.ORDER_ID in (". implode(",", $json_id).")";
  150. $result2=$pdo->query($sql2);
  151. do {
  152. $rowset2 = $result2 -> fetchAll(PDO::FETCH_ASSOC);
  153. if ($rowset2) {
  154. $pay_type[] = $rowset2;
  155. }
  156. } while ($result2->nextRowset());
  157. foreach ($pay_type[0] as $v) {
  158. $pay_type_arr[$v['ORDER_ID']]=$v['TYPE_NAME']; //支付方式
  159. }
  160. //支付状态
  161. $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)
  162. left join dict_type c on c.id=a.ORDER_STATUS "
  163. . " where a.ORDER_ID in (". implode(",", $json_id).")";
  164. $result4=$pdo->query($sql4);
  165. do {
  166. $rowset4 = $result4 -> fetchAll(PDO::FETCH_ASSOC);
  167. if ($rowset4) {
  168. $order_sta[] = $rowset4;
  169. }
  170. } while ($result4->nextRowset());
  171. foreach ($order_sta[0] as $v) {
  172. $order_status[$v['ORDER_ID']]=$v['TYPE_NAME'];
  173. $order_status_id[$v['ORDER_ID']]=$v['order_status'];//订单的状态
  174. }
  175. $array_order_list=array();
  176. //echo count($pay_type_arr),'--', count($json_id);
  177. //var_dump($array_order_desc);die;
  178. foreach ($json_id as $v) {
  179. $tic='';
  180. if($order_info[$v]['order_prod_type']==258 || $order_info[$v]['order_prod_type']==259){
  181. foreach($array_order_desc[$v] as $v1){
  182. $tic.= str_replace('迪士尼剧场','',$v1[0]).'×'.$v1[2].' ';
  183. if(isset($v1['ifback']))
  184. $ifback=$v1['ifback'];
  185. }
  186. $product_info =$order_info[$v]['prod_name'];
  187. $ifdisn=0;
  188. if($order_info[$v]['order_prod_type']==258 ){
  189. $type ="迪士尼门票";
  190. }else{
  191. $type = "迪士尼剧场";
  192. }
  193. if($top_org_id!=0){
  194. $go_to =0;//不显示
  195. }else{
  196. if($order_status_id[$v]==145){
  197. $go_to ='1';//去支付
  198. } else {
  199. $go_to='0';
  200. }
  201. }
  202. }else{
  203. if($bus_type[$v] ==255){
  204. $type ="直通巴士";
  205. }else{
  206. $type = "穿梭巴士";
  207. }
  208. foreach($array_order_desc[$v] as $v1){
  209. if( !isset($v1[2]) ) {
  210. continue;
  211. }
  212. $tic.= str_replace('票','',$v1[0]).'×'.$v1[2].' ';
  213. if(isset($v1['ifback']))
  214. $ifback=$v1['ifback'];
  215. }
  216. $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'].')';
  217. $ifdisn=1;
  218. //退票 去支付 空
  219. if($top_org_id!=0){
  220. $time_cut = strtotime($station[$v]['run_date'].' '.$station[$v]['run_time'].':01')-time();
  221. if($order_status_id[$v]==146){
  222. if($time_cut<1800){
  223. $go_to=0;
  224. }else{
  225. $go_to =2;//退票
  226. }
  227. }else{
  228. $go_to=0;
  229. }
  230. }else{
  231. $time_cut = strtotime($station[$v]['run_date'].' '.$station[$v]['run_time'].':01')-time();
  232. if($order_status_id[$v]==146){
  233. if($time_cut<1800){
  234. $go_to=0;
  235. }else{
  236. $go_to =0;//退票
  237. }
  238. }else{
  239. $time_cut = time()-strtotime($order_info[$v]['create_time']);
  240. if($time_cut>600 ||$order_status_id[$v]==148 ){
  241. $go_to=0;
  242. }else{
  243. $go_to=1;
  244. }
  245. }
  246. }
  247. }
  248. $array_order_list[]=array(
  249. 'order_id' =>$v,
  250. 'create_time' =>substr($order_info[$v]['create_time'],5,11),
  251. 'go_pay' =>$go_to,
  252. 'start_station_area' => $station[$v]['PROD_START_STATION_AREA_NAME'],
  253. 'start_station_name' => $station[$v]['PROD_START_STATION_RES_NAME'],
  254. 'end_station_area' => $station[$v]['PROD_END_STATION_AREA_NAME'],
  255. 'end_station_name' => $station[$v]['PROD_END_STATION_RES_NAME'],
  256. 'product_info' =>$product_info,
  257. 'ifdisney' =>$ifdisn,
  258. 'run_time' => substr($station[$v]['run_date'].' '.$station[$v]['run_time'],5,11),
  259. 'customer_id_type' => $order_info[$v]['customer_id_type'],
  260. 'customer_name'=>$order_info[$v]['customer_name'],
  261. 'customer_mobile'=>$order_info[$v]['customer_mobile'],
  262. 'customer_id_no' =>$order_info[$v]['customer_id_no'],
  263. 'order_pay' =>$order_info[$v]['order_price'],
  264. 'order_pay_type' =>$pay_type_arr[$v],
  265. 'order_status' => $order_status[$v],
  266. 'tic_info' =>$tic,
  267. 'pic_type' => $type,
  268. );
  269. }
  270. $list_count= count($array_order_list);
  271. //echo $list_count;
  272. $array_order_list=array_slice($array_order_list, $list_start,$pagesize);
  273. $data = (array("code" => "0", "info" => "","list_count"=>$list_count, "searchInfo" =>$array_order_list));
  274. echo json_encode($data);