|
- <?php
- /*
- Author:fuhc
- Compeny:导出次日上车乘客信息 将备注转为一条数据添加进去
- */
- require_once '../Common/Mysql.php';
- if (ALLOW_ORIGIN)
- header("Access-Control-Allow-Origin:*");
-
- $method = isset($_GET['method']) ? $_GET['method'] : "";
-
- $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;
- $paystatus = isset($_GET['paystatus']) ? (empty($_GET['paystatus']) ? -1 : $_GET['paystatus']) : -1;
- $billingstatus = isset($_GET['billingstatus']) ? $_GET['billingstatus'] : "";
- $mealbounce = isset($_GET['mealbounce']) ? $_GET['mealbounce'] : "";
- $refund = isset($_GET['refund']) ? $_GET['refund'] : "";
- $moresearch = isset($_GET['moresearch']) ? $_GET['moresearch'] : '';
- $export = isset($_GET['export']) ? $_GET['export'] : '';
- $currentpage = isset($_GET['currentpage']) ? (empty($_GET['currentpage']) ? 1 : $_GET['currentpage']) : 1;
- $pagesize = isset($_GET['pagesize']) ? (empty($_GET['pagesize']) ? 10000 : $_GET['pagesize']) : 10000;
-
- //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'] : '';
-
- $pdo = conn();
- $pdo2 = conn();
- $sql = "CALL XM_ORDER_GET_LIST(1,'" . $timelimit . "','" . $starttime . "','" . $endtime . "'," . $ordersource . "," . $orderstatus . "," . $paystatus . ",'" . $billingstatus . "','" . $mealbounce . "','" . $refund . "','" . $moresearch . "','" . $export . "'," . $currentpage . "," . $pagesize . ",'" . $line . "','" . $start_area . "','" . $end_area . "')";
- // writeLog('order_list.php -- sql== '.$sql);
- $result = $pdo -> query($sql);
-
- $data = array();
- do {
- $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
- // if ($rowset) {
- $data[] = $rowset;
- // }
- } while ($result->nextRowset());
-
- $line_code_array = array();
- foreach ($data[1] as $data_info) {
- if (!in_array($data_info["line_code"], $line_code_array)) {
- $line_code_array[] = $data_info["line_code"];
- }
- }
- $sqlLine = " SELECT * FROM opera_product WHERE PROD_ID IN(" . implode(",", $line_code_array) . ") ";
- $result = $pdo2 -> query($sqlLine);
- $linedata_array = $result -> fetchAll();
- $linedata_array2 = array();
- foreach ($linedata_array as $line_info) {
- $linedata_array2[$line_info["PROD_ID"]] = $line_info["PROD_NAME"];
- }
- $msg_pdo = conn();
- $count = count($data);
- //获取门票价格和酒店价格
- $data2 = array();
- $order_id_array = array();
- foreach ($data[1] as $k => $v) {
- $data2[$v['parent_orderNo']][] = $v['travel_time'];
- if (!in_array($v['parent_orderNo'], $order_id_array)) {
- $order_id_array[] = $v['parent_orderNo'];
- }
- }
- $pdo_search_extra = conn();
- $search_extra_sql = " SELECT * FROM order_extra_info WHERE order_id IN (" . implode(",", $order_id_array) . ") ";
- //echo $search_extra_sql;exit();
- $result_search = $pdo_search_extra -> query($search_extra_sql);
- $order_extra_array = $result_search -> fetchAll();
-
- $order_extra_array2 = array();
- $order_id_extra = array();
- foreach ($order_extra_array as $temp) {
- $order_extra_array2[$temp['order_id'] . ""] = $temp;
- $order_id_extra[] = $temp['order_id'];
- }
- // 提交将订单备注里面的值取出来
- $remark_byorder_id = array();
- //echo json_encode($data[1]);exit();
- for ($i = 0; $i < count($data[1]); $i++) {
- $dict = $data[1][$i];
- $temp_order_id=$dict['parent_orderNo'];
- if ($dict['remark']=="") {
- continue;
- }
- $temp_remark = $dict['remark'];
- // 解决历史遗留问题
- // $temp_remark=str_replace(' ', '*', $temp_remark);
- // $temp_remark=str_replace(',', '*', $temp_remark);
- // $temp_remark=str_replace(',', '*', $temp_remark);
- // $temp_remark=str_replace('|', '/', $temp_remark);
- if (strpos($temp_remark, '/') > 0) {
- $temp = $temp_remark;
- // $temp=str_replace(',', '+', $temp_remark);
- // $temp=str_replace(',', '+', $temp);
- // $temp=str_replace('|', '/', $temp);
- $customers = explode("/", $temp);
- } else if(strpos($temp_remark,'*')>0) {
- $temp = explode("/", $dict['remark'] . "/");
- unset($temp[1]);
- $customers = $temp;
- }else{
- $temp_str=$dict['contacts']."*".$dict['idNo']."/";
- $temp = explode("/", $temp_str);
- unset($temp[1]);
- $customers = $temp;
- }
- $new_arr_cus = array();
- for ($j = 0; $j < count($customers); $j++) {
- $cus = explode("*", $customers[$j]);
- $cus_one = array('name' => isset($cus[0]) ? $cus[0] : "", 'carid' => isset($cus[1]) ? $cus[1] : "");
- $new_arr_cus[] = $cus_one;
- }
-
- $pos = strpos($dict['seat'], '×');
- $people_count = substr($dict['seat'], $pos + 2);
- // print_r($new_arr_cus);exit();
- if($people_count-1==count($new_arr_cus)){
- $temp_cus[]=array('name'=>isset($dict['contacts'])?$dict['contacts']:"-",'carid'=>isset($dict['idNo'])?$dict['idNo']:"-");
- $new_arr_cus=array_merge($temp_cus,$new_arr_cus);
- }
- // 保存订单人的键
- $temp_k="";
- foreach($new_arr_cus as $k=>$cus){
- if($cus['name']==$dict['contacts']){
- $temp_k=$k;
- }
- }
- if($temp_k!=""){
- // 将订单人的键放在第一位
- $temp_1=$new_arr_cus[0];
- $new_arr_cus[0]=$new_arr_cus[$temp_k];
- $new_arr_cus[$temp_k]=$temp_1;
- }
-
- // print_r($new_arr_cus);
-
- $new_arr=arr_unique2D($new_arr_cus);
- $remark_byorder_id[$dict['parent_orderNo']] = $new_arr;
- $remark_byorder_id = isset($remark_byorder_id) ? $remark_byorder_id : array();
- }
- //$new_arr = arr_unique2D($remark_byorder_id);
- //array_unique($remark_byorder_id);
- //print_r($remark_byorder_id);
- //exit();
- $str = "线路名称,车号,车牌号码,司机姓名,司机手机,上车站点,下车站点,发班日期,产品名称,座位等级,出行人数,分销价,GMV,门票价格,酒店价格,游客姓名,联系方式,身份证号,渠道,渠道订单号,订单号,状态" . "\n";
-
- for ($i = 0; $i < count($data[1]); $i++) {
- $dict = $data[1][$i];
- $temp_order_id=$dict['parent_orderNo'];
-
- $driver_info = getDriverInfo($dict['parent_orderNo']);
- $send_bus_no = $driver_info["bus_no"] . "\t";
- ;
- $send_driver_name = $driver_info["driver_name"] . "\t";
- ;
- $send_driver_mobile = $driver_info["driver_mobile"] . "\t";
- ;
- $dict['line'] = isset($linedata_array2[$dict['line_code']]) ? $linedata_array2[$dict['line_code']] : "";
- $line_name = $dict['line'] . "\t";
- $start_station = $dict['start_station'] . "\t";
- $end_station = $dict['end_station'] . "\t";
- $start_date = substr($dict['travel_time'], 0, 10) . "\t";
- $prod_name=$dict['prod_name']."\t";
- $pos = strpos($dict['seat'], '×');
- $seat_level = substr($dict['seat'], 0, $pos) . "\t";
-
- $people_count = substr($dict['seat'], $pos + 2) . "\t";
- $f_price = $dict['total_price'] / substr($dict['seat'], $pos + 2) . "\t";
- $GMV = isset($dict['total_price']) ? $dict['total_price'] : "" . "\t";
- $cus_name = $dict['contacts'] . "\t";
- $cus_mobile = $dict['tel'] . "\t";
- $cus_carid = $dict['idNo'] . "\t";
- $order_remark = $dict['remark'];
-
- //订单备注
- $org_name = $dict['org_name'] . "\t";
- $org_order_id = $dict['outside_order_no']==""?"-":$dict['outside_order_no']."\t";
- $order_id = $dict['parent_orderNo'] . "\t";
- $bus_no = isset($dict['bus_order_id']) ? $dict['bus_order_id'] . "\t" : "";
- //门票价格和酒店价格
- $door_price = "-";
- $hotel_price = "-";
- if (in_array($dict['parent_orderNo'], $order_id_extra)) {
- $door_price = $order_extra_array2[$dict['parent_orderNo']]['gate_price'];
- $hotel_price = $order_extra_array2[$dict['parent_orderNo']]['hotel_price'];
- }
-
- $or_status = $dict['order_status'];
- $or_status_str = '';
- if ($or_status == "145") {
- $or_status_str = "待支付" . "\t";
- } else if ($or_status == "146") {
- $or_status_str = "已出票" . "\t";
- } else if ($or_status == "147") {
- $or_status_str = "已完成" . "\t";
- } else if ($or_status == "148") {
- $or_status_str = "已取消" . "\t";
- } else {
- $or_status_str = "未知" . "\t";
- }
-
- // $str .= $line_name . "," . $send_bus_no . "," . $send_driver_name . "," . $send_driver_mobile . "," . $start_station . "," . $end_station . "," . $start_date . "," . $seat_level . "," . $people_count . "," . $f_price . "," . $GMV . "," . $door_price . "," . $hotel_price . "," . $cus_name . "," . $cus_mobile . "," . $cus_carid . "," . $org_name . "," . $org_order_id . "," . $order_id . "," . $or_status_str ."\n";
- $cstr1 = "";
- $cstr2 = "";
- $cstr3 = "";
- $count_remark = 0;
- // 统计备注里面的人数
- $bool_zhizhu = false;
- // 是否是蜘蛛业务人员录入
- // 备注不填
- if ($order_remark == '') {
- if ($count_remark < (int)substr($dict['seat'], $pos + 2)) {
- for ($k = $count_remark; $k < (int)substr($dict['seat'], $pos + 2); $k++) {
- if ($k == 0) {
- $str .= $line_name . "," . $bus_no . "," . $send_bus_no . "," . $send_driver_name . "," . $send_driver_mobile . "," . $start_station . "," . $end_station . "," . $start_date . ",".$prod_name."," . $seat_level . "," . $people_count . "," . $f_price . "," . $GMV . "," . $door_price . "," . $hotel_price . "," . $cus_name . "," . $cus_mobile . "," . $cus_carid . "," . $org_name . "," . $org_order_id . "," . $order_id . "," . $or_status_str . "\n";
- } else {
- $cus_name = "-";
- $cus_carid = "-";
- $str .= $line_name . "," . $bus_no . "," . $send_bus_no . "," . $send_driver_name . "," . $send_driver_mobile . "," . $start_station . "," . $end_station . "," . $start_date . ",".$prod_name."," . $seat_level . "," . $people_count . "," . $f_price . "," . $GMV . "," . $door_price . "," . $hotel_price . "," . $cus_name . "," . $cus_mobile . "," . $cus_carid . "," . $org_name . "," . $org_order_id . "," . $order_id . "," . $or_status_str . "\n";
- }
- }
- }
- // $str.=$line_name . ",".$bus_no."," . $send_bus_no . "," . $send_driver_name . "," . $send_driver_mobile . "," . $start_station . "," . $end_station . "," . $start_date . "," . $seat_level . "," . $people_count . "," . $f_price . "," . $GMV . "," . $door_price . "," . $hotel_price . "," . $cus_name . "," . $cus_mobile . "," . $cus_carid . "," . $org_name . "," . $org_order_id . "," . $order_id . "," . $or_status_str ."\n";
- }
- // 拿到该订单下的备注
- if (isset($remark_byorder_id[$dict['parent_orderNo']]) && count($remark_byorder_id[$dict['parent_orderNo']]) > 0) {
- $remark1 = $remark_byorder_id[$dict['parent_orderNo']];
- // if (!array_key_exists($dict['contacts'], $remark1)) {
- // $str .= $line_name . "," . $bus_no . "," . $send_bus_no . "," . $send_driver_name . "," . $send_driver_mobile . "," . $start_station . "," . $end_station . "," . $start_date . "," . $seat_level . "," . $people_count . "," . $f_price . "," . $GMV . "," . $door_price . "," . $hotel_price . "," . $cus_name . "," . $cus_mobile . "," . $cus_carid . "," . $org_name . "," . $org_order_id . "," . $order_id . "," . $or_status_str . "\n";
- // $bool_zhizhu = true;
- // }
- foreach ($remark1 as $temp) {
- // 张三,手机号 remark= 张三*身份证号/李四*身份证号
- if ($temp['name'] == $dict['contacts']) {
- $cus_carid = $temp['carid'] . "\t";
- $cus_name = $temp['name'] . "\t";
- $cstr1 .= $line_name . "," . $bus_no . "," . $send_bus_no . "," . $send_driver_name . "," . $send_driver_mobile . "," . $start_station . "," . $end_station . "," . $start_date . ",".$prod_name."," . $seat_level . "," . $people_count . "," . $f_price . "," . $GMV . "," . $door_price . "," . $hotel_price . "," . $cus_name . "," . $cus_mobile . "," . $cus_carid . "," . $org_name . "," . $org_order_id . "," . $order_id . "," . $or_status_str . "\n";
- $count_remark++;
- } else {
- // 身份证号码相同,即备注中有了订单人的信息
- if ($temp['carid'] == $dict['idNo']) {continue;}
- $cus_name = isset($temp['name']) ? $temp['name'] ."\t": "-";
- $cus_carid = isset($temp['carid']) ? $temp['carid'] ."\t": "";
- // $str .= $line_name . "," . $send_bus_no . "," . $send_driver_name . "," . $send_driver_mobile . "," . $start_station . "," . $end_station . "," . $start_date . "," . $seat_level . "," . $people_count . "," . $f_price . "," . $GMV . "," . $door_price . "," . $hotel_price . "," . $cus_name . "," . $cus_mobile . "," . $cus_carid . "," . $org_name . "," . $org_order_id . "," . $order_id . "," . $or_status_str ."\n";
- $cstr2 .= $line_name . "," . $bus_no . "," . $send_bus_no . "," . $send_driver_name . "," . $send_driver_mobile . "," . $start_station . "," . $end_station . "," . $start_date . ",".$prod_name."," . $seat_level . "," . $people_count . "," . $f_price . "," . $GMV . "," . $door_price . "," . $hotel_price . "," . $cus_name . "," . $cus_mobile . "," . $cus_carid . "," . $org_name . "," . $org_order_id . "," . $order_id . "," . $or_status_str . "\n";
- $count_remark++;
- }
- }
- $pe_count = (int)substr($dict['seat'], $pos + 2);
- if ($bool_zhizhu == true) {
- $pe_count--;
- }
- //判断备注信息有可能不是添加的乘客姓名+身份证号而是其它的内容
- if ($count_remark < $pe_count) {
- for ($k = $count_remark; $k < $pe_count; $k++) {
- if ($k == 0) {
- $cstr3 .= $line_name . "," . $bus_no . "," . $send_bus_no . "," . $send_driver_name . "," . $send_driver_mobile . "," . $start_station . "," . $end_station . "," . $start_date . ",".$prod_name."," . $seat_level . "," . $people_count . "," . $f_price . "," . $GMV . "," . $door_price . "," . $hotel_price . "," . $cus_name . "," . $cus_mobile . "," . $cus_carid . "," . $org_name . "," . $org_order_id . "," . $order_id . "," . $or_status_str . "\n";
- } else {
- $cus_name = "-";
- $cus_carid = "-";
- $cstr3 .= $line_name . "," . $bus_no . "," . $send_bus_no . "," . $send_driver_name . "," . $send_driver_mobile . "," . $start_station . "," . $end_station . "," . $start_date . ",".$prod_name."," . $seat_level . "," . $people_count . "," . $f_price . "," . $GMV . "," . $door_price . "," . $hotel_price . "," . $cus_name . "," . $cus_mobile . "," . $cus_carid . "," . $org_name . "," . $org_order_id . "," . $order_id . "," . $or_status_str . "\n";
- }
- }
- }
-
- // echo $count_remark;
- // echo (int)substr($dict['seat'], $pos + 2);
- // echo "</br>";
-
- $str .= $cstr1;
- $str .= $cstr2;
- $str .= $cstr3;
- }
- }
- $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);
- echo $data;
- }
-
- function getDriverInfo($ORDER_ID) {
- $msg_pdo = conn();
- $msg_sql = "CALL SP_GET_MESSAGE_TEMPLATE('" . $ORDER_ID . "')";
- $content = '';
- if (is_object($msg_pdo)) {
- $msg_result = $msg_pdo -> query($msg_sql);
- $i = 1;
- $data = array();
- if ($msg_result) {
- $data['code'] = "0";
- $data['info'] = "";
- do {
- $row = $msg_result -> fetchAll(PDO::FETCH_ASSOC);
- if ($i == 1) {
- $data['seat'] = isset($row) ? $row : array();
- } else if ($i == 2) {
- $data['run_info'] = isset($row) ? $row : array();
- } else if ($i == 3) {
- $data['driver'] = isset($row) ? $row : array();
- } else {
- }
- $i++;
- } while($msg_result->nextRowset());
- }
- $json_obj = json_decode(json_encode($data), TRUE);
- $seat = isset($json_obj['seat'][0]) ? $json_obj['seat'][0] : array();
- $run_info = isset($json_obj['run_info'][0]) ? $json_obj['run_info'][0] : array();
- $driver = isset($json_obj['driver'][0]) ? $json_obj['driver'][0] : array();
- if ($driver) {
- return $driver;
- $bus_no = isset($driver['bus_no']) ? $driver['bus_no'] : "";
- $driver_name = isset($driver['driver_name']) ? $driver['driver_name'] : "";
- $driver_mobile = isset($driver['driver_mobile']) ? $driver['driver_mobile'] : "";
- } else {
- return array("bus_no" => "", "driver_name" => "", "driver_mobile" => "");
- }
- }
- }
-
- // 二维数组
- function arr_unique2D($data = array()) {
- $tmp = array();
- foreach ($data as $key => $value) {
- //把一维数组键值与键名组合
- foreach ($value as $key1 => $value1) {
- $value[$key1] = $key1 . '_|_' . $value1;
- //_|_分隔符复杂点以免冲突
- }
- $tmp[$key] = implode(',|,', $value);
- //,|,分隔符复杂点以免冲突
- }
-
- //对降维后的数组去重复处理
- $tmp = array_unique($tmp);
-
- //重组二维数组
- $newArr = array();
- foreach ($tmp as $k => $tmp_v) {
- $tmp_v2 = explode(',|,', $tmp_v);
- foreach ($tmp_v2 as $k2 => $v2) {
- $v2 = explode('_|_', $v2);
- $tmp_v3[$v2[0]] = $v2[1];
- }
- $newArr[$k] = $tmp_v3;
- }
- return $newArr;
- }
-
- exit();
|