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.
 
 
 
 

486 lines
19 KiB

  1. <?php
  2. /*
  3. Author:fuhc
  4. Compeny:Spiders Travel
  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. header("Content-type:text/html;charset=utf-8");
  11. $method = isset($_GET['method']) ? $_GET['method'] : "";
  12. $user_id = getUserId();
  13. //if ($user_id == false) {
  14. // echo json_encode(array("code" => "1", "info" => "用户未登录"));
  15. // exit ;
  16. //}
  17. //$user_id=1;
  18. //取消订单原因
  19. if(isset($_GET['reason'])){
  20. $reason=$_GET['reason'];
  21. $order_id=$_GET['order_id'];
  22. $clock=$_GET['clock'];
  23. // $return_data = array();
  24. // $return_data["code"] = 1;
  25. // $return_data["info"] = $reason;
  26. $pdo_insert = conn();
  27. $sql = "insert into order_comment(ORDER_ID,COMMENT_TXT,CREATE_TIME) VALUES ({$order_id},'{$reason}','{$clock}')";
  28. $result = $pdo_insert->exec($sql);
  29. }
  30. if ($method == "cancelOrder") {
  31. $order_id = isset($_GET['order_id']) ? $_GET['order_id'] : "";
  32. $pdo = conn();
  33. $list_d = Find($order_id);
  34. if($list_d['prod_id'] == 449862 || $list_d['prod_id'] == 449867 || $list_d['prod_id'] == 450039 || $list_d['prod_id'] == 450043 || $list_d['prod_id'] == 450541 || $list_d['prod_id'] == 450546 ){
  35. $result = post2('http://wx.zhizhuchuxing.com/ZZDZ2/application/custom_made/control.php',array('type' =>'order_refund','order_id'=>$order_id));
  36. $result = (array)json_decode($result,true);
  37. }else{
  38. // $sql = "CALL SP_CANCEL_ORDER(" . $user_id . "," . $order_id . ")";
  39. // writeLog('cancelOrder= sql='.$sql);
  40. // $result = $pdo -> query($sql);
  41. // if( false != $result ) {
  42. // $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
  43. // $result = array();
  44. // $result['code'] = $rowset[0]['errorcode'];
  45. // }
  46. $cancel_url = 'http://'.CS1_DOMAIN.'/api/submit-order/cancel-bus-order';
  47. $send_post_data = array(
  48. "order_id" => $order_id,
  49. "user_id" => $user_id,
  50. "if_link" => 1,
  51. "cancel_reason" => $reason,
  52. 'opera_platform' => 'CS系统'
  53. );
  54. $temp=httpRequest($cancel_url,$send_post_data);
  55. $result = json_decode($temp, true);
  56. }
  57. if($result){
  58. if(isset($result['code']) && $result['code'] == 0){
  59. $rowset['code'] ='0';
  60. $rowset['info'] ='退票成功';
  61. $data['code'] ='0';
  62. $data['info'] = '退票成功';
  63. // $pdo_insert = conn();
  64. // $current_time = date("Y-m-d H:i:s");
  65. // $cancel_reason = "取消原因:".$reason;
  66. // $sql = "insert into order_opera_log(order_id,opera_user_id,opera_type,opera_time,opera_detail,opera_platform) VALUES ({$order_id},$user_id,2,'{$current_time}','{$cancel_reason}','CS系统')";
  67. // $result = $pdo_insert->exec($sql);
  68. // $post_data['order_id'] = "{$order_id}";
  69. // $post_data['order_status'] = "460";
  70. // $temp=post2("http://". CS_DOMAIN. "/st-xm/Api/add_order_status_log.php",$post_data);
  71. // //在这里加入run_x重排,该取消订单所在的车次的run_x数据
  72. // $re_data=array();
  73. // $re_data['order_id']=$order_id;
  74. // $temp2=post2("http://". CS_DOMAIN. "/api1.0/run_x_reorder.php",$re_data);
  75. // $data['extra']=json_decode($temp2);
  76. }else{
  77. $data['code']=isset($result['code'])?$result['code']:"499";
  78. $data['info']=isset($result['info'])?$result['info']:"未从数据库中获得返回值";
  79. $rowset['code'] = $data['code'];
  80. $rowset['info'] = $data['info'];
  81. echo json_encode($data);exit();
  82. }
  83. // echo json_encode($data);exit();
  84. }else{
  85. $data['code']="500";
  86. $data['info']="数据库错误";
  87. echo json_encode($data);exit();
  88. }
  89. if (is_array($rowset) && $rowset['code'] == 0 && SEND_MESSAGE == true) {
  90. $res_content = get_msg_info($order_id);
  91. $name = isset($res_content[0])?$res_content[0]:"";
  92. $tel = isset($res_content[1])?$res_content[1]:"";
  93. $content = isset($res_content[2])?$res_content[2]:"";
  94. // $content = "单号:" . $order_id . ',订单状态变更为' . $order_status . "随机数" . rand(1, 10000);
  95. writeLog("巴士取消短信模板内容:【" . $content . "】");
  96. //..取消发短信
  97. // $response=null;
  98. // $send_success="-100";
  99. // $response = sendTelMessage($tel, $name, $content, $order_id);
  100. // writeLog(json_encode($response));
  101. // $send_success = (int)$response;
  102. // $comment_type=0;
  103. // $comment_text="";
  104. // $sql1 = "CALL HT_ADD_MSG_COMMENT(".$user_id.",'addmsg'," . $order_id . "," . $comment_type . ",'" . $comment_text . "','" . $tel . "','" . $content . "','" . date("Y-m-d H:i:s") . "',{$send_success})";
  105. // $result1 = $pdo -> query($sql1);
  106. // $rowset1 = $result1 -> fetchAll(PDO::FETCH_ASSOC);
  107. // $result1 -> closeCursor();
  108. // writeLog("order_list.php HT_ADD_MSG_COMMENT()::" . $sql1);
  109. }
  110. echo json_encode($data);exit();
  111. }else if($method=="getOrderORG"){
  112. $pdo=conn();
  113. // $sql="SELECT ORG_ID AS org_id ,ORG_NAME as soure FROM base_organization where cancel_flag=0;";
  114. $sql="SELECT ID AS org_id ,SUPPLIER_NAME as soure FROM base_supplier where cancel_flag=0 AND SUPPLIER_TYPE=301";
  115. $main_corp_id = isset($_COOKIE["user_main_corp"]) ? $_COOKIE["user_main_corp"] : 0;
  116. if( $main_corp_id > 0 ) {
  117. $sql .= " AND MAIN_CORP_ID IN(0,{$main_corp_id}) ";
  118. }
  119. if( $main_corp_id != 3 ) {
  120. $sql .= " AND MAIN_CORP_ID NOT IN(3) ";
  121. }
  122. $result=$pdo->query($sql);
  123. $rowset=array("code"=>"0","info"=>"");
  124. $rowset['order_ORG_List']=$result->fetchAll(PDO::FETCH_ASSOC);
  125. $result->closeCursor();
  126. //准备查找运营负责人列表
  127. $pdo1=conn();
  128. $sql1="SELECT ID AS run_duty_id ,TRUE_NAME as name FROM base_user where cancel_flag=0 AND IS_RUN_DUTY=1";
  129. $main_corp_id = isset($_COOKIE["user_main_corp"]) ? $_COOKIE["user_main_corp"] : 0;
  130. if( $main_corp_id > 0 ) {
  131. $sql1 .= " AND MAIN_CORP_ID = {$main_corp_id} ";
  132. }
  133. $res=$pdo1->query($sql1);
  134. $rowset['run_duty_list']=$res->fetchAll(PDO::FETCH_ASSOC);
  135. $res->closeCursor();
  136. echo json_encode($rowset);exit();
  137. }
  138. else {
  139. $timelimit = isset($_GET['timelimit']) ? $_GET['timelimit'] : '';
  140. $starttime = isset($_GET['starttime']) ? $_GET['starttime'] : '';
  141. $endtime = isset($_GET['endtime']) ? $_GET['endtime'] : '';
  142. $ordersource = isset($_GET['ordersource']) ? (empty($_GET['ordersource']) ? 0 : $_GET['ordersource']) : 0;
  143. $orderstatus = isset($_GET['orderstatus']) ? (empty($_GET['orderstatus']) ? 0 : $_GET['orderstatus']) : 0;
  144. $paystatus = isset($_GET['paystatus']) ? (empty($_GET['paystatus']) ? -1 : $_GET['paystatus']) : -1;
  145. $bus_type= isset($_GET['bus_type']) ? (empty($_GET['bus_type']) ? -1 : $_GET['bus_type']) : -1;
  146. $billingstatus = isset($_GET['billingstatus']) ? $_GET['billingstatus'] : '';
  147. $mealbounce = isset($_GET['mealbounce']) ? $_GET['mealbounce'] : '';
  148. $refund = isset($_GET['refund']) ? $_GET['refund'] : '';
  149. $moresearch = isset($_GET['moresearch']) ? trim($_GET['moresearch']) : '';
  150. $export = isset($_GET['export']) ? $_GET['export'] : '';
  151. $run_time = isset($_GET['run_time'])?$_GET['run_time']:'';
  152. $search_bus_no = isset($_GET['search_bus_no'])?$_GET['search_bus_no']:'';
  153. //2016-07-15新增
  154. $start_area=isset($_GET['start_area']) ? $_GET['start_area'] : '';
  155. $end_area=isset($_GET['end_area']) ? $_GET['end_area'] : '';
  156. $line=isset($_GET['line']) ? $_GET['line'] : '';
  157. //..暂未加入存储过程
  158. //运营负责人
  159. $run_duty=isset($_GET['run_duty']) ? $_GET['run_duty'] : '-1';
  160. $currpage = isset($_GET['currpage']) ? (empty($_GET['currpage']) ? 1 : $_GET['currpage']) : 1;
  161. $pagesize = isset($_GET['pagesize']) ? (empty($_GET['pagesize']) ? 10 : $_GET['pagesize']) : 10;
  162. $pdo = conn();
  163. // $sql = "CALL XM_ORDER_GET_LIST(".$user_id.",'" . $timelimit . "','" . $starttime . "','" . $endtime . "'," . $ordersource . "," . $orderstatus . "," . $paystatus . ",'" . $billingstatus . "','" . $mealbounce . "','" . $refund . "','" . $moresearch . "','" . $export . "'," . $currpage . "," . $pagesize . ",'".$line."','".$start_area."','".$end_area."','".$bus_type."')";
  164. // writeLog('order_list.php -- sql== '.$sql);
  165. //
  166. // $result = $pdo -> query($sql);
  167. // if( false == $result ) {
  168. // echo json_encode(array("code" => "0", "info" => "", "searchInfo" => array()));exit();
  169. // }
  170. // $data = array();
  171. // do {
  172. // $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  173. // if ($rowset) {
  174. // $data[] = $rowset;
  175. // }
  176. // } while ($result->nextRowset());
  177. // $count = count($data);
  178. $_GET["main_corp_id"] = isset($_COOKIE["user_main_corp"]) ? $_COOKIE["user_main_corp"] : 0;
  179. $data = get_order_list( $pdo, $_GET );
  180. if( false == $data ) {
  181. echo json_encode(array("code" => "0", "info" => "", "searchInfo" => array()));exit();
  182. }
  183. $all_supplier_array = get_memcache("ARY_ALL_SUPPLIER");
  184. if( false == $all_supplier_array || is_array($all_supplier_array) == false || count($all_supplier_array) <= 0 ) {
  185. $pdo4=conn();
  186. $sql = " SELECT id,main_corp_id,supplier_type,supplier_name FROM base_supplier WHERE cancel_flag = 0 ";
  187. $result=$pdo->query($sql);
  188. $search_result = $result->fetchAll(PDO::FETCH_ASSOC);
  189. $all_supplier_array = array();
  190. foreach( $search_result as $result_info ) {
  191. $all_supplier_array[$result_info["id"]] = $result_info;
  192. }
  193. $result->closeCursor();
  194. }
  195. //准备查找运营负责人列表
  196. $pdo5=conn();
  197. $sql1="SELECT ID AS run_duty_id ,TRUE_NAME as name FROM base_user where MAIN_CORP_ID = {$_GET["main_corp_id"]} ";
  198. $result=$pdo->query($sql1);
  199. $search_result = $result->fetchAll(PDO::FETCH_ASSOC);
  200. $base_user_name_array = array();
  201. foreach( $search_result as $result_info ) {
  202. $base_user_name_array[$result_info["run_duty_id"]] = $result_info["name"];
  203. }
  204. $order_list = $data["order_list"];
  205. $order_id_array = array();
  206. $order_paymain_id_array = array();
  207. foreach($order_list as $k => $v){
  208. $order_id_array[]=$v['parent_orderNo'];
  209. $order_paymain_id_array[] = $v['order_pay_main_id'];
  210. $order_list[$k]['passenger_info']=str_replace(',','</br>',$v['passenger_info']);
  211. }
  212. //额外酒店门票价格
  213. $pdo2 = conn();
  214. $search_extra_sql = " SELECT id,order_id,hotel_price,gate_price FROM order_extra_info WHERE order_id IN (".implode(",",$order_id_array).") ";
  215. $result2 = $pdo2->query($search_extra_sql);
  216. if( false != $result2 ) {
  217. $order_extra_array = $result2->fetchAll();
  218. if ($order_extra_array != false && count($order_extra_array) > 0) {
  219. $order_extra_array2 = array();
  220. foreach ($order_extra_array as $order_extra_info) {
  221. $order_extra_array2[$order_extra_info["order_id"]] = $order_extra_info;
  222. }
  223. $order_extra_array = $order_extra_array2;
  224. }
  225. }
  226. //支付方式
  227. $pdo3 = conn();
  228. $search_extra_sql = " SELECT pay_main_id,pay_type_id_1 FROM order_pay_detail WHERE pay_main_id IN (".implode(",",$order_paymain_id_array).") ";
  229. $result3 = $pdo2->query($search_extra_sql);
  230. if( false != $result2 ) {
  231. $order_pay_array = $result3->fetchAll();
  232. if ($order_pay_array != false && count($order_pay_array) > 0) {
  233. $order_pay_array2 = array();
  234. foreach ($order_pay_array as $order_extra_info) {
  235. $order_pay_array2[$order_extra_info["pay_main_id"]] = $order_extra_info["pay_type_id_1"];
  236. }
  237. $order_pay_array = $order_pay_array2;
  238. }
  239. }
  240. //订单数组的数据重置
  241. $disp_pay_type = array("221" => "授信支付", "232" => "天猫旗舰店支付", "275" => "授信支付", "278" => "微信支付", "638" => "支付宝支付");
  242. $order_list2 = array();
  243. foreach( $order_list as $order_info ) {
  244. if( isset($all_supplier_array[$order_info["org_id"]]) ) {
  245. $order_info["org_name"] = $all_supplier_array[$order_info["org_id"]]["supplier_name"];
  246. } else {
  247. $order_info["org_name"] = "";
  248. }
  249. if( isset($all_supplier_array[$order_info["sub_channel_id"]]) ) {
  250. $order_info["sub_channel_name"] = $all_supplier_array[$order_info["sub_channel_id"]]["supplier_name"];
  251. } else {
  252. $order_info["sub_channel_name"] = "";
  253. }
  254. if( isset($order_pay_array[$order_info["order_pay_main_id"]]) ) {
  255. $order_info["pay_type"] = isset($disp_pay_type[$order_pay_array[$order_info["order_pay_main_id"]]]) ? $disp_pay_type[$order_pay_array[$order_info["order_pay_main_id"]]] : "授信支付";
  256. } else {
  257. $order_info["pay_type"] = "授信支付";
  258. }
  259. $order_info["seat"] = "普通座×".$order_info["count"];
  260. if( isset($order_extra_array[$order_info["M_ID"]]) ) {
  261. $order_info["hotel_price"] = $order_extra_array[$order_info["M_ID"]]["hotel_price"];
  262. $order_info["gate_price"] = $order_extra_array[$order_info["M_ID"]]["gate_price"];
  263. $extra_info_array = array();
  264. if( isset($order_info["hotel_price"]) && mb_strlen($order_info["hotel_price"]) > 0 ) {
  265. $extra_info_array[] ="酒店:".$order_info["hotel_price"];
  266. }
  267. if( isset($order_info["gate_price"]) && mb_strlen($order_info["gate_price"]) > 0 ) {
  268. $extra_info_array[] ="门票:".$order_info["gate_price"];
  269. }
  270. $order_info["seat"] .= "[br /]".implode(" ", $extra_info_array);
  271. }
  272. if( isset($base_user_name_array[$order_info["run_duty_id"]]) ) {
  273. $order_info["run_duty_name"] = $base_user_name_array[$order_info["run_duty_id"]];
  274. } else {
  275. $order_info["run_duty_name"] = "";
  276. }
  277. $order_list2[] = $order_info;
  278. }
  279. $order_list = $order_list2;
  280. $json = array("code" => "0", "info" => "");
  281. $json['totalTickets'] = $data["total_num"];
  282. $json['totalPages'] = ceil($data["total_num"]/$pagesize);
  283. $json['currentpage'] = $currpage;
  284. $json['pagesize'] = $pagesize;
  285. $json['orderList'] = array_values($order_list);
  286. $json['orderStatus'][] = $data["status_count"];
  287. $json['totalGmv'] = number_format($data["total_gmv"],2);
  288. $json['totalPeople'] = number_format($data["total_people"]);
  289. echo json_encode($json);exit();
  290. }
  291. function get_msg_info($ORDER_ID) {
  292. $msg_pdo = conn();
  293. $msg_sql = "CALL SP_GET_MESSAGE_TEMPLATE('" . $ORDER_ID . "')";
  294. $content = '';
  295. if (is_object($msg_pdo)) {
  296. $msg_result = $msg_pdo -> query($msg_sql);
  297. $i = 1;
  298. $data = array();
  299. if ($msg_result) {
  300. $data['code'] = "0";
  301. $data['info'] = "";
  302. do {
  303. $row = $msg_result -> fetchAll(PDO::FETCH_ASSOC);
  304. if ($i == 1) {
  305. $data['seat'] = isset($row) ? $row : array();
  306. } else if ($i == 2) {
  307. $data['run_info'] = isset($row) ? $row : array();
  308. } else if ($i == 3) {
  309. $data['driver'] = isset($row) ? $row : array();
  310. } else {
  311. }
  312. $i++;
  313. } while($msg_result->nextRowset());
  314. }
  315. $json_obj = json_decode(json_encode($data), TRUE);
  316. $seat = isset($json_obj['seat'][0])?$json_obj['seat'][0]:array();
  317. $run_info = isset($json_obj['run_info'][0])?$json_obj['run_info'][0]:array();
  318. $driver = isset($json_obj['driver'][0])?$json_obj['driver'][0]:array();
  319. //取消
  320. $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已成功退票,期待下次再为您服务!";
  321. if ($seat) {
  322. $seat_x = $seat['seat_x'];
  323. $seat_y = $seat['seat_y'];
  324. $seat_name = $seat['seat_name'];
  325. $order_main_id = $seat['order_main_id'];
  326. }
  327. if ($run_info) {
  328. $order_count = $run_info['order_count'];
  329. $start_date = $run_info['start_date'];
  330. $start_time = $run_info['start_time'];
  331. $parent_order_id = $run_info['parent_order_id'];
  332. $end_date = $run_info['end_date'];
  333. $start_area = $run_info['start_area'];
  334. $end_area = $run_info['end_area'];
  335. $res_name = $run_info['res_name'];
  336. $prod_name=$run_info['prod_name'];
  337. $prod_name="标准票";
  338. $customer_name = $run_info['customer_name'];
  339. $customer_mobile = $run_info['customer_mobile'];
  340. $start_end_date = $start_date . "," . $start_time;
  341. $content = str_replace("{出发地}", $start_area, $content);
  342. $content = str_replace("{目的地}", $end_area, $content);
  343. $content = str_replace("{出发日期 出发时间}", $start_end_date, $content);
  344. $content = str_replace("{票种名}", $prod_name, $content);
  345. $content = str_replace("{张数}", $order_count, $content);
  346. }
  347. if ($driver) {
  348. $bus_no = $driver['bus_no'];
  349. $driver_name = $driver['driver_name'];
  350. $driver_mobile = $driver['driver_mobile'];
  351. }
  352. return array(isset($customer_name)?$customer_name:"", isset($customer_mobile)?$customer_mobile:"", isset($content)?$content:"短信错误!!!");
  353. }
  354. }
  355. function post2($url, $data){//file_get_content
  356. $postdata = http_build_query(
  357. $data
  358. );
  359. $opts = array('http' =>
  360. array(
  361. 'method' => 'POST',
  362. 'header' => 'Content-type: application/x-www-form-urlencoded',
  363. 'content' => $postdata
  364. )
  365. );
  366. $context = stream_context_create($opts);
  367. $result = file_get_contents($url, false, $context);
  368. return $result;
  369. }
  370. function Find($order_id){
  371. $pdo= conn();
  372. $sql = "select order_description,order_price,order_pay_main_id "
  373. . "from order_main "
  374. . "where order_id=".$order_id;
  375. $result=$pdo->query($sql);
  376. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  377. $order_price = $rowset[0];//订单总价格 订单票的数量
  378. $sql = "SELECT DISTINCT
  379. order_description,parent_order_id,run_date,run_id,run_time,run_bus_order_id,prod_id,parent_prod_id,PROD_START_STATION_AREA_NAME,PROD_START_STATION_RES_NAME,PROD_END_STATION_AREA_NAME,PROD_END_STATION_RES_NAME
  380. FROM `order_main`
  381. where PARENT_ORDER_ID=".$order_id;
  382. $result=$pdo->query($sql);
  383. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  384. $order_station = $rowset[0];//订单来往地址 订单时间 订单好
  385. if(empty($order_station))
  386. return false;
  387. $array_order_desc=array();
  388. $arr_temp = explode('|',$order_price['order_description']);
  389. $arr=array();
  390. foreach ($arr_temp as $k=>$v2) {
  391. if(!empty($v2))
  392. $array_order_desc[]= explode (',', $v2); //订单票 * 数量
  393. }
  394. $list = array();
  395. //上海(黄浦旅游集散站) - 乌镇(西栅1号停车场)//反的数组
  396. $list['station'] = $order_station['PROD_START_STATION_AREA_NAME'].'('.$order_station['PROD_START_STATION_RES_NAME'].')'
  397. .'-'.$order_station['PROD_END_STATION_AREA_NAME'].'('.$order_station['PROD_END_STATION_RES_NAME'].')';
  398. $list['start_station']=$order_station['PROD_START_STATION_AREA_NAME'];
  399. $list['end_station']=$order_station['PROD_END_STATION_AREA_NAME'];
  400. $list['start_res_name'] = $order_station['PROD_START_STATION_RES_NAME'];
  401. $list['end_res_name'] = $order_station['PROD_END_STATION_RES_NAME'];
  402. $list['run_date'] = $order_station['run_date'];
  403. $list['run_time'] = $order_station['run_date'].' '.$order_station['run_time'];
  404. $list['count']='';
  405. $list['tic_num'] = 0;
  406. foreach ($array_order_desc as $v){
  407. if( !isset($v[2]) ) { continue; }
  408. $list['count'] .= ' '.$v[0].' × '.$v[2];
  409. $list['tic_num'] +=$v[2] ;
  410. }
  411. $list['order_price'] = $order_price['order_price'];
  412. $sql = "select pay_serial_number from order_pay_detail where pay_main_id =".$order_price['order_pay_main_id'];
  413. $result=$pdo->query($sql);
  414. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  415. $list['pay_num'] = $rowset[0]['pay_serial_number'];
  416. $list['line_id'] = $order_station['parent_prod_id'];
  417. $list['run_id'] = $order_station['run_id'];//run_bus_order_id
  418. $list['run_bus_order_id'] = $order_station['run_bus_order_id'];//parent_order_id
  419. $list['parent_order_id'] = $order_station['parent_order_id'];
  420. $list['prod_id'] = $order_station['prod_id'];
  421. return $list;
  422. }
  423. exit();