|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- <?php
- require_once '../st-xm/Common/Mysql.php';
- require_once '../st-xm/Common/dictionary.php';
- header("Access-Control-Allow-Origin:*");
-
- //test
- //$_POST['auth_code'] = "abcdefg";
- //$_POST['ctrip_order_no'] = "abcdefg1234";
- //end of test
- $auth_code=isset($_POST['auth_code'])? $_POST['auth_code']:false;
- $ctrip_order_no=isset($_POST['ctrip_order_no'])? $_POST['ctrip_order_no']:false;
-
- $return_data = array();
- $return_data['code']='201';
- $cancel_limit_time = date("Y-m-d H:i",strtotime("+30 minutes"));
-
- if( $auth_code == false || $ctrip_order_no == false ) {
- $return_data['code']='401';
- echo json_encode($return_data);
- exit();
- }
-
- $pdo=conn1();
- $sql=" SELECT user_name,user_psd,user_auth_code FROM api_auth_code WHERE user_auth_code='".$auth_code."' ";
- $result=$pdo->query($sql);
- $rowset=$result->fetchAll();
- $result->closeCursor();
- if( false == $rowset ) {
- $return_data['code']='400';
- echo json_encode($return_data);
- exit();
- }
- $sql1 = " SELECT * FROM outside_submit_order WHERE outside_order_no = '{$ctrip_order_no}' ";
- $result=$pdo->query($sql1);
- $result_array=$result->fetchAll();
- $result->closeCursor();
- if( false == $result_array ) {
- $return_data['code']='601';
- $return_data['msg']='该订单并未下单成功';
- echo json_encode($return_data);
- exit();
- }
- $outside_submit_order_info = $result_array[0];
- $submit_status = $result_array[0]["submit_status"];
- if( $submit_status == 0 ) {
- $return_data['code']='601';
- $return_data['msg']='该订单并未下单成功';
- echo json_encode($return_data);
- exit();
- } else if( $submit_status == 99 ) {
- $return_data['code']='801';
- $return_data['msg']='该订单号已在之前的处理中退单成功';
- echo json_encode($return_data);
- exit();
- }
-
- $sql1 = " SELECT * FROM order_main WHERE OUTSIDE_ORDER_NO = '{$ctrip_order_no}' AND ORDER_STATUS != 238 ";
- $result=$pdo->query($sql1);
- $result_array=$result->fetchAll();
- $result->closeCursor();
- $order_array = array();
- $run_id_array = array();
- $outside_run_flag = false;
- foreach( $result_array as $order_info ) {
- if( $order_info["PROD_ID"] == 380001 ) {
- $outside_run_flag = true;
- }
- if ($order_info["PARENT_ORDER_ID"] == 0) {
- $order_array[$order_info["ORDER_ID"]] = $order_info;
- } else {
- if (!in_array($order_info["RUN_ID"], $run_id_array)) {
- $run_id_array[] = $order_info["RUN_ID"];
- }
- }
- }
-
- if( false == $outside_run_flag ) {
- $cancel_limit_time = date("Y-m-d H:i",strtotime("+24 hours"));//test
- $sql2 = " SELECT * FROM run_main WHERE RUN_ID IN (" . implode(",", $run_id_array) . ") ";
- $result = $pdo->query($sql2);
- $result_array = $result->fetchAll();
- $result->closeCursor();
- if ($result_array == false) {
- $return_data['code'] = '501';
- $return_data['msg'] = '该班次为无效班次';
- echo json_encode($return_data);
- exit();
- }
- foreach ($result_array as $run_main_info) {
- if ($run_main_info["RUN_STATUS"] != 138) {
- $return_data['code'] = '501';
- $return_data['msg']='该班次已无法退单,详细情况请联系客服。';
- echo json_encode($return_data);
- exit();
- }
- $run_start_time = $run_main_info["RUN_DATE"] . " " . $run_main_info["RUN_TIME"];
- if ($run_start_time <= $cancel_limit_time) {
- $return_data['code'] = '501';
- $return_data['msg'] = '该班次已过最后退票截止时间(发车前24小时)无法退单';
- echo json_encode($return_data);
- exit();
- }
- }
- $run_main_info = $result_array[0];
- } else {
- $cancel_limit_time = date("Y-m-d H:i",strtotime("+24 hours"));
- $sql2 = " SELECT * FROM outside_run WHERE prod_code = '{$outside_submit_order_info["prod_id"]}' ";
- $result = $pdo->query($sql2);
- $result_array = $result->fetchAll();
- $result->closeCursor();
- $run_main_info = $result_array[0];
- $run_start_time = $run_main_info["start_date"] . " " . $run_main_info["start_time"];
- if ($run_start_time <= $cancel_limit_time) {
- $return_data['code'] = '501';
- $return_data['msg'] = '该班次已过最后退票截止时间(发车前24小时)无法退单';
- echo json_encode($return_data);
- exit();
- }
- }
-
- $current_time = date("Y-m-d H:i:s");
- $user_id = 1;
- foreach( $order_array as $order_main_info ) {
- $order_id = $order_main_info["ORDER_ID"];
- if( isset($run_main_info['PROD_ID']) && in_array($run_main_info['PROD_ID'], $__ary_special_line_array) ){
- $result = post2('wx.zhizhuchuxing.com/ZZDZ2/application/custom_made/control.php',array('type' =>'order_refund','order_id'=>$order_id));
- $return_array = json_decode( $result, true );
- if($return_array["code"] == 0 ){
- $tel = "13816608252";
- $name = "";
- $content = "订单号:【" . $order_id . "】已被取消(定制巴士)";
- $response = sendTelMessage($tel, $name, $content, $order_id);
-
- //cancel log
- $pdo_insert2 = conn1();
- $cancel_reason = "取消原因:渠道取消";
- $sql = "insert into order_opera_log(order_id,opera_user_id,opera_type,opera_time,opera_detail,opera_platform) VALUES ({$order_id},2,2,'{$current_time}','{$cancel_reason}','OTA对接')";
- $result = $pdo_insert2->exec($sql);
-
- break;
- } else {
- $return_data['code'] = '501';
- $return_data['msg'] = '该班次已无法退单,详细情况请联系客服。';
- echo json_encode($return_data);
- exit();
- }
- } else {
- $sql = "CALL SP_CANCEL_ORDER(" . $user_id . "," . $order_id . ")";
- $result = $pdo->query($sql);
- if (false == $result) {
- $return_data['code'] = '501';
- $return_data['msg'] = '该班次已无法退单,详细情况请联系客服。';
- echo json_encode($return_data);
- exit();
- }
- $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
- $result->closeCursor();
- if ($rowset[0]['errorcode'] != 0) {
- $return_data['code'] = '501';
- $return_data['msg'] = '该班次已无法退单,详细情况请联系客服。';
- echo json_encode($return_data);
- exit();
- }
- if ($outside_run_flag == true) {
- $tel = "18321097335,15938561301";
- $name = "";
- $content = "订单号:【" . $order_id . "】已被取消(自在产品订单号:【" . $outside_submit_order_info["supply_order_id"] . "】)";
- $response = sendTelMessage($tel, $name, $content, $order_id);
- }
-
- //cancel log
- $pdo_insert2 = conn1();
- $cancel_reason = "取消原因:渠道取消";
- $sql = "insert into order_opera_log(order_id,opera_user_id,opera_type,opera_time,opera_detail,opera_platform) VALUES ({$order_id},2,2,'{$current_time}','{$cancel_reason}','OTA对接')";
- $result = $pdo_insert2->exec($sql);
-
- $status_post_data = array();
- $status_post_data['order_id'] = $order_id;
- $status_post_data['order_status'] = "460";
- post2("http://". CS_DOMAIN. "/st-xm/Api/add_order_status_log.php",$status_post_data);
- }
- /*
- $res_content = get_msg_info($order_id);
- $name = isset($res_content[0])?$res_content[0]:"";
- $tel = isset($res_content[1])?$res_content[1]:"";
- $content = isset($res_content[2])?$res_content[2]:"";
- $response = sendTelMessage($tel, $name, $content, $order_id);
- $comment_type=0;
- $comment_text="";
- $send_success = (int)$response;
- $sql1 = "CALL HT_ADD_MSG_COMMENT(2,'addmsg'," . $order_id . "," . $comment_type . ",'" . $comment_text . "','" . $tel . "','" . $content . "','" . date("Y-m-d H:i:s") . "',{$send_success})";
- $result1 = $pdo -> query($sql1);
- $rowset1 = $result1 -> fetchAll(PDO::FETCH_ASSOC);
- $result1 -> closeCursor();*/
- }
-
- $pdo_update = conn1();
- $sql_update = " UPDATE outside_submit_order set submit_status=99 WHERE outside_order_no='{$ctrip_order_no}'";
- $pdo_update->exec($sql_update);
-
- $return_data["code"] = "201";
- $return_data["return_money"] = $outside_submit_order_info["all_price"];
- //舟山线路退票规则
- //1.发车前72h以外收取5%手续费
- //2.发车前72h以内收取10%手续费
- //3.发车前1h以内收取50%手续费
- //if( $outside_run_flag == true ) {
- $before_24hours = date("Y-m-d H:i:s", strtotime($run_start_time." -24 hours"));
- //if( $current_time >= $before_24hours ) {
- $return_data["return_money"] = $outside_submit_order_info["all_price"] * 0.9;
- //} else {
- // $return_data["return_money"] = $outside_submit_order_info["all_price"];
- //}
- //}
-
-
- $return_data["msg"] = "订单已成功取消";
- echo json_encode($return_data);
- exit();
-
- function post2($url, $post_data = '', $timeout = 5){//curl
- $ch = curl_init();
- curl_setopt ($ch, CURLOPT_URL, $url);
- curl_setopt ($ch, CURLOPT_POST, 1);
- if($post_data != ''){
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
- }
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
- curl_setopt($ch, CURLOPT_HEADER, false);
- $file_contents = curl_exec($ch);
- curl_close($ch);
- return $file_contents;
- }
-
- /*
- function get_msg_info($ORDER_ID) {
- $msg_pdo = conn1();
- $msg_sql = "CALL SP_GET_MESSAGE_TEMPLATE('" . $ORDER_ID . "')";
- $content = '';
- if (is_object($msg_pdo)) {
- $msg_result = $msg_pdo -> query($msg_sql);
- $i = 1;
- $data = array();
- if ($msg_result) {
- $data['code'] = "0";
- $data['info'] = "";
- do {
- $row = $msg_result -> fetchAll(PDO::FETCH_ASSOC);
- if ($i == 1) {
- $data['seat'] = isset($row) ? $row : array();
- } else if ($i == 2) {
- $data['run_info'] = isset($row) ? $row : array();
- } else if ($i == 3) {
- $data['driver'] = isset($row) ? $row : array();
- } else {
- }
- $i++;
- } while($msg_result->nextRowset());
- }
- $json_obj = json_decode(json_encode($data), TRUE);
- $seat = isset($json_obj['seat'][0])?$json_obj['seat'][0]:array();
- $run_info = isset($json_obj['run_info'][0])?$json_obj['run_info'][0]:array();
- $driver = isset($json_obj['driver'][0])?$json_obj['driver'][0]:array();
- //取消
- $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已成功退票,期待下次再为您服务!";
- if ($seat) {
- $seat_x = $seat['seat_x'];
- $seat_y = $seat['seat_y'];
- $seat_name = $seat['seat_name'];
- $order_main_id = $seat['order_main_id'];
- }
- if ($run_info) {
- $order_count = $run_info['order_count'];
- $start_date = $run_info['start_date'];
- $start_time = $run_info['start_time'];
- $parent_order_id = $run_info['parent_order_id'];
- $end_date = $run_info['end_date'];
- $start_area = $run_info['start_area'];
- $end_area = $run_info['end_area'];
- $res_name = $run_info['res_name'];
- $prod_name=$run_info['prod_name'];
- $prod_name="标准票";
- $customer_name = $run_info['customer_name'];
- $customer_mobile = $run_info['customer_mobile'];
- $start_end_date = $start_date . "," . $start_time;
- $content = str_replace("{出发地}", $start_area, $content);
- $content = str_replace("{目的地}", $end_area, $content);
- $content = str_replace("{出发日期 出发时间}", $start_end_date, $content);
- $content = str_replace("{票种名}", $prod_name, $content);
- $content = str_replace("{张数}", $order_count, $content);
- }
- if ($driver) {
- $bus_no = $driver['bus_no'];
- $driver_name = $driver['driver_name'];
- $driver_mobile = $driver['driver_mobile'];
- }
- return array(isset($customer_name)?$customer_name:"", isset($customer_mobile)?$customer_mobile:"", isset($content)?$content:"短信错误!!!");
- }
- }*/
|