query($sql); $rowset=$result->fetchAll(); $result->closeCursor(); if( false == $rowset ) { $return_data['code']='400'; 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(); foreach( $result_array as $order_info ) { 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"]; } } } $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(); } } $user_id = 1; foreach( $order_array as $order_main_info ) { $order_id = $order_main_info["ORDER_ID"]; $sql = "CALL SP_CANCEL_ORDER(" . $user_id . "," . $order_id . ")"; $result = $pdo->query($sql); $result->closeCursor(); $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(); } $return_data["code"] = "201"; $return_data["msg"] = ""; echo json_encode($return_data); exit(); function get_msg_info($ORDER_ID) { $msg_pdo = conn(); $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:"短信错误!!!"); } }