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.
 
 
 
 

166 lines
7.8 KiB

  1. <?php
  2. /*
  3. Author:fuhc
  4. Compeny:导出次日上车乘客信息 将备注转为一条数据添加进去
  5. */
  6. require_once '../Common/Mysql.php';
  7. if (ALLOW_ORIGIN)
  8. header("Access-Control-Allow-Origin:*");
  9. set_time_limit(1200);
  10. $method = isset($_GET['method']) ? $_GET['method'] : "";
  11. $user_id = getUserId();
  12. $not_cancel_mode = isset($_GET['nocancel']) ? $_GET['nocancel'] : 0;
  13. $timelimit = isset($_GET['timelimit']) ? $_GET['timelimit'] : '出发时间';
  14. $starttime = isset($_GET['starttime']) ? $_GET['starttime'] : date("Y-m-d");
  15. $endtime = isset($_GET['endtime']) ? $_GET['endtime'] : date("Y-m-d");
  16. //$starttime = "2016-08-04";
  17. //$endtime = "2016-08-04";
  18. $ordersource = isset($_GET['ordersource']) ? (empty($_GET['ordersource']) ? -1 : $_GET['ordersource']) : -1;
  19. $orderstatus = isset($_GET['orderstatus']) ? (empty($_GET['orderstatus']) ? 0 : $_GET['orderstatus']) : 0;
  20. $moresearch = isset($_GET['moresearch']) ? $_GET['moresearch'] : '';
  21. //2016-07-15新增
  22. $start_area = isset($_GET['start_area']) ? $_GET['start_area'] : '';
  23. $end_area = isset($_GET['end_area']) ? $_GET['end_area'] : '';
  24. $line = isset($_GET['line']) ? $_GET['line'] : '';
  25. //2016-10-19新增
  26. $bus_type_param = isset($_GET['bus_type'])?$_GET['bus_type']:"0";
  27. $pdo = conn();
  28. $pdo2 = conn();
  29. $pdo3 = conn();
  30. //分销往返票的统计
  31. $sql_both = " SELECT to_orderid,back_orderid FROM to_from WHERE CREATE_TIME >= '{$starttime} 00:00:00' AND CREATE_TIME <= '{$endtime} 23:59:59' ";
  32. $bothway_order_array = array();
  33. $result2 = $pdo2->query($sql_both);
  34. if( $result2 ) {
  35. $to_from_array =$result2->fetchAll();
  36. $result2->closeCursor();
  37. if( false != $to_from_array && count($to_from_array) > 0 ) {
  38. foreach( $to_from_array as $to_from_info ) {
  39. $bothway_order_array[] = $to_from_info["to_orderid"];
  40. $bothway_order_array[] = $to_from_info["back_orderid"];
  41. }
  42. }
  43. }
  44. $sql_search_bus = " SELECT base_bus.bus_id,base_bus.org_id,base_supplier.supplier_name FROM base_bus LEFT JOIN base_supplier ON base_supplier.id = base_bus.org_id WHERE base_bus.main_corp_id <> 3 ";
  45. $result3 = $pdo3->query($sql_search_bus);
  46. $bus_array =$result3->fetchAll();
  47. $all_bus_array = array();
  48. foreach( $bus_array as $bus_info ) {
  49. $all_bus_array[$bus_info["bus_id"]] = $bus_info;
  50. }
  51. $result3->closeCursor();
  52. //IN `TIMELIMIT` VARCHAR(20), IN `STARTTIME` VARCHAR(20), IN `ENDTIME` VARCHAR(20), IN `ORDERSOURCE` INT, IN `ORDERSTATUS` INT, IN `MORESEARCH` VARCHAR(50), IN `LINE` VARCHAR(20), IN `START_AREA` VARCHAR(20), IN `END_AREA` VARCHAR(20)
  53. //$sql = "CALL SP_EXPORT_CUSTOMERINFO(1,'" . $timelimit . "','" . $starttime . "','" . $endtime . "'," . $ordersource . "," . $orderstatus . "," . $paystatus . ",'" . $billingstatus . "','" . $mealbounce . "','" . $refund . "','" . $moresearch . "','" . $export . "'," . $currentpage . "," . $pagesize . ",'" . $line . "','" . $start_area . "','" . $end_area . "')";
  54. $sql = "CALL SP_EXPORT_CUSTOMER('".$timelimit."','".$starttime."','".$endtime."','".$ordersource."','".$orderstatus."','".$moresearch."','".$line."','".$start_area."','".$end_area."',{$user_id});";
  55. writeLog('order_list2.php export-- sql== '.$sql);
  56. if($pdo){
  57. $result = $pdo -> query($sql);
  58. if($result){
  59. $data = array();
  60. $data = $result -> fetchAll(PDO::FETCH_ASSOC);
  61. }else{
  62. $data['code']="400";
  63. $data['info']="数据库错误";
  64. echo json_encode($data);exit();
  65. }
  66. }else{
  67. $data['code']="500";
  68. $data['info']="连接数据库错误";
  69. echo json_encode($data);exit();
  70. }
  71. $str = "线路名称,线路类型,车号,车队名,车牌号码,司机姓名,司机手机,出发地,上车站点,目的地,下车站点,预订日期,发班日期,发班时间,乘客预定时间,产品名称,座位等级,出行人数,分销价,GMV,用车成本,渠道佣金,游客姓名,联系方式,身份证号,渠道,渠道订单号,订单号,状态,支付方式" . "\n";
  72. $disp_pay_type = array("221" => "授信支付", "232" => "天猫旗舰店支付", "275" => "授信支付", "278" => "微信支付");
  73. for ($i = 0; $i < count($data); $i++) {
  74. $dict = $data[$i];
  75. if( $not_cancel_mode == 1 ) {
  76. if( $dict['order_status'] != "已出票" && $dict['order_status'] != "已完成" ) {
  77. continue;
  78. }
  79. if( $dict['create_user_id'] == 450 ) {
  80. continue;
  81. }
  82. }
  83. $send_bus_no = $dict["send_bus_no"] . "\t";
  84. // $bus_type = $dict["bus_type"] . "\t";
  85. $send_bus_res_id = $dict["send_bus_res_id"];
  86. if( isset($all_bus_array[$send_bus_res_id]) ) {
  87. $bus_info = $all_bus_array[$send_bus_res_id];
  88. $send_bus_company_name = $bus_info["supplier_name"] . "\t";
  89. } else {
  90. $send_bus_company_name = " \t";
  91. }
  92. $send_driver_name = $dict["send_driver_name"] . "\t";
  93. $disp_bus_type = array("255" => "直通巴士", "256" => "穿梭巴士","284" => "城际商务车");
  94. // $bus_type = isset($disp_bus_type[$dict["bus_type"]])?$disp_bus_type[$dict["bus_type"]]. "\t": "-";
  95. if($bus_type_param=="0"){
  96. $bus_type = isset($disp_bus_type[$dict["bus_type"]])?$disp_bus_type[$dict["bus_type"]]. "\t": "-";
  97. }else{
  98. if($bus_type_param!=$dict['bus_type']){
  99. continue;
  100. }
  101. $bus_type = isset($disp_bus_type[$bus_type_param])?$disp_bus_type[$bus_type_param]. "\t": "-";
  102. }
  103. $send_driver_mobile = $dict["send_driver_mobile"] . "\t";
  104. $line = $dict['line'] . "\t";
  105. $start_area = $dict['start_area'] . "\t";
  106. $start_station = $dict['start_station'] . "\t";
  107. $end_area = $dict['end_area'] . "\t";
  108. $end_station = $dict['end_station'] . "\t";
  109. $run_date = substr($dict['run_date'], 0, 10) . "\t";
  110. $bus_run_time = substr($dict['run_time'], 0, 10) . "\t";
  111. $run_time = substr($dict['run_time'], 0, 10) . "\t";
  112. if( in_array( $dict['parent_order_id'], $bothway_order_array ) && mb_strpos($dict['prod_name'], "往返") === false ) {
  113. $dict['prod_name'] .= "(往返)";
  114. }
  115. $prod_name=$dict['prod_name']."\t";
  116. $create_time=$dict['create_time']."\t";
  117. $seat=$dict['seat']."\t";
  118. $order_count = $dict['order_count'];
  119. $order_price=$dict['order_price'];
  120. $GMV = isset($dict['gmv']) ? $dict['gmv']: "-";
  121. $base_price = isset($dict['base_price']) ? $dict['base_price'] * $order_count: "-";
  122. $total_commision = isset($dict['total_commission']) ? $dict['total_commission'] * $order_count: "-";
  123. $customer_name = isset($dict['customer_name'])?$dict['customer_name']. "\t":"-" ;
  124. $customer_mobile = isset($dict['customer_mobile'])?$dict['customer_mobile']. "\t":"-" ;
  125. $customer_id_no = isset($dict['customer_id_no'])?$dict['customer_id_no']. "\t":"-";
  126. $org_name = $dict['org_name'] . "\t";
  127. $outside_order_no = $dict['outside_order_no']==""?"-":$dict['outside_order_no']."\t";
  128. $parent_order_id = $dict['parent_order_id'] . "\t";
  129. $bus_order_id = isset($dict['bus_order_id']) ? $dict['bus_order_id'] . "\t" : "-";
  130. $order_status=$dict['order_status'];
  131. $pay_type= isset($disp_pay_type[$dict['pay_type']]) ? $disp_pay_type[$dict['pay_type']] : "授信支付";
  132. $strline = $line . ",".$bus_type."," . $bus_order_id . "," . $send_bus_company_name. "," .$send_bus_no . "," . $send_driver_name . "," . $send_driver_mobile . "," . $start_area ."," . $start_station . "," . $end_area ."," . $end_station . "," . $create_time . "," . $run_date . ",". $bus_run_time . ",". $run_time . ",".$prod_name."," . $seat . "," . $order_count . "," . $order_price . "," . $GMV . "," . $base_price . "," . $total_commision . "," . $customer_name . ",\"" . $customer_mobile . "\",\"" . $customer_id_no . "\"," . $org_name . ",\"" . $outside_order_no . "\"," . $parent_order_id . "," . $order_status. "," .$pay_type;
  133. $strline=str_replace(array("\n","\r"),array("",""),$strline);
  134. $str.= $strline."\n";
  135. }
  136. $filename = date('Ymd') . '.csv';
  137. //设置文件名
  138. //echo $str;
  139. export_csv($filename, $str);
  140. //导出
  141. function export_csv($filename, $data) {
  142. header("Content-type:text/csv");
  143. header("Content-Disposition:attachment;filename=订单明细" . $filename);
  144. header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
  145. header('Expires:0');
  146. header('Pragma:public');
  147. $data = chr(0xEF) . chr(0xBB) . chr(0xBF) . $data;
  148. // $data = iconv("utf-8","gb2312",$data);
  149. writeLog('export success');
  150. echo $data;
  151. }
  152. exit();