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.
 
 
 
 

240 lines
11 KiB

  1. <?php
  2. /*
  3. Author:fuhc
  4. Compeny:导出次日上车乘客信息 将备注转为一条数据添加进去
  5. */
  6. require_once '../Common/Mysql.php';
  7. require_once '../Common/order_common.php';
  8. if (ALLOW_ORIGIN)
  9. header("Access-Control-Allow-Origin:*");
  10. set_time_limit(1200);
  11. $method = isset($_GET['method']) ? $_GET['method'] : "";
  12. $user_id = getUserId();
  13. $not_cancel_mode = isset($_GET['nocancel']) ? $_GET['nocancel'] : 0;
  14. $timelimit = isset($_GET['timelimit']) ? $_GET['timelimit'] : '出发时间';
  15. $starttime = isset($_GET['starttime']) ? $_GET['starttime'] : date("Y-m-d");
  16. $endtime = isset($_GET['endtime']) ? $_GET['endtime'] : date("Y-m-d");
  17. //$starttime = "2016-08-04";
  18. //$endtime = "2016-08-04";
  19. $ordersource = isset($_GET['ordersource']) ? (empty($_GET['ordersource']) ? -1 : $_GET['ordersource']) : -1;
  20. $orderstatus = isset($_GET['orderstatus']) ? (empty($_GET['orderstatus']) ? 0 : $_GET['orderstatus']) : 0;
  21. $moresearch = isset($_GET['moresearch']) ? $_GET['moresearch'] : '';
  22. //2016-07-15新增
  23. $start_area = isset($_GET['start_area']) ? $_GET['start_area'] : '';
  24. $end_area = isset($_GET['end_area']) ? $_GET['end_area'] : '';
  25. $line = isset($_GET['line']) ? $_GET['line'] : '';
  26. $run_time = isset($_GET['run_time'])?$_GET['run_time']:'';
  27. $search_bus_no = isset($_GET['search_bus_no'])?$_GET['search_bus_no']:'';
  28. $cusmo = isset($_GET['cusmo'])?$_GET['cusmo']:0;
  29. //2016-10-19新增
  30. $bus_type_param = isset($_GET['bus_type'])?$_GET['bus_type']:"0";
  31. $_GET["main_corp_id"] = isset($_COOKIE["user_main_corp"]) ? $_COOKIE["user_main_corp"] : 0;
  32. //2018/2/8
  33. //运营负责人
  34. $run_duty=isset($_GET['run_duty']) ? $_GET['run_duty'] : '-1';
  35. $pdo = conn();
  36. $pdo2 = conn();
  37. $pdo3 = conn();
  38. //分销往返票的统计
  39. $sql_both = " SELECT to_orderid,back_orderid FROM to_from WHERE CREATE_TIME >= '{$starttime} 00:00:00' AND CREATE_TIME <= '{$endtime} 23:59:59' ";
  40. $bothway_order_array = array();
  41. $result2 = $pdo2->query($sql_both);
  42. if( $result2 ) {
  43. $to_from_array =$result2->fetchAll();
  44. $result2->closeCursor();
  45. if( false != $to_from_array && count($to_from_array) > 0 ) {
  46. foreach( $to_from_array as $to_from_info ) {
  47. $bothway_order_array[] = $to_from_info["to_orderid"];
  48. $bothway_order_array[] = $to_from_info["back_orderid"];
  49. }
  50. }
  51. }
  52. $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 ";
  53. $result3 = $pdo3->query($sql_search_bus);
  54. $bus_array =$result3->fetchAll();
  55. $all_bus_array = array();
  56. foreach( $bus_array as $bus_info ) {
  57. $all_bus_array[$bus_info["bus_id"]] = $bus_info;
  58. }
  59. $result3->closeCursor();
  60. $all_supplier_array = get_memcache("ARY_ALL_SUPPLIER");
  61. if( false == $all_supplier_array || is_array($all_supplier_array) == false || count($all_supplier_array) <= 0 ) {
  62. $pdo4=conn();
  63. $sql = " SELECT id,main_corp_id,supplier_type,supplier_name FROM base_supplier WHERE cancel_flag = 0 ";
  64. $result=$pdo->query($sql);
  65. $search_result = $result->fetchAll(PDO::FETCH_ASSOC);
  66. $all_supplier_array = array();
  67. foreach( $search_result as $result_info ) {
  68. $all_supplier_array[$result_info["id"]] = $result_info;
  69. }
  70. $result->closeCursor();
  71. }
  72. $all_user_array = get_memcache("ARY_ALL_CSUSER");
  73. if( false == $all_user_array || is_array($all_user_array) == false || count($all_user_array) <= 0 ) {
  74. $pdo5=conn();
  75. $sql = " SELECT id,user_name,true_name FROM base_user WHERE id > 0 ";
  76. $result=$pdo5->query($sql);
  77. $search_result = $result->fetchAll(PDO::FETCH_ASSOC);
  78. $all_user_array = array();
  79. foreach( $search_result as $result_info ) {
  80. $all_user_array[$result_info["id"]] = $result_info;
  81. }
  82. $result->closeCursor();
  83. }
  84. $order_list = get_export_order_list( $pdo, $_GET );
  85. if( $order_list == false ) {
  86. $data['code']="400";
  87. $data['info']="没有符合检索条件的数据";
  88. echo json_encode($data);exit();
  89. }
  90. $data = $order_list;
  91. if( $cusmo == 1 ) {
  92. $str = "线路名称,上车站点,下车站点,预定日期,发班日期,发班时间,发车时间,订单号,渠道,出行人数,GMV,序号,游客姓名,身份证号,联系方式,是否购买保险,运营负责人" . "\n";
  93. } else {
  94. $str = "线路名称,线路类型,车号,车队名,车牌号码,司机姓名,司机手机,出发地,上车站点,目的地,下车站点,预订日期,发班日期,发班时间,发车时间,座位等级,出行人数,座位号,分销价,GMV,用车成本,渠道佣金,游客姓名,联系方式,身份证号,出行人,下单人,渠道,渠道订单号,销售终端,销售终端号,订单号,状态,支付方式,是否组合订单,备注,上门接地址,运营负责人" . "\n";
  95. }
  96. $disp_pay_type = array("221" => "授信支付", "232" => "天猫旗舰店支付", "275" => "授信支付", "278" => "微信支付");
  97. $disp_order_status = array( "145" => "待支付", "146" => "已出票", "147" => "已完成", "148" => "已取消" );
  98. for ($i = 0; $i < count($data); $i++) {
  99. $dict = $data[$i];
  100. $dict['order_status'] = $disp_order_status[$dict['order_status']];
  101. if( $not_cancel_mode == 1 ) {
  102. if( $dict['order_status'] != "已出票" && $dict['order_status'] != "已完成" ) {
  103. continue;
  104. }
  105. }
  106. $send_bus_no = $dict["send_bus_no"] . "\t";
  107. $send_bus_res_id = $dict["send_bus_res_id"];
  108. if( isset($all_bus_array[$send_bus_res_id]) ) {
  109. $bus_info = $all_bus_array[$send_bus_res_id];
  110. $send_bus_company_name = $bus_info["supplier_name"] . "\t";
  111. } else {
  112. $send_bus_company_name = " \t";
  113. }
  114. $send_driver_name = $dict["send_driver_name"] . "\t";
  115. $disp_bus_type = array("255" => "直通巴士", "256" => "穿梭巴士","284" => "城际商务车");
  116. // $bus_type = isset($disp_bus_type[$dict["bus_type"]])?$disp_bus_type[$dict["bus_type"]]. "\t": "-";
  117. if($bus_type_param=="0"){
  118. $bus_type = isset($disp_bus_type[$dict["bus_type"]])?$disp_bus_type[$dict["bus_type"]]. "\t": "-";
  119. }else{
  120. if($bus_type_param!=$dict['bus_type']){
  121. continue;
  122. }
  123. $bus_type = isset($disp_bus_type[$bus_type_param])?$disp_bus_type[$bus_type_param]. "\t": "-";
  124. }
  125. $create_user_name = "";
  126. if( isset($all_user_array[$dict["create_user_id"]]) ) {
  127. $user_info = $all_user_array[$dict["create_user_id"]];
  128. $create_user_name = strlen($user_info["true_name"]) > 0 ? $user_info["true_name"] : $user_info["user_name"];
  129. }
  130. $send_driver_mobile = $dict["send_driver_mobile"] . "\t";
  131. $seat_list = isset($dict['seat_list']) ? str_replace(",","/",$dict['seat_list']) . "\t" : "";
  132. $line = $dict['line'] . "\t";
  133. $start_area = $dict['start_area'] . "\t";
  134. $start_station = $dict['start_station'] . "\t";
  135. $end_area = $dict['end_area'] . "\t";
  136. $end_station = $dict['end_station'] . "\t";
  137. $run_date = substr($dict['run_date'], 0, 10) . "\t";
  138. $bus_run_time = substr($dict['bus_run_time'], 0, 10) . "\t";
  139. $run_time = substr($dict['prod_start_station_time'], 0, 10) . "\t";
  140. $passenger_list = $dict['passenger_info'] . "\t";
  141. if( in_array( $dict['parent_orderNo'], $bothway_order_array ) && mb_strpos($dict['prod_name'], "往返") === false ) {
  142. $dict['prod_name'] .= "(往返)";
  143. }
  144. // $prod_name=$dict['line']."\t";
  145. $create_time=$dict['create_time']."\t";
  146. $seat=$dict['prod_name']."\t";
  147. $order_count = $dict['count'];
  148. $order_price=$dict['order_price'];
  149. $GMV = isset($dict['gmv']) ? $dict['gmv']: "-";
  150. $base_price = isset($dict['base_price']) ? $dict['base_price'] : "-";
  151. $total_commision = isset($dict['total_commission']) ? $dict['total_commission'] : "-";
  152. $customer_name = isset($dict['contacts'])?$dict['contacts']. "\t":"-" ;
  153. $customer_mobile = isset($dict['tel'])?$dict['tel']. "\t":"-" ;
  154. $customer_id_no = isset($dict['idNo'])?$dict['idNo']. "\t":"-";
  155. $order_remark = $dict['remark'];
  156. $order_address = $dict['customer_address'];
  157. $run_duty_name = isset($all_user_array[$dict['run_duty_id']]) ? $all_user_array[$dict['run_duty_id']]["true_name"] : '';
  158. if( isset($all_supplier_array[$dict["org_id"]]) ) {
  159. $dict["org_name"] = $all_supplier_array[$dict["org_id"]]["supplier_name"];
  160. } else {
  161. $dict["org_name"] = "";
  162. }
  163. if( isset($all_supplier_array[$dict["sub_channel_id"]]) ) {
  164. $dict["sub_channel_name"] = $all_supplier_array[$dict["sub_channel_id"]]["supplier_name"];
  165. } else {
  166. $dict["sub_channel_name"] = "";
  167. }
  168. $org_name = $dict['org_name'];
  169. $outside_order_no = $dict['outside_order_no']==""?"-":$dict['outside_order_no']. "\t";
  170. $sub_channel_name = $dict['sub_channel_name'];
  171. $sub_channel_no = $dict['sub_channel_no']==""?"-":$dict['sub_channel_no']. "\t";
  172. $parent_order_id = $dict['parent_orderNo'] . "\t";
  173. $bus_order_id = isset($dict['bus_order_id']) ? $dict['bus_order_id'] . "\t" : "-";
  174. $order_status=$dict['order_status'];
  175. $order_group_flag = $dict['order_title_id'] > 0 ? "是({$dict['order_title_id']})" : "否" ;
  176. $pay_type= isset($disp_pay_type[$dict['pay_type']]) ? $disp_pay_type[$dict['pay_type']] : "授信支付";
  177. $if_gift = $dict['if_gift'] == 1 ? "是" : "否";
  178. if( $cusmo == 1 ) {
  179. $passenger_index = 0;
  180. $passenger_array = array();
  181. if( strpos( $order_remark, "/" ) != false && strpos( $order_remark, "*" ) != false ) {
  182. $passenger_array = explode("/", $order_remark);
  183. }
  184. while( $passenger_index < $order_count ) {
  185. $passenger_name = $customer_name;
  186. $passenger_idno = $customer_id_no;
  187. if( isset($passenger_array[$passenger_index]) ) {
  188. $passenger_info_tmp = explode("*", $passenger_array[$passenger_index]);
  189. $passenger_name = isset($passenger_info_tmp[0]) ? $passenger_info_tmp[0] : $customer_name;
  190. $passenger_idno = isset($passenger_info_tmp[1]) ? $passenger_info_tmp[1]. "\t" : $customer_id_no;
  191. }
  192. $passenger_index ++;
  193. $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;
  194. $strline=str_replace(array("\n","\r"),array("",""),$strline);
  195. $str.= $strline."\n";
  196. }
  197. } else {
  198. $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;
  199. $strline=str_replace(array("\n","\r"),array("",""),$strline);
  200. $str.= $strline."\n";
  201. }
  202. }
  203. $filename = date('Ymd') . '.csv';
  204. //设置文件名
  205. //echo $str;
  206. export_csv($filename, $str);
  207. //导出
  208. function export_csv($filename, $data) {
  209. header("Content-type:text/csv");
  210. header("Content-Disposition:attachment;filename=订单明细" . $filename);
  211. header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
  212. header('Expires:0');
  213. header('Pragma:public');
  214. $data = chr(0xEF) . chr(0xBB) . chr(0xBF) . $data;
  215. // $data = iconv("utf-8","gb2312",$data);
  216. writeLog('export success');
  217. echo $data;
  218. }
  219. exit();