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.
 
 
 
 

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