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.
 
 
 
 

368 lines
16 KiB

  1. <?php
  2. /*
  3. Author:fuhc
  4. Compeny:导出次日上车乘客信息 将备注转为一条数据添加进去
  5. */
  6. require_once '../Common/Mysql.php';
  7. if (ALLOW_ORIGIN)
  8. header("Access-Control-Allow-Origin:*");
  9. $method = isset($_GET['method']) ? $_GET['method'] : "";
  10. $timelimit = isset($_GET['timelimit']) ? $_GET['timelimit'] : '出发时间';
  11. $starttime = isset($_GET['starttime']) ? $_GET['starttime'] : date("Y-m-d");
  12. $endtime = isset($_GET['endtime']) ? $_GET['endtime'] : date("Y-m-d");
  13. //$starttime = "2016-08-04";
  14. //$endtime = "2016-08-04";
  15. $ordersource = isset($_GET['ordersource']) ? (empty($_GET['ordersource']) ? -1 : $_GET['ordersource']) : -1;
  16. $orderstatus = isset($_GET['orderstatus']) ? (empty($_GET['orderstatus']) ? 0 : $_GET['orderstatus']) : 0;
  17. $paystatus = isset($_GET['paystatus']) ? (empty($_GET['paystatus']) ? -1 : $_GET['paystatus']) : -1;
  18. $billingstatus = isset($_GET['billingstatus']) ? $_GET['billingstatus'] : "";
  19. $mealbounce = isset($_GET['mealbounce']) ? $_GET['mealbounce'] : "";
  20. $refund = isset($_GET['refund']) ? $_GET['refund'] : "";
  21. $moresearch = isset($_GET['moresearch']) ? $_GET['moresearch'] : '';
  22. $export = isset($_GET['export']) ? $_GET['export'] : '';
  23. $currentpage = isset($_GET['currentpage']) ? (empty($_GET['currentpage']) ? 1 : $_GET['currentpage']) : 1;
  24. $pagesize = isset($_GET['pagesize']) ? (empty($_GET['pagesize']) ? 10000 : $_GET['pagesize']) : 10000;
  25. //2016-07-15新增
  26. $start_area = isset($_GET['start_area']) ? $_GET['start_area'] : '';
  27. $end_area = isset($_GET['end_area']) ? $_GET['end_area'] : '';
  28. $line = isset($_GET['line']) ? $_GET['line'] : '';
  29. $pdo = conn();
  30. $pdo2 = conn();
  31. $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 . "')";
  32. // writeLog('order_list.php -- sql== '.$sql);
  33. $result = $pdo -> query($sql);
  34. $data = array();
  35. do {
  36. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  37. // if ($rowset) {
  38. $data[] = $rowset;
  39. // }
  40. } while ($result->nextRowset());
  41. $line_code_array = array();
  42. foreach ($data[1] as $data_info) {
  43. if (!in_array($data_info["line_code"], $line_code_array)) {
  44. $line_code_array[] = $data_info["line_code"];
  45. }
  46. }
  47. $sqlLine = " SELECT * FROM opera_product WHERE PROD_ID IN(" . implode(",", $line_code_array) . ") ";
  48. $result = $pdo2 -> query($sqlLine);
  49. $linedata_array = $result -> fetchAll();
  50. $linedata_array2 = array();
  51. foreach ($linedata_array as $line_info) {
  52. $linedata_array2[$line_info["PROD_ID"]] = $line_info["PROD_NAME"];
  53. }
  54. $msg_pdo = conn();
  55. $count = count($data);
  56. //获取门票价格和酒店价格
  57. $data2 = array();
  58. $order_id_array = array();
  59. foreach ($data[1] as $k => $v) {
  60. $data2[$v['parent_orderNo']][] = $v['travel_time'];
  61. if (!in_array($v['parent_orderNo'], $order_id_array)) {
  62. $order_id_array[] = $v['parent_orderNo'];
  63. }
  64. }
  65. $pdo_search_extra = conn();
  66. $search_extra_sql = " SELECT * FROM order_extra_info WHERE order_id IN (" . implode(",", $order_id_array) . ") ";
  67. //echo $search_extra_sql;exit();
  68. $result_search = $pdo_search_extra -> query($search_extra_sql);
  69. $order_extra_array = $result_search -> fetchAll();
  70. $order_extra_array2 = array();
  71. $order_id_extra = array();
  72. foreach ($order_extra_array as $temp) {
  73. $order_extra_array2[$temp['order_id'] . ""] = $temp;
  74. $order_id_extra[] = $temp['order_id'];
  75. }
  76. // 提交将订单备注里面的值取出来
  77. $remark_byorder_id = array();
  78. //echo json_encode($data[1]);exit();
  79. for ($i = 0; $i < count($data[1]); $i++) {
  80. $dict = $data[1][$i];
  81. $temp_order_id=$dict['parent_orderNo'];
  82. if ($dict['remark']=="") {
  83. continue;
  84. }
  85. $temp_remark = $dict['remark'];
  86. // 解决历史遗留问题
  87. // $temp_remark=str_replace(' ', '*', $temp_remark);
  88. // $temp_remark=str_replace(',', '*', $temp_remark);
  89. // $temp_remark=str_replace(',', '*', $temp_remark);
  90. // $temp_remark=str_replace('|', '/', $temp_remark);
  91. if (strpos($temp_remark, '/') > 0) {
  92. $temp = $temp_remark;
  93. // $temp=str_replace(',', '+', $temp_remark);
  94. // $temp=str_replace(',', '+', $temp);
  95. // $temp=str_replace('|', '/', $temp);
  96. $customers = explode("/", $temp);
  97. } else if(strpos($temp_remark,'*')>0) {
  98. $temp = explode("/", $dict['remark'] . "/");
  99. unset($temp[1]);
  100. $customers = $temp;
  101. }else{
  102. $temp_str=$dict['contacts']."*".$dict['idNo']."/";
  103. $temp = explode("/", $temp_str);
  104. unset($temp[1]);
  105. $customers = $temp;
  106. }
  107. $new_arr_cus = array();
  108. for ($j = 0; $j < count($customers); $j++) {
  109. $cus = explode("*", $customers[$j]);
  110. $cus_one = array('name' => isset($cus[0]) ? $cus[0] : "", 'carid' => isset($cus[1]) ? $cus[1] : "");
  111. $new_arr_cus[] = $cus_one;
  112. }
  113. $pos = strpos($dict['seat'], '×');
  114. $people_count = substr($dict['seat'], $pos + 2);
  115. // print_r($new_arr_cus);exit();
  116. if($people_count-1==count($new_arr_cus)){
  117. $temp_cus[]=array('name'=>isset($dict['contacts'])?$dict['contacts']:"-",'carid'=>isset($dict['idNo'])?$dict['idNo']:"-");
  118. $new_arr_cus=array_merge($temp_cus,$new_arr_cus);
  119. }
  120. // 保存订单人的键
  121. $temp_k="";
  122. foreach($new_arr_cus as $k=>$cus){
  123. if($cus['name']==$dict['contacts']){
  124. $temp_k=$k;
  125. }
  126. }
  127. if($temp_k!=""){
  128. // 将订单人的键放在第一位
  129. $temp_1=$new_arr_cus[0];
  130. $new_arr_cus[0]=$new_arr_cus[$temp_k];
  131. $new_arr_cus[$temp_k]=$temp_1;
  132. }
  133. // print_r($new_arr_cus);
  134. $new_arr=arr_unique2D($new_arr_cus);
  135. $remark_byorder_id[$dict['parent_orderNo']] = $new_arr;
  136. $remark_byorder_id = isset($remark_byorder_id) ? $remark_byorder_id : array();
  137. }
  138. //$new_arr = arr_unique2D($remark_byorder_id);
  139. //array_unique($remark_byorder_id);
  140. //print_r($remark_byorder_id);
  141. //exit();
  142. $str = "线路名称,车号,车牌号码,司机姓名,司机手机,上车站点,下车站点,发班日期,产品名称,座位等级,出行人数,分销价,GMV,门票价格,酒店价格,游客姓名,联系方式,身份证号,渠道,渠道订单号,订单号,状态" . "\n";
  143. for ($i = 0; $i < count($data[1]); $i++) {
  144. $dict = $data[1][$i];
  145. $temp_order_id=$dict['parent_orderNo'];
  146. $driver_info = getDriverInfo($dict['parent_orderNo']);
  147. $send_bus_no = $driver_info["bus_no"] . "\t";
  148. ;
  149. $send_driver_name = $driver_info["driver_name"] . "\t";
  150. ;
  151. $send_driver_mobile = $driver_info["driver_mobile"] . "\t";
  152. ;
  153. $dict['line'] = isset($linedata_array2[$dict['line_code']]) ? $linedata_array2[$dict['line_code']] : "";
  154. $line_name = $dict['line'] . "\t";
  155. $start_station = $dict['start_station'] . "\t";
  156. $end_station = $dict['end_station'] . "\t";
  157. $start_date = substr($dict['travel_time'], 0, 10) . "\t";
  158. $prod_name=$dict['prod_name']."\t";
  159. $pos = strpos($dict['seat'], '×');
  160. $seat_level = substr($dict['seat'], 0, $pos) . "\t";
  161. $people_count = substr($dict['seat'], $pos + 2) . "\t";
  162. $f_price = $dict['total_price'] / substr($dict['seat'], $pos + 2) . "\t";
  163. $GMV = isset($dict['total_price']) ? $dict['total_price'] : "" . "\t";
  164. $cus_name = $dict['contacts'] . "\t";
  165. $cus_mobile = $dict['tel'] . "\t";
  166. $cus_carid = $dict['idNo'] . "\t";
  167. $order_remark = $dict['remark'];
  168. //订单备注
  169. $org_name = $dict['org_name'] . "\t";
  170. $org_order_id = $dict['outside_order_no']==""?"-":$dict['outside_order_no']."\t";
  171. $order_id = $dict['parent_orderNo'] . "\t";
  172. $bus_no = isset($dict['bus_order_id']) ? $dict['bus_order_id'] . "\t" : "";
  173. //门票价格和酒店价格
  174. $door_price = "-";
  175. $hotel_price = "-";
  176. if (in_array($dict['parent_orderNo'], $order_id_extra)) {
  177. $door_price = $order_extra_array2[$dict['parent_orderNo']]['gate_price'];
  178. $hotel_price = $order_extra_array2[$dict['parent_orderNo']]['hotel_price'];
  179. }
  180. $or_status = $dict['order_status'];
  181. $or_status_str = '';
  182. if ($or_status == "145") {
  183. $or_status_str = "待支付" . "\t";
  184. } else if ($or_status == "146") {
  185. $or_status_str = "已出票" . "\t";
  186. } else if ($or_status == "147") {
  187. $or_status_str = "已完成" . "\t";
  188. } else if ($or_status == "148") {
  189. $or_status_str = "已取消" . "\t";
  190. } else {
  191. $or_status_str = "未知" . "\t";
  192. }
  193. // $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";
  194. $cstr1 = "";
  195. $cstr2 = "";
  196. $cstr3 = "";
  197. $count_remark = 0;
  198. // 统计备注里面的人数
  199. $bool_zhizhu = false;
  200. // 是否是蜘蛛业务人员录入
  201. // 备注不填
  202. if ($order_remark == '') {
  203. if ($count_remark < (int)substr($dict['seat'], $pos + 2)) {
  204. for ($k = $count_remark; $k < (int)substr($dict['seat'], $pos + 2); $k++) {
  205. if ($k == 0) {
  206. $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";
  207. } else {
  208. $cus_name = "-";
  209. $cus_carid = "-";
  210. $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";
  211. }
  212. }
  213. }
  214. // $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";
  215. }
  216. // 拿到该订单下的备注
  217. if (isset($remark_byorder_id[$dict['parent_orderNo']]) && count($remark_byorder_id[$dict['parent_orderNo']]) > 0) {
  218. $remark1 = $remark_byorder_id[$dict['parent_orderNo']];
  219. // if (!array_key_exists($dict['contacts'], $remark1)) {
  220. // $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";
  221. // $bool_zhizhu = true;
  222. // }
  223. foreach ($remark1 as $temp) {
  224. // 张三,手机号 remark= 张三*身份证号/李四*身份证号
  225. if ($temp['name'] == $dict['contacts']) {
  226. $cus_carid = $temp['carid'] . "\t";
  227. $cus_name = $temp['name'] . "\t";
  228. $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";
  229. $count_remark++;
  230. } else {
  231. // 身份证号码相同,即备注中有了订单人的信息
  232. if ($temp['carid'] == $dict['idNo']) {continue;}
  233. $cus_name = isset($temp['name']) ? $temp['name'] ."\t": "-";
  234. $cus_carid = isset($temp['carid']) ? $temp['carid'] ."\t": "";
  235. // $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";
  236. $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";
  237. $count_remark++;
  238. }
  239. }
  240. $pe_count = (int)substr($dict['seat'], $pos + 2);
  241. if ($bool_zhizhu == true) {
  242. $pe_count--;
  243. }
  244. //判断备注信息有可能不是添加的乘客姓名+身份证号而是其它的内容
  245. if ($count_remark < $pe_count) {
  246. for ($k = $count_remark; $k < $pe_count; $k++) {
  247. if ($k == 0) {
  248. $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";
  249. } else {
  250. $cus_name = "-";
  251. $cus_carid = "-";
  252. $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";
  253. }
  254. }
  255. }
  256. // echo $count_remark;
  257. // echo (int)substr($dict['seat'], $pos + 2);
  258. // echo "</br>";
  259. $str .= $cstr1;
  260. $str .= $cstr2;
  261. $str .= $cstr3;
  262. }
  263. }
  264. $filename = date('Ymd') . '.csv';
  265. //设置文件名
  266. //echo $str;
  267. export_csv($filename, $str);
  268. //导出
  269. function export_csv($filename, $data) {
  270. header("Content-type:text/csv");
  271. header("Content-Disposition:attachment;filename=客人" . $filename);
  272. header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
  273. header('Expires:0');
  274. header('Pragma:public');
  275. $data = chr(0xEF) . chr(0xBB) . chr(0xBF) . $data;
  276. // $data = iconv("utf-8","gb2312",$data);
  277. echo $data;
  278. }
  279. function getDriverInfo($ORDER_ID) {
  280. $msg_pdo = conn();
  281. $msg_sql = "CALL SP_GET_MESSAGE_TEMPLATE('" . $ORDER_ID . "')";
  282. $content = '';
  283. if (is_object($msg_pdo)) {
  284. $msg_result = $msg_pdo -> query($msg_sql);
  285. $i = 1;
  286. $data = array();
  287. if ($msg_result) {
  288. $data['code'] = "0";
  289. $data['info'] = "";
  290. do {
  291. $row = $msg_result -> fetchAll(PDO::FETCH_ASSOC);
  292. if ($i == 1) {
  293. $data['seat'] = isset($row) ? $row : array();
  294. } else if ($i == 2) {
  295. $data['run_info'] = isset($row) ? $row : array();
  296. } else if ($i == 3) {
  297. $data['driver'] = isset($row) ? $row : array();
  298. } else {
  299. }
  300. $i++;
  301. } while($msg_result->nextRowset());
  302. }
  303. $json_obj = json_decode(json_encode($data), TRUE);
  304. $seat = isset($json_obj['seat'][0]) ? $json_obj['seat'][0] : array();
  305. $run_info = isset($json_obj['run_info'][0]) ? $json_obj['run_info'][0] : array();
  306. $driver = isset($json_obj['driver'][0]) ? $json_obj['driver'][0] : array();
  307. if ($driver) {
  308. return $driver;
  309. $bus_no = isset($driver['bus_no']) ? $driver['bus_no'] : "";
  310. $driver_name = isset($driver['driver_name']) ? $driver['driver_name'] : "";
  311. $driver_mobile = isset($driver['driver_mobile']) ? $driver['driver_mobile'] : "";
  312. } else {
  313. return array("bus_no" => "", "driver_name" => "", "driver_mobile" => "");
  314. }
  315. }
  316. }
  317. // 二维数组
  318. function arr_unique2D($data = array()) {
  319. $tmp = array();
  320. foreach ($data as $key => $value) {
  321. //把一维数组键值与键名组合
  322. foreach ($value as $key1 => $value1) {
  323. $value[$key1] = $key1 . '_|_' . $value1;
  324. //_|_分隔符复杂点以免冲突
  325. }
  326. $tmp[$key] = implode(',|,', $value);
  327. //,|,分隔符复杂点以免冲突
  328. }
  329. //对降维后的数组去重复处理
  330. $tmp = array_unique($tmp);
  331. //重组二维数组
  332. $newArr = array();
  333. foreach ($tmp as $k => $tmp_v) {
  334. $tmp_v2 = explode(',|,', $tmp_v);
  335. foreach ($tmp_v2 as $k2 => $v2) {
  336. $v2 = explode('_|_', $v2);
  337. $tmp_v3[$v2[0]] = $v2[1];
  338. }
  339. $newArr[$k] = $tmp_v3;
  340. }
  341. return $newArr;
  342. }
  343. exit();