query($sql); $rowset=$result->fetchAll(); $result->closeCursor(); if( false == $rowset ) { $return_data['code']='400'; echo json_encode($return_data); exit(); } $sql = " SELECT * FROM order_main WHERE OUTSIDE_ORDER_NO='{$ctrip_order_no}' AND PARENT_ORDER_ID = 0 "; $result=$pdo->query($sql); $rowset=$result->fetchAll(); $result->closeCursor(); if( false != $rowset ) { //$order_id = $rowset[0]["ORDER_ID"]; $return_data['code']='701'; echo json_encode($return_data); exit(); } $current_time = date("Y-m-d H:i:s"); $pdo_insert = conn1(); $sql_insert = " INSERT INTO outside_submit_order (from_org_id,outside_order_no,prod_id,ticket_num,per_price,all_price,customer_name,customer_mobile,customer_id_no,submit_status,opera_time,passenger) VALUE(" . "17,'{$ctrip_order_no}','{$run_code }',{$ticket_num},{$per_price},{$all_price},'{$customer_name}','{$customer_mobile}','{$customer_id_no}',0,'{$current_time}','{$passenger_txt}') "; //$pdo_insert->exec($sql_insert); $return_data = array(); $return_data['code']='201'; if( $auth_code == false || $run_code == false || $ticket_num == false || $per_price == false || $all_price == false || $customer_name == false || $customer_id_no == false || $ctrip_order_no == false ) { $return_data['code']='401'; echo json_encode($return_data); exit(); } $param_run_code = $run_code; $run_code_array = explode("_",$run_code); //for 第三方 if( !isset($run_code_array[1]) ) { require_once '../st-xm/Common/zizai_orderAPI.php'; //zizai $prod_id = $run_code_array[0]; $sql = " SELECT * FROM outside_run WHERE prod_code='".$prod_id."' AND cancel_flag = 0 "; $result=$pdo->query($sql); $rowset=$result->fetchAll(); $result->closeCursor(); $return_data = array(); if( $result == false ) { $return_data['code']='501'; $return_data['msg']='该班次为无效班次'; echo json_encode($return_data); exit(); } $run_info = $rowset[0]; if( $run_info["prod_name"] == "儿童票" ) { $return_data['code']='501'; $return_data['msg']='该班次为无效班次'; echo json_encode($return_data); exit(); } $remain_count = $run_info["remain_count"] > 3 ? $run_info["remain_count"] - 3 : 0; if( $remain_count < $ticket_num ) { $return_data['code'] = '500'; $return_data['msg'] = '该班次剩余库存不足'; echo json_encode($return_data);exit(); } $run_code = $run_info["run_code"]; //自在下票 //$setOrder = new orderService(); //票务系统锁定 //$zizai_cus = "{|".$customer_name."|".$customer_mobile."|".$customer_id_no."||}"; //$lock_order = $setOrder->createOrder(zizaiArgs::$USER, $prod_id."P".$ticket_num."|", $customer_name,$customer_mobile,$customer_id_no,'', 0); //$lock_order = $setOrder->lock(zizaiArgs::$USER, 30, $prod_id."P".$ticket_num."|", $zizai_cus ); //if ($lock_order['code']!=0) { // $return_data['code'] = '500'; // $return_data['msg'] = '该班次剩余库存不足'; // echo json_encode($return_data);exit(); //} //$tradeno = $lock_order['tradeno']; //$customerlist = ""; //foreach( $passenger_array as $passenger_info ) { // $customerlist .= '{'.$prod_id.'|'.$passenger_info["passengerName"].'||'.descryption_by_shif($passenger_info["passengerId"]).'}'; //} //$return_info = $setOrder->customer(zizaiArgs::$USER, $tradeno, $customerlist); /* //确认订单 $res_order = $setOrder->eticket(zizaiArgs::$USER, $tradeno); if ($res_order['code']!=0) { $return_data['code'] = '500'; $return_data['msg'] = '该班次剩余库存不足'; echo json_encode($return_data);exit(); }*/ //出发地和目的地的area_id $sql = " SELECT ID,AREA_NAME FROM base_area WHERE AREA_NAME like \"".$run_info["start_area"]."%%\" AND cancel_flag = 0 "; $result=$pdo->query($sql); $rowset=$result->fetchAll(); $result->closeCursor(); if( $rowset == false ) { $start_area_id = 791; } else { $start_area_id = $rowset[0]["ID"]; } $sql = " SELECT ID,AREA_NAME FROM base_area WHERE AREA_NAME like \"".$run_info["end_area"]."%%\" AND cancel_flag = 0 "; $result=$pdo->query($sql); $rowset=$result->fetchAll(); $result->closeCursor(); if( $rowset == false ) { $end_area_id = 791; } else { $end_area_id = $rowset[0]["ID"]; } $userid = 1; $prod_id = 380001; $run_code = 0; $myprod = '{m'.$prod_id.'p'.$ticket_num.'|r'.$run_code.'}'; $mycustomer = "{,".$customer_name.",,".$customer_mobile.",150,".$customer_id_no.",,,,".$passenger_txt."}"; $run_info_txt = "{0,普通座票,".$run_info["line_name"].",".$run_info["start_date"].",".$run_info["start_time"].",".$run_info["start_res"].",".$run_info["start_date"].",".$run_info["start_time"].",".$run_info["start_area"].",".$run_info["end_res"].",,,".$run_info["end_area"].",".$start_area_id.",".$end_area_id."}"; $sql_insert="call sp_make_order_for_zizai(".$userid.",'".$myprod."','".$mycustomer."', 17, '".$ctrip_order_no."',".$run_info["cus_price"].", '".$run_info_txt."')"; writeLog($sql_insert); //test $return_data["code"] = "201"; $return_data["msg"] = $sql_insert; echo json_encode($return_data); exit(); //end of test $result=$pdo->query($sql_insert); if( $result == false ) { $rowset = false; } else { $rowset = $result->fetchAll(PDO::FETCH_ASSOC); } $result->closeCursor(); if (is_array($rowset) && $rowset[0]['errcode'] == 0 ) { $order_id=$rowset[0]['order_id']; //update submit order $pdo_update = conn1(); $sql_update = " UPDATE order_main set PROD_SUPPLY_ORG_NAME='自在旅行' WHERE ORDER_ID=".$order_id." OR PARENT_ORDER_ID=".$order_id; $pdo_update->exec($sql_update); $pdo_update2 = conn1(); $sql_update = " UPDATE outside_submit_order set submit_status=1,supply_order_id='-1' WHERE outside_order_no='{$ctrip_order_no}'"; $pdo_update2->exec($sql_update); $return_data["code"] = "201"; $return_data["order_no"] = $order_id; $return_data["msg"] = ""; $return_data["send_message_num"] = 1; $return_data["send_message_array"] = array("您已成功订购了{$run_info["line_name"]}[{$run_info["prod_name"]}]{$ticket_num}张。出发时间:{$run_info["start_date"]} {$run_info["start_time"]}。上车地点:{$run_info["start_res"]}。请于发车前到上车站点的服务台领票。咨询电话4008872626"); echo json_encode($return_data); exit(); } else { $pdo_update2 = conn1(); $sql_update = " UPDATE outside_submit_order set supply_order_id='-2' WHERE outside_order_no='{$ctrip_order_no}'"; $pdo_update2->exec($sql_update); $return_data['code'] = '500'; $return_data['msg'] = '该班次剩余库存不足'; echo json_encode($return_data); $pdo_update4 = conn1(); $sql_update = " UPDATE outside_submit_order set submit_status=-2,supply_order_id='{$sql_insert}' WHERE outside_order_no='{$ctrip_order_no}'"; $pdo_update4->exec($sql_update); exit(); } } $run_code = $run_code_array[0]; $prod_id = $run_code_array[1]; $sql2 = " SELECT * FROM run_main WHERE RUN_ID = {$run_code} "; $result=$pdo->query($sql2); $rowset=$result->fetchAll(); $result->closeCursor(); $return_data['code']='201'; if( $rowset == false ) { $return_data['code']='501'; $return_data['msg']='该班次为无效班次'; echo json_encode($return_data); exit(); } $run_main_info = $rowset[0]; $sql3 = " SELECT * FROM run_bus WHERE RUN_ID = {$run_code} AND RUN_BUS_STATUS = 138 "; $result=$pdo->query($sql3); $result_array=$result->fetchAll(); $result->closeCursor(); if( $result == false ) { $return_data['code'] = '402'; $return_data['msg'] = '发送参数不符合定义'; echo json_encode($return_data);exit(); } $run_bus_array = array(); foreach( $result_array as $run_bus_info ) { if( !isset($run_bus_array[$run_bus_info["RUN_ID"]]) ) { $run_bus_array[$run_bus_info["RUN_ID"]] = array(); } $run_bus_array[$run_bus_info["RUN_ID"]][] = $run_bus_info; } $data_array = array(); if( !$run_bus_array[$run_main_info["RUN_ID"]] || ( $run_main_info["RUN_DATE"] == $today && $limit_time >= $run_main_info["RUN_TIME"] ) || ( in_array( $run_main_info["PROD_ID"], $limit_sell_prod ) && $run_main_info["RUN_DATE"] <= $tomorrow_day && $current_hour > "10:00" ) ) { $total_count = 0; $saled_count = 0; $remain_count = 0; } else { $total_count = 0; $saled_count = 0; $remain_count = 0; foreach( $run_bus_array[$run_main_info["RUN_ID"]] as $run_bus_info ) { $total_count += $run_bus_info["SEAT_COUNT"]; $saled_count += $run_bus_info["SALED_COUNT"]; } $remain_count = $total_count - $saled_count; $remain_count = $remain_count <= 3 ? 0 : $remain_count; } if( $remain_count < $ticket_num ) { $return_data['code'] = '500'; $return_data['msg'] = '该班次剩余库存不足'; echo json_encode($return_data);exit(); } $sql4 = " SELECT opera_product.PROD_ID FROM opera_product WHERE PARENT_ID={$run_main_info["PROD_ID"]} AND PROD_TYPE=82"; $result=$pdo->query($sql4); $result_array=$result->fetchAll(); $result->closeCursor(); if( $result_array == false ) { $return_data['code'] = '500'; $return_data['msg'] = '该班次剩余库存不足'; echo json_encode($return_data);exit(); } $match_prod_flag = 0; foreach( $result_array as $ticket_info ) { if( $ticket_info["PROD_ID"] == $prod_id ) { $match_prod_flag = 1; break; } } if( $match_prod_flag == 0 ) { $return_data['code'] = '402'; $return_data['msg'] = '发送参数不符合定义'; echo json_encode($return_data);exit(); } $userid = 1; $myprod = '{m'.$prod_id.'p'.$ticket_num.'|r'.$run_code.'}'; $mycustomer = "{,".$customer_name.",,".$customer_mobile.",150,".$customer_id_no.",,,,".$passenger_txt."}"; $sql_insert="call sp_make_order(".$userid.",'".$myprod."','".$mycustomer."', 17, '".$ctrip_order_no."')"; $result=$pdo->query($sql_insert); $rowset=$result->fetchAll(PDO::FETCH_ASSOC); $result->closeCursor(); $send_message_num = 0; $send_message_mobile = array(); $back_order_id = false; if (is_array($rowset) && $rowset[0]['errcode'] == 0 ) { $order_id=$rowset[0]['order_id']; //come back ticket if( count($run_code_array) > 2 ) { $back_run_code = $run_code_array[2]; $back_prod_id = $run_code_array[3]; $back_myprod = '{m'.$back_prod_id.'p'.$ticket_num.'|r'.$back_run_code.'}'; $sql_insert2="call sp_make_order(".$userid.",'".$back_myprod."','".$mycustomer."', 17, '".$ctrip_order_no."')"; $result=$pdo->query($sql_insert2); $rowset_back=$result->fetchAll(PDO::FETCH_ASSOC); $result->closeCursor(); if (is_array($rowset_back) && $rowset_back[0]['errcode'] == 0 ) { $back_order_id=$rowset_back[0]['order_id']; } else { $sql = "CALL SP_CANCEL_ORDER(" . $user_id . "," . $order_id . ")"; $result = $pdo->query($sql); $result->closeCursor(); $return_data["code"] = $rowset_back[0]['errcode']; $return_data["msg"] = $rowset_back[0]['errinfo']; echo json_encode($return_data); exit(); } } $res_content=get_msg_info($order_id); $name=$res_content[0]; $tel=$res_content[1]; $content=$res_content[2]; //$response = sendTelMessage($tel, $name, $content, $order_id); $send_message_mobile[] = $content; $comment_type=0; $comment_text=""; $send_success = 0; $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(); if( $back_order_id != false ) { $res_content=get_msg_info($back_order_id); $name=$res_content[0]; $tel=$res_content[1]; $content=$res_content[2]; //$response = sendTelMessage($tel, $name, $content, $back_order_id); $send_message_mobile[] = $content; $comment_type=0; $comment_text=""; $send_success = 0; $sql1 = "CALL HT_ADD_MSG_COMMENT(2,'addmsg'," . $back_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(); } } else { $return_data["code"] = $rowset[0]['errcode']; $return_data["msg"] = $rowset[0]['errinfo']; echo json_encode($return_data); exit(); } $pdo_update = conn1(); $sql_update = " UPDATE outside_submit_order set submit_status=1 WHERE outside_order_no='{$ctrip_order_no}'"; $pdo_update->exec($sql_update); $return_data["code"] = "201"; $return_data["order_no"] = $rowset[0]['order_id']; $return_data["msg"] = ""; $return_data["send_message_num"] = count($send_message_mobile); $return_data["send_message_array"] = $send_message_mobile; echo json_encode($return_data); exit(); 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(); $bus_res_id = isset($json_obj['driver'][0]) ? $json_obj['driver'][0]["bus_res_id"] : 0; $short_url = false; if( $bus_res_id != 0 ) { $ary_sell_ary = array(916,917); if( in_array( $bus_res_id, $ary_sell_ary ) ) { $ticket_url = TICKET_QR_URL.$ORDER_ID; $short_url = sinaShortenUrl($ticket_url); } } $extra_message = ""; if( $short_url != false ) { $extra_message = "或点击以下链接获取您的电子票扫码上车:{$short_url}"; } //出票成功 // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车,车牌号{车牌号},司机电话{司机姓司机电话}。"; // 得到明天的时间 date_default_timezone_set('PRC'); //解决时区问题 $tomorrow = date("Y-m-d", strtotime("+1 day")); $now_time = date('H:i:s', time()); //判断当前时间是否在17:30:00之后 $cur_date = date('Y-m-d', time()); if (($now_time > "17:30:00" && $run_info['start_date'] == $tomorrow) || $cur_date == $run_info['start_date']) {//17:30之后的订单或者下单时间为今天出行为今天下午 发送短信模板 // if("18:30:00">"17:30:00" && $run_info['start_date']==$tomorrow){ //17:30之后的订单 发送短信模板 // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车,车牌号{车牌号},司机电话{司机姓司机电话}。"; $content = "您预订的{出发日期}{出发地}-{目的地}{票种名}{张数}张,已成功出票,请在{出发时间}前三十分钟到达{上车站点}。您的乘车订单号为{订单号},车牌号{车牌号},司机电话{司机姓司机电话},请凭短信订单号乘车".$extra_message.",预祝您旅途愉快。"; } else { // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车。"; $content = "您预订的{出发日期}{出发地}-{目的地}{票种名}{张数}张,已成功出票,请在{出发时间}前三十分钟到达{上车站点}。您的乘车订单号为{订单号},请凭短信订单号乘车".$extra_message."。出行前一天下午的18:30会将车牌号与司机电话发送给您,预祝您旅途愉快。"; } // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车。"; if ($seat) { $seat_x = isset($seat['seat_x']) ? $seat['seat_x'] : ""; $seat_y = isset($seat['seat_y']) ? $seat['seat_y'] : ""; $seat_name = isset($seat['seat_name']) ? $seat['seat_name'] : ""; $order_main_id = isset($seat['order_main_id']) ? $seat['order_main_id'] : ""; } else { } 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_date, $content); $content = str_replace("{出发时间}", $start_time, $content); $content = str_replace("{上车站点}", $res_name, $content); $content = str_replace("{出发地}", $start_area, $content); $content = str_replace("{目的地}", $end_area, $content); $content = str_replace("{票种名}", $prod_name, $content); $content = str_replace("{张数}", $order_count, $content); $content = str_replace("{订单号}", $ORDER_ID, $content); } else { $content = str_replace("{出发日期}", "", $content); $content = str_replace("{出发时间}", "", $content); $content = str_replace("{出发地}", "", $content); $content = str_replace("{目的地}", "", $content); $content = str_replace("{票种名}", "", $content); $content = str_replace("{张数}", "", $content); $content = str_replace("{订单号}", "", $content); } if ($driver) { $bus_no = isset($driver['bus_no']) ? $driver['bus_no'] : ""; $driver_name = isset($driver['driver_name']) ? $driver['driver_name'] : ""; $driver_mobile = isset($driver['driver_mobile']) ? $driver['driver_mobile'] : ""; if ($bus_no == "") { $content = str_replace(",车牌号{车牌号}", "", $content); } else { $content = str_replace("{车牌号}", $bus_no, $content); } if ($driver_name == "") { $content = str_replace(",司机电话{司机姓司机电话},", "。", $content); } else { $driver_xing = mb_substr($driver_name, 0, 1, 'utf-8'); $driver_name_mobile = $driver_xing . $driver_mobile; $content = str_replace("{司机姓司机电话}", $driver_name_mobile, $content); } } else { $content = str_replace("车牌号{车牌号},", "", $content); $content = str_replace("司机电话{司机姓司机电话},", "", $content); } $content.="【重要提示】:因G20峰会影响,7月1号开始实名登记安检,出行时请所有游客携带有效证件(身份证或户口本),凭有效证件上车,如被查出无有效证件,导致无法出行,责任自行承担,谢谢配合!"; return array(isset($customer_name) ? $customer_name : "", isset($customer_mobile) ? $customer_mobile : "", isset($content) ? $content : "短信错误,联系客服!!!"); } }