= '{$starttime} 00:00:00' AND CREATE_TIME <= '{$endtime} 23:59:59' "; $bothway_order_array = array(); $result2 = $pdo2->query($sql_both); if( $result2 ) { $to_from_array =$result2->fetchAll(); $result2->closeCursor(); if( false != $to_from_array && count($to_from_array) > 0 ) { foreach( $to_from_array as $to_from_info ) { $bothway_order_array[] = $to_from_info["to_orderid"]; $bothway_order_array[] = $to_from_info["back_orderid"]; } } } $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 "; $result3 = $pdo3->query($sql_search_bus); $bus_array =$result3->fetchAll(); $all_bus_array = array(); foreach( $bus_array as $bus_info ) { $all_bus_array[$bus_info["bus_id"]] = $bus_info; } $result3->closeCursor(); //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) //$sql = "CALL SP_EXPORT_CUSTOMERINFO(1,'" . $timelimit . "','" . $starttime . "','" . $endtime . "'," . $ordersource . "," . $orderstatus . "," . $paystatus . ",'" . $billingstatus . "','" . $mealbounce . "','" . $refund . "','" . $moresearch . "','" . $export . "'," . $currentpage . "," . $pagesize . ",'" . $line . "','" . $start_area . "','" . $end_area . "')"; $sql = "CALL SP_EXPORT_CUSTOMER('".$timelimit."','".$starttime."','".$endtime."','".$ordersource."','".$orderstatus."','".$moresearch."','".$line."','".$start_area."','".$end_area."',{$user_id});"; writeLog('order_list2.php export-- sql== '.$sql); if($pdo){ $result = $pdo -> query($sql); if($result){ $data = array(); $data = $result -> fetchAll(PDO::FETCH_ASSOC); }else{ $data['code']="400"; $data['info']="数据库错误"; echo json_encode($data);exit(); } }else{ $data['code']="500"; $data['info']="连接数据库错误"; echo json_encode($data);exit(); } $str = "线路名称,线路类型,车号,车队名,车牌号码,司机姓名,司机手机,出发地,上车站点,目的地,下车站点,预订日期,发班日期,发班时间,乘客预定时间,产品名称,座位等级,出行人数,分销价,GMV,用车成本,渠道佣金,游客姓名,联系方式,身份证号,渠道,渠道订单号,订单号,状态,支付方式" . "\n"; $disp_pay_type = array("221" => "授信支付", "232" => "天猫旗舰店支付", "275" => "授信支付", "278" => "微信支付"); for ($i = 0; $i < count($data); $i++) { $dict = $data[$i]; if( $not_cancel_mode == 1 ) { if( $dict['order_status'] != "已出票" && $dict['order_status'] != "已完成" ) { continue; } if( $dict['create_user_id'] == 450 ) { continue; } } $send_bus_no = $dict["send_bus_no"] . "\t"; // $bus_type = $dict["bus_type"] . "\t"; $send_bus_res_id = $dict["send_bus_res_id"]; if( isset($all_bus_array[$send_bus_res_id]) ) { $bus_info = $all_bus_array[$send_bus_res_id]; $send_bus_company_name = $bus_info["supplier_name"] . "\t"; } else { $send_bus_company_name = " \t"; } $send_driver_name = $dict["send_driver_name"] . "\t"; $disp_bus_type = array("255" => "直通巴士", "256" => "穿梭巴士","284" => "城际商务车"); // $bus_type = isset($disp_bus_type[$dict["bus_type"]])?$disp_bus_type[$dict["bus_type"]]. "\t": "-"; if($bus_type_param=="0"){ $bus_type = isset($disp_bus_type[$dict["bus_type"]])?$disp_bus_type[$dict["bus_type"]]. "\t": "-"; }else{ if($bus_type_param!=$dict['bus_type']){ continue; } $bus_type = isset($disp_bus_type[$bus_type_param])?$disp_bus_type[$bus_type_param]. "\t": "-"; } $send_driver_mobile = $dict["send_driver_mobile"] . "\t"; $line = $dict['line'] . "\t"; $start_area = $dict['start_area'] . "\t"; $start_station = $dict['start_station'] . "\t"; $end_area = $dict['end_area'] . "\t"; $end_station = $dict['end_station'] . "\t"; $run_date = substr($dict['run_date'], 0, 10) . "\t"; $bus_run_time = substr($dict['run_time'], 0, 10) . "\t"; $run_time = substr($dict['run_time'], 0, 10) . "\t"; if( in_array( $dict['parent_order_id'], $bothway_order_array ) && mb_strpos($dict['prod_name'], "往返") === false ) { $dict['prod_name'] .= "(往返)"; } $prod_name=$dict['prod_name']."\t"; $create_time=$dict['create_time']."\t"; $seat=$dict['seat']."\t"; $order_count = $dict['order_count']; $order_price=$dict['order_price']; $GMV = isset($dict['gmv']) ? $dict['gmv']: "-"; $base_price = isset($dict['base_price']) ? $dict['base_price'] * $order_count: "-"; $total_commision = isset($dict['total_commission']) ? $dict['total_commission'] * $order_count: "-"; $customer_name = isset($dict['customer_name'])?$dict['customer_name']. "\t":"-" ; $customer_mobile = isset($dict['customer_mobile'])?$dict['customer_mobile']. "\t":"-" ; $customer_id_no = isset($dict['customer_id_no'])?$dict['customer_id_no']. "\t":"-"; $org_name = $dict['org_name'] . "\t"; $outside_order_no = $dict['outside_order_no']==""?"-":$dict['outside_order_no']."\t"; $parent_order_id = $dict['parent_order_id'] . "\t"; $bus_order_id = isset($dict['bus_order_id']) ? $dict['bus_order_id'] . "\t" : "-"; $order_status=$dict['order_status']; $pay_type= isset($disp_pay_type[$dict['pay_type']]) ? $disp_pay_type[$dict['pay_type']] : "授信支付"; $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; $strline=str_replace(array("\n","\r"),array("",""),$strline); $str.= $strline."\n"; } $filename = date('Ymd') . '.csv'; //设置文件名 //echo $str; export_csv($filename, $str); //导出 function export_csv($filename, $data) { header("Content-type:text/csv"); header("Content-Disposition:attachment;filename=订单明细" . $filename); header('Cache-Control:must-revalidate,post-check=0,pre-check=0'); header('Expires:0'); header('Pragma:public'); $data = chr(0xEF) . chr(0xBB) . chr(0xBF) . $data; // $data = iconv("utf-8","gb2312",$data); writeLog('export success'); echo $data; } exit();