|
- <?php
-
- /*
- Author:fuhc
- Compeny:Spiders Travel
- */
- require_once '../../Common/Mysql.php';
- if (ALLOW_ORIGIN)
- header("Access-Control-Allow-Origin:*");
-
-
- $condition = array();
- $timelimit = isset($_GET['timelimit']) ? $_GET['timelimit'] : '';
- $starttime = isset($_GET['starttime']) ? $_GET['starttime'] : '';
- $endtime = isset($_GET['endtime']) ? $_GET['endtime'] : '';
- $ordersource = isset($_GET['ordersource']) ? $_GET['ordersource'] : 0;
- $typelimit = isset($_GET['typelimit']) ? $_GET['typelimit'] : '';
- $moresearch = isset($_GET['moresearch']) ? trim($_GET['moresearch']) : '';
- $orderstatus = isset($_GET['orderstatus']) ? $_GET['orderstatus'] : 0;
-
- if ($orderstatus) {
- $condition[] = " a.order_status =" . $orderstatus;
- }
- if ($timelimit == 0) {
- empty($starttime) ? null : $condition[] = ' a.create_time >= "' . $starttime . ' 00:00:00' . '"'; //创建时间条件筛选
- empty($endtime) ? null : $condition[] = ' a.create_time <= "' . $endtime . ' 23:59:01' . '"';
- } elseif ($timelimit == 1) {
- empty($starttime) ? null : $condition[] = ' a.run_date >= "' . $starttime . '"'; // 出发时间筛选
- empty($endtime) ? null : $condition[] = ' a.run_date <= "' . $endtime . ' 23:59:01' . '"';
- }
- if ($ordersource == '-1') {
-
- } else {
- empty($ordersource) ? null : $condition[] = ' a.outside_sale_org_id = ' . $ordersource;
- }
-
- if ($typelimit == 1) {
- $condition[] = ' a.order_prod_type in (258,259,282,311)';
- } else {
- empty($typelimit) ? $condition[] = ' a.order_prod_type in (258,259)' : $condition[] = ' a.order_prod_type= ' . $typelimit;
- }
- empty($moresearch) ? $condition2 = 1 : $condition2 = ' a.order_id like "%' . $moresearch . '%" or a.customer_name like "%' . $moresearch . '%" or a.customer_mobile like "%' . $moresearch . '%" or a.outside_order_no like "%' . $moresearch . '%"';
- $condition = implode(' AND ', $condition);
-
- //状态筛选环境
- $condition1 = array();
- if ($timelimit == 0) {
- empty($starttime) ? null : $condition1[] = ' a.create_time >= "' . $starttime . ' 00:00:00' . '"'; //创建时间条件筛选
- empty($endtime) ? null : $condition1[] = ' a.create_time <= "' . $endtime . ' 23:59:01' . '"';
- } elseif ($timelimit == 1) {
- empty($starttime) ? null : $condition1[] = ' a.run_date >= "' . $starttime . '"'; // 出发时间筛选
- empty($endtime) ? null : $condition1[] = ' a.run_date <= "' . $endtime . ' 23:59:01' . '"';
- }
- if ($ordersource == '-1') {
-
- } else {
- empty($ordersource) ? null : $condition1[] = ' a.org_id = ' . $ordersource;
- }
-
- if ($typelimit == 1) {
- $condition1[] = ' a.order_prod_type in (258,259,282,311)';
- } else {
- empty($typelimit) ? $condition1[] = ' a.order_prod_type in (258,259)' : $condition1[] = ' a.order_prod_type= ' . $typelimit;
- }
- $condition1 = implode(' AND ', $condition1);
- //结束
- $orderstatus = isset($_POST['orderstatus']) ? (empty($_POST['orderstatus']) ? 0 : $_POST['orderstatus']) : 0;
- $paystatus = isset($_POST['paystatus']) ? (empty($_POST['paystatus']) ? -1 : $_POST['paystatus']) : -1;
- $billingstatus = isset($_POST['billingstatus']) ? $_POST['billingstatus'] : '';
- $mealbounce = isset($_POST['mealbounce']) ? $_POST['mealbounce'] : '';
- $refund = isset($_POST['refund']) ? $_POST['refund'] : '';
-
- $export = isset($_POST['export']) ? $_POST['export'] : '';
-
- //2016-07-15新增
- $start_area = isset($_POST['start_area']) ? $_POST['start_area'] : '';
- $end_area = isset($_POST['end_area']) ? $_POST['end_area'] : '';
- $line = isset($_POST['line']) ? $_POST['line'] : '';
- //..暂未加入存储过程
-
- $currpage = 1;
- $pagesize = 100000;
- $pdo = conn();
- if ($condition2 != 1) {
- $condition2 = " where " . $condition2." AND ".$condition1;
- } else {
- $condition2 = " where ".$condition1;
- }
- $sql = "select a.order_id "
- . "from order_main as a "
- . $condition2;
- //echo $sql;die;
- $result = $pdo->query($sql);
- $json22 = array();
- do {
- $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
- if ($rowset) {
- $json22 = $rowset;
- }
- } while ($result->nextRowset());
-
- if (empty($json22)) {
- die;
- }
- foreach ($json22 as $v) {
- $arr_o[] = $v['order_id'];
- }
- $arr_o = implode(',', $arr_o);
-
- $sql_org = "select org_id,org_name from base_organization ";
- $result_org = $pdo->query($sql_org);
- $org_list = $result_org->fetchAll(PDO::FETCH_ASSOC);
- $o_list = array();
- foreach ($org_list as $v) {
- $o_list[$v['org_id']] = array('org_name' => $v['org_name'], 'org_id' => $v['org_id']);
- }
- $sql = "select a.prod_name,a.order_prod_type,a.order_description,a.run_date,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,a.customer_memo,a.main_create_user_id,a.outside_sale_org_id,a.outside_order_no "
- . "from order_main as a "
- . "where a.PARENT_ORDER_ID=0 and a.CANCEL_FLAG=0 and a.order_id in (" . $arr_o . ") AND " . $condition. " order by a.create_time desc";
- $result = $pdo->query($sql);
- if( false != $result ) {
- $json = array();
- $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
- if ($rowset) {
- $json = $rowset;
- }
- $result->closeCursor();
- }
- if (empty($json)) {
- die;
- }
- //获取销售渠道信息
- $json_id = array();
- foreach ($json as $v) {
- $json_id[] = $v['order_id'];
- $json2[] = $v['order_id'];
- $org[$v['order_id']] = $v['main_create_user_id'];
- if ( $v['outside_sale_org_id'] == 0 || !isset($o_list[$v['outside_sale_org_id']])) {
- $v['org_name'] = 'CS平台下单';
- } else {
- $v['org_name'] = $o_list[$v['outside_sale_org_id']]["org_name"];
- }
- $org_name[$v['order_id']] = $v['org_name'];
- $outside_order_no[$v['order_id']] = $v['outside_order_no'];
- $order_info[$v['order_id']] = $v; //价格手机 姓名 run_time pay_time
- }
-
- $array_order_desc = array();
- foreach ($order_info as $v) {
- $arr_temp = explode('|', $v['order_description']);
- $arr = array();
- foreach ($arr_temp as $k => $v2) {
- if (!empty($v2))
- $arr[] = explode(',', $v2);
- }
- $array_order_desc[$v['order_id']] = $arr;
- }
-
- //var_dump($array_order_desc);die;
- $sql3 = "select parent_order_id,run_date,run_time,PROD_START_STATION_AREA_NAME,PROD_START_STATION_RES_NAME,PROD_END_STATION_AREA_NAME,PROD_END_STATION_RES_NAME "
- . "from order_main "
- . "where parent_order_id in (" . implode(",", $json_id) . ")";
- $result3 = $pdo->query($sql3);
- $rowset3 = $result3->fetchAll(PDO::FETCH_ASSOC);
- foreach ($rowset3 as $v) {
- $station[$v['parent_order_id']] = $v;//上车站下车站 详情
- }
- //获取支付方式
- $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)
- left join dict_type c on c.id=b.PAY_TYPE_ID_1 "
- . " where a.ORDER_ID in (" . implode(",", $json_id) . ")";
- $result2 = $pdo->query($sql2);
- do {
- $rowset2 = $result2->fetchAll(PDO::FETCH_ASSOC);
- if ($rowset2) {
- $pay_type[] = $rowset2;
- }
- } while ($result2->nextRowset());
- foreach ($pay_type[0] as $v) {
- $pay_type_arr[$v['ORDER_ID']] = $v['TYPE_NAME']; //支付方式
- }
- //支付状态
- $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)
- left join dict_type c on c.id=a.ORDER_STATUS "
- . " where a.ORDER_ID in (" . implode(",", $json_id) . ")";
- $result4 = $pdo->query($sql4);
- do {
- $rowset4 = $result4->fetchAll(PDO::FETCH_ASSOC);
- if ($rowset4) {
- $order_sta[] = $rowset4;
- }
- } while ($result4->nextRowset());
- foreach ($order_sta[0] as $v) {
- $order_status[$v['ORDER_ID']] = $v['TYPE_NAME']; //订单的状态
- }
- $array_order_list = array();
- //echo count($pay_type_arr),'--', count($json_id);
- //var_dump($array_order_desc);die;
- foreach ($json_id as $v) {
- $tic = '';
-
- if ($order_info[$v]['order_prod_type'] == 258 || $order_info[$v]['order_prod_type'] == 259) {
- foreach ($array_order_desc[$v] as $v1) {
- $tic .= str_replace('迪士尼剧场', '', $v1[0]) . '×' . $v1[2] . ' ';
- if (isset($v1['ifback']))
- $ifback = $v1['ifback'];
- }
- $product_info = $order_info[$v]['prod_name'] . "\r\n" . $tic;
- $ifdisn = 0;
- } elseif ($order_info[$v]['order_prod_type'] == 282) {
- foreach ($array_order_desc[$v] as $v1) {
- if( !isset($v1[0]) || !isset($v1[2]) || strlen($v1[2]) <= 0 ) { break;}
- $tic .= str_replace('周庄门票', '', $v1[0]) . '×' . $v1[2] . ' ';
- if (isset($v1['ifback']))
- $ifback = $v1['ifback'];
- }
- $product_info = $order_info[$v]['prod_name'] . '' . $tic;
-
- if ($order_info[$v]['run_date'] <= date('Y-m-d', time()) || $order_info[$v]['order_status'] != 146) {
- $ifdisn = 0;
- } else {
- $ifdisn = 1;
- }
-
- } else {
- foreach ($array_order_desc[$v] as $v1) {
- $tic .= $v1[0] . '×' . $v1[2] . ' ';
- if (isset($v1['ifback']))
- $ifback = $v1['ifback'];
- }
- $product_info = $order_info[$v]['prod_name'] . '' . $tic;
-
- if ($order_info[$v]['run_date'] <= date('Y-m-d', time()) || $order_info[$v]['order_status'] != 146) {
- $ifdisn = 0;
- } else {
- $ifdisn = 1;
- }
- }
- $array_order_list[] = array(
- 'order_id' => $v,
- 'create_time' => $order_info[$v]['create_time'],
-
- 'org_name' => $org_name[$v],
- 'product_info' => $product_info,
- 'outside_order_no' => $outside_order_no[$v],
- 'ifdisney' => $ifdisn,
- 'ifzhouzhuang' => $ifdisn,
- 'run_time' => $station[$v]['run_date'] . ' ' . $station[$v]['run_time'],
- 'customer_info' => $order_info[$v]['customer_name'] . "\r\n" . $order_info[$v]['customer_mobile'] . "\r\n" . $order_info[$v]['customer_id_no'],
- 'order_pay' => $order_info[$v]['order_price'],
- 'customer_memo' => $order_info[$v]['customer_memo'],
- 'order_pay_type' => $pay_type_arr[$v],
- 'order_status' => $order_status[$v],
-
- );
- }
-
-
- $str = "订单编号,预订时间,订单渠道,预订产品,支付金额,出发时间, 联系人,状态,支付方式,备注" . "\n";
- foreach( $array_order_list as $order_info_temp) {
- $str .= "{$order_info_temp["order_id"]},{$order_info_temp["create_time"]},\"{$order_info_temp["org_name"]}\",\"{$order_info_temp["product_info"]}\",\"{$order_info_temp["order_pay"]}\",\"{$order_info_temp["run_time"]}\",\"{$order_info_temp["customer_info"]}\",\"{$order_info_temp["order_status"]}\",\"{$order_info_temp["order_pay_type"]}\",\"{$order_info_temp["customer_memo"]}\"" . "\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;
- }
-
|