|
- <?php
- /*
- Author:fuhc
- Compeny:导出次日上车乘客信息 将备注转为一条数据添加进去
- */
- require_once '../Common/Mysql.php';
- require_once '../Common/order_common.php';
- if (ALLOW_ORIGIN)
- header("Access-Control-Allow-Origin:*");
- set_time_limit(1200);
- $method = isset($_GET['method']) ? $_GET['method'] : "";
-
- $user_id = getUserId();
- $not_cancel_mode = isset($_GET['nocancel']) ? $_GET['nocancel'] : 0;
- $timelimit = isset($_GET['timelimit']) ? $_GET['timelimit'] : '出发时间';
- $starttime = isset($_GET['starttime']) ? $_GET['starttime'] : date("Y-m-d");
- $endtime = isset($_GET['endtime']) ? $_GET['endtime'] : date("Y-m-d");
- //$starttime = "2016-08-04";
- //$endtime = "2016-08-04";
- $ordersource = isset($_GET['ordersource']) ? (empty($_GET['ordersource']) ? -1 : $_GET['ordersource']) : -1;
- $orderstatus = isset($_GET['orderstatus']) ? (empty($_GET['orderstatus']) ? 0 : $_GET['orderstatus']) : 0;
- $moresearch = isset($_GET['moresearch']) ? $_GET['moresearch'] : '';
-
- //2016-07-15新增
- $start_area = isset($_GET['start_area']) ? $_GET['start_area'] : '';
- $end_area = isset($_GET['end_area']) ? $_GET['end_area'] : '';
- $line = isset($_GET['line']) ? $_GET['line'] : '';
- $run_time = isset($_GET['run_time'])?$_GET['run_time']:'';
- $search_bus_no = isset($_GET['search_bus_no'])?$_GET['search_bus_no']:'';
- $cusmo = isset($_GET['cusmo'])?$_GET['cusmo']:0;
-
- //2016-10-19新增
- $bus_type_param = isset($_GET['bus_type'])?$_GET['bus_type']:"0";
-
- $_GET["main_corp_id"] = isset($_COOKIE["user_main_corp"]) ? $_COOKIE["user_main_corp"] : 0;
-
- //2018/2/8
- //运营负责人
- $run_duty=isset($_GET['run_duty']) ? $_GET['run_duty'] : '-1';
-
- $pdo = conn();
- $pdo2 = conn();
- $pdo3 = conn();
-
- //分销往返票的统计
- $sql_both = " SELECT to_orderid,back_orderid FROM to_from WHERE CREATE_TIME >= '{$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();
-
- $all_supplier_array = get_memcache("ARY_ALL_SUPPLIER");
- if( false == $all_supplier_array || is_array($all_supplier_array) == false || count($all_supplier_array) <= 0 ) {
- $pdo4=conn();
- $sql = " SELECT id,main_corp_id,supplier_type,supplier_name FROM base_supplier WHERE cancel_flag = 0 ";
- $result=$pdo->query($sql);
- $search_result = $result->fetchAll(PDO::FETCH_ASSOC);
- $all_supplier_array = array();
- foreach( $search_result as $result_info ) {
- $all_supplier_array[$result_info["id"]] = $result_info;
- }
- $result->closeCursor();
- }
- $all_user_array = get_memcache("ARY_ALL_CSUSER");
- if( false == $all_user_array || is_array($all_user_array) == false || count($all_user_array) <= 0 ) {
- $pdo5=conn();
- $sql = " SELECT id,user_name,true_name FROM base_user WHERE id > 0 ";
- $result=$pdo5->query($sql);
- $search_result = $result->fetchAll(PDO::FETCH_ASSOC);
- $all_user_array = array();
- foreach( $search_result as $result_info ) {
- $all_user_array[$result_info["id"]] = $result_info;
- }
- $result->closeCursor();
- }
-
- $order_list = get_export_order_list( $pdo, $_GET );
- if( $order_list == false ) {
- $data['code']="400";
- $data['info']="没有符合检索条件的数据";
- echo json_encode($data);exit();
- }
- $data = $order_list;
-
- if( $cusmo == 1 ) {
- $str = "线路名称,上车站点,下车站点,预定日期,发班日期,发班时间,发车时间,订单号,渠道,出行人数,GMV,序号,游客姓名,身份证号,联系方式,是否购买保险,运营负责人" . "\n";
- } else {
- $str = "线路名称,线路类型,车号,车队名,车牌号码,司机姓名,司机手机,出发地,上车站点,目的地,下车站点,预订日期,发班日期,发班时间,发车时间,座位等级,出行人数,座位号,分销价,GMV,用车成本,渠道佣金,游客姓名,联系方式,身份证号,出行人,下单人,渠道,渠道订单号,销售终端,销售终端号,订单号,状态,支付方式,是否组合订单,备注,上门接地址,运营负责人" . "\n";
- }
- $disp_pay_type = array("221" => "授信支付", "232" => "天猫旗舰店支付", "275" => "授信支付", "278" => "微信支付");
- $disp_order_status = array( "145" => "待支付", "146" => "已出票", "147" => "已完成", "148" => "已取消" );
- for ($i = 0; $i < count($data); $i++) {
- $dict = $data[$i];
- $dict['order_status'] = $disp_order_status[$dict['order_status']];
- if( $not_cancel_mode == 1 ) {
- if( $dict['order_status'] != "已出票" && $dict['order_status'] != "已完成" ) {
- continue;
- }
- }
- $send_bus_no = $dict["send_bus_no"] . "\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": "-";
- }
- $create_user_name = "";
- if( isset($all_user_array[$dict["create_user_id"]]) ) {
- $user_info = $all_user_array[$dict["create_user_id"]];
- $create_user_name = strlen($user_info["true_name"]) > 0 ? $user_info["true_name"] : $user_info["user_name"];
- }
- $send_driver_mobile = $dict["send_driver_mobile"] . "\t";
- $seat_list = isset($dict['seat_list']) ? str_replace(",","/",$dict['seat_list']) . "\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['bus_run_time'], 0, 10) . "\t";
- $run_time = substr($dict['prod_start_station_time'], 0, 10) . "\t";
- $passenger_list = $dict['passenger_info'] . "\t";
- if( in_array( $dict['parent_orderNo'], $bothway_order_array ) && mb_strpos($dict['prod_name'], "往返") === false ) {
- $dict['prod_name'] .= "(往返)";
- }
- // $prod_name=$dict['line']."\t";
- $create_time=$dict['create_time']."\t";
- $seat=$dict['prod_name']."\t";
- $order_count = $dict['count'];
- $order_price=$dict['order_price'];
- $GMV = isset($dict['gmv']) ? $dict['gmv']: "-";
- $base_price = isset($dict['base_price']) ? $dict['base_price'] : "-";
- $total_commision = isset($dict['total_commission']) ? $dict['total_commission'] : "-";
- $customer_name = isset($dict['contacts'])?$dict['contacts']. "\t":"-" ;
- $customer_mobile = isset($dict['tel'])?$dict['tel']. "\t":"-" ;
- $customer_id_no = isset($dict['idNo'])?$dict['idNo']. "\t":"-";
- $order_remark = $dict['remark'];
- $order_address = $dict['customer_address'];
-
- $run_duty_name = isset($all_user_array[$dict['run_duty_id']]) ? $all_user_array[$dict['run_duty_id']]["true_name"] : '';
-
- if( isset($all_supplier_array[$dict["org_id"]]) ) {
- $dict["org_name"] = $all_supplier_array[$dict["org_id"]]["supplier_name"];
- } else {
- $dict["org_name"] = "";
- }
-
- if( isset($all_supplier_array[$dict["sub_channel_id"]]) ) {
- $dict["sub_channel_name"] = $all_supplier_array[$dict["sub_channel_id"]]["supplier_name"];
- } else {
- $dict["sub_channel_name"] = "";
- }
-
- $org_name = $dict['org_name'];
- $outside_order_no = $dict['outside_order_no']==""?"-":$dict['outside_order_no']. "\t";
- $sub_channel_name = $dict['sub_channel_name'];
- $sub_channel_no = $dict['sub_channel_no']==""?"-":$dict['sub_channel_no']. "\t";
- $parent_order_id = $dict['parent_orderNo'] . "\t";
- $bus_order_id = isset($dict['bus_order_id']) ? $dict['bus_order_id'] . "\t" : "-";
- $order_status=$dict['order_status'];
- $order_group_flag = $dict['order_title_id'] > 0 ? "是({$dict['order_title_id']})" : "否" ;
- $pay_type= isset($disp_pay_type[$dict['pay_type']]) ? $disp_pay_type[$dict['pay_type']] : "授信支付";
- $if_gift = $dict['if_gift'] == 1 ? "是" : "否";
- if( $cusmo == 1 ) {
- $passenger_index = 0;
- $passenger_array = array();
- if( strpos( $order_remark, "/" ) != false && strpos( $order_remark, "*" ) != false ) {
- $passenger_array = explode("/", $order_remark);
- }
- while( $passenger_index < $order_count ) {
- $passenger_name = $customer_name;
- $passenger_idno = $customer_id_no;
- if( isset($passenger_array[$passenger_index]) ) {
- $passenger_info_tmp = explode("*", $passenger_array[$passenger_index]);
- $passenger_name = isset($passenger_info_tmp[0]) ? $passenger_info_tmp[0] : $customer_name;
- $passenger_idno = isset($passenger_info_tmp[1]) ? $passenger_info_tmp[1]. "\t" : $customer_id_no;
- }
- $passenger_index ++;
- $strline = $line . "," . $start_station . "," . $end_station . "," . $create_time . "," . $run_date . "," . $bus_run_time . "," . $run_time . "," . $parent_order_id . "," . $org_name . "," . $order_count . "," . $GMV . "," . $passenger_index . "," . $passenger_name . ",\"" . $passenger_idno . "\",\"" . $customer_mobile . "\"," . $if_gift . "," . $run_duty_name;
- $strline=str_replace(array("\n","\r"),array("",""),$strline);
- $str.= $strline."\n";
- }
- } else {
- $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 . "," . $seat . "," . $order_count . "," . $seat_list . "," . $order_price . "," . $GMV . "," . $base_price . "," . $total_commision . "," . $customer_name . ",\"" . $customer_mobile . "\",\"" . $customer_id_no . "\"," ."\"".$passenger_list."\",". $create_user_name . "," . $org_name . ",\"" . $outside_order_no . "\"," . $sub_channel_name . ",\"" . $sub_channel_no . "\"," . $parent_order_id . "," . $order_status . "," . $pay_type . "," . $order_group_flag . "," . $order_remark . "," . $order_address . "," . $run_duty_name;
- $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();
|