get_prod_info($prod_list,$pdo); $ticket_id = $prod_info['ticket_id'];//票种ID $tic_num = $prod_info['tic_num'];//订票数量 $run_id = $prod_info['run_id'];//班次ID $userid = $prod_info['userid'];//用户ID $member_id = $prod_info['member_id'];//会员号 $run_date = $prod_info['run_date'];//发车日期 $run_time = $prod_info['run_time'];//发车时间 $run_date_time = $prod_info['run_date_time'];//检验订单所需时间 //判断会员号 if (!$member_id) { echo json_encode(array("code" => '1', "iflogin" => 1, "info" => "请关注公众号:蜘蛛出行")); exit; } //判断购票数量 if ($tic_num == 0) { echo json_encode(array("code" => '1', "info" => "订票数量不可为0")); exit; } //检查订单 $order_result =$this->check_order($startx_y, $endx_y, $line_id, $run_id, $tic_num, $start_name, $end_name,$run_date_time); writeLog("check_order:".json_encode($order_result)); //检查订单完全失败 if (!$order_result) { echo json_encode(array("code" => '120', "info" => "不可预订")); exit; } $cust_info = $this->explode_cust_info($customer_info); $cust_name = $cust_info['name']; $cust_phone = $cust_info['phone']; //交易还有机会,电话联系 if ($order_result['code'] == 101) { //将数据存入order_man_contact $sql_temp = "INSERT into order_man_contact(name,phone,run_id,start_station,end_station) VALUES('" . $cust_name . "','" . $cust_phone . "'," . $run_id . ",'" . $start_name . "','" . $end_name . "')"; $result_temp = $pdo->exec($sql_temp); echo json_encode(array("code" => '101', "info" => "提交成功,电话联系")); exit; } //检查订单成功 $order_result = $order_result['result']; $order_id = $order_result['order_id'];//订单ID $bus_no = $order_result['bus_no'];//车号 $start_time = substr($order_result['start_time'],-5);//开始时间 $end_time = substr($order_result['end_time'],-5);//结束时间 $order_from_org_id = 0;//订单渠道ID $top_org_id = 0;//顶级订单渠道ID $outside_order_id = isset($_POST['outside_order_id']) ? $_POST['outside_order_id'] : '1';//外部订单渠道ID //获取票种价格 $sql_price = "select cus_price from opera_product_price where prod_id =" . $ticket_id; $result_price = $pdo->query($sql_price); $row_p = $result_price->fetchAll(PDO::FETCH_ASSOC); $price_list = $ticket_id . ',' . $row_p[0]['cus_price'];//票种价格完整信息 $sql = "CALL sp_make_order_for_business('" . $userid . "','" . $prod_list . "','" . $customer_info . "','1','0','" . $start_name . "','" . $end_name . "','" . $start_time . "','" . $end_time . "','" . $bus_no . "','" . $member_id . "','" . $order_id . "')"; writeLog("sp_make_order_for_business---san: " . $sql); //提交order_main表 $rowset = $this->create_order($sql, $price_list,$pdo); //order_main提交失败 if(!$rowset || $rowset[0]['errcode']){ //启动退票算法 $cancel_order = new cancelOrder(); $res = $cancel_order -> funCancelOrder($line_id, $run_id, $bus_no, $order_id, $run_date_time); if($res){ $sql_temp = "INSERT into order_man_contact(name,phone,run_id,start_station,end_station) VALUES('" . $cust_name . "','" . $cust_phone . "'," . $run_id . ",'" . $start_name . "','" . $end_name . "')"; $result_temp = $pdo->exec($sql_temp); echo json_encode(array('code' => '1', 'info' => '您的订单正在审核中,15分钟客服人员将会致电您')); exit; }else{ echo json_encode(array('code' => '1', 'info' => '退票算法错误'));//退票算法和order_main表插入均失败 exit; } } //获取订单详情 $order_info = $this -> get_order_info($order_id,$pdo); $pay_main_id = $order_info[0]['order_pay_main_id'];//支付方式 //修改订单 $this -> update_order_info($order_id,$run_id,$bus_no,$member_id,$pay_main_id,$pdo); //发短信 //$this -> send_msg($order_id); echo json_encode(array('code' => '0', 'info' => '提交成功', 'order_id' => $order_id)); exit(); } //获取要提交订单的详细信息 public function get_prod_info($prod_list,$pdo){ $ticket_id = substr($prod_list, strpos($prod_list, 'm') + 1, strpos($prod_list, 'p') - 2);//票种ID $tic_num = substr($prod_list, strpos($prod_list, 'p') + 1, strpos($prod_list, '|') - strpos($prod_list, 'p') - 1);//乘客数量 $run_id = substr(substr($prod_list, strpos($prod_list, 'r') + 1), 0, -1);//班次ID //$beginX_Y = isset($_POST['startx_y']) ? $_POST['startx_y'] : false; $userid = 0;//用户ID $member_id =1;// isset($_COOKIE['user_id']) ? $_COOKIE['user_id'] : '0';//会员号ID $sql_time = "select run_date,run_time from run_main where run_id =" . $run_id; $result_time = $pdo->query($sql_time); $row_t = $result_time->fetchAll(PDO::FETCH_ASSOC); $run_date = $row_t[0]['run_date'];//出发日期 $run_time = $row_t[0]['run_time'];//出发时间 $run_date_time = $run_date . " " . $run_time; $prod_info['ticket_id'] = $ticket_id; $prod_info['tic_num'] = $tic_num; $prod_info['run_id'] = $run_id; $prod_info['userid'] = $userid; $prod_info['member_id'] =1;// $_COOKIE['user_id']; $prod_info['run_date'] = $run_date; $prod_info['run_time'] = $run_time; $prod_info['run_date_time'] = $run_date_time; return $prod_info; } //解析乘客信息 public function explode_cust_info($cust_info){ $cust_info_temp = explode(',', $cust_info ); $temp['name'] = $cust_info_temp['1']; $temp['phone']= $cust_info_temp['3']; return $temp; } //检验订单 public function check_order($startx_y, $endx_y, $line_id, $run_id, $tic_num, $start_name, $end_name,$run_date_time) { $co = new createOrder(); $time = commonUtils::baiduShortTime($startx_y, $endx_y); if (!$startx_y || !$endx_y) { $result['status'] = 111; //状态码:111为经纬度不能为空) $result['info'] = "经纬度不能为空"; echo json_encode($result); exit(); } if ($time > 360) //总时长不能超过360分钟 { $result['status'] = 101; //状态码:101为总时长不符合要求(超过360分钟) $result['info'] = "总时长不能超过360分钟"; echo json_encode($result); exit(); } if ($tic_num > 6) { $result['status'] = 108; //状态码:人数不能超过6人 $result['info'] = "每个订单人数不能超过6人"; echo json_encode($result); exit(); } //先判断是否属于规定的市区 $start_area = commonUtils::GeocodingAPI($startx_y); $end_area = commonUtils::GeocodingAPI($endx_y); if (($line_id == "449860" && $start_area == "南京市" && $end_area == "南通市") || ($line_id == "449865" && $start_area == "南通市" && $end_area == "南京市")) { if ($line_id && $run_id && $tic_num && $startx_y && $endx_y && $run_date_time) { $orderID = commonUtils::produceOrderId($tic_num); //获取订单号 $res = $co->calShortTime($line_id, $run_id, $orderID, $tic_num, $startx_y, $start_name, $endx_y, $end_name, $run_date_time); return $res; }else{ $result['code'] = '1'; $result['info'] = "订单提交信息不全"; echo json_encode($result); exit(); } } else { $result['code'] = '1'; $result['info'] = "所选地点不在规划范围内"; echo json_encode($result); exit(); } } //..短信模板-改为17:30后OK,当天下单也OK public 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 if ($i == 4) { $data['dsn_prod'] = isset($row) ? $row : array(); } else if ($i == 5) { $data['zhou_su_prod'] = isset($row) ? $row : array(); } $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(); $dsn_prod = isset($json_obj['dsn_prod']) ? $json_obj['dsn_prod'] : array(); $zhou_su_prod = isset($json_obj['zhou_su_prod']) ? $json_obj['zhou_su_prod'] : 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()); //迪士尼特殊情况parent_prod_id // $dsn_arr_prod = array(152752, 152759, 152763, 152770, 152777, 152784, 152791, 152801, 152808, 152815, 152822, 152832, 152842, 152852, 152859, 152866, 152873, 152877, 152884, 152891, 152898, 152905, 152915, 152922, 152929, 152936, 152946, 152956, 152966, 152973, 152980, 152990, 153003, 153016, 153023, 153033, 153034, 153044, 153057, 153070, 153083, 153090, 153100, 153110); $dsn_arr_prod = array(); //用来保存迪士尼产品的prod_id foreach ($dsn_prod as $temp) { $dsn_arr_prod[] = $temp['prod_id']; } $zhou_su_arr_prod = array(); foreach ($zhou_su_prod as $temp) { $zhou_su_arr_prod[] = $temp['prod_id']; } $new_message_array = array(448569, 448568); if (in_array($run_info['parent_prod_id'], $new_message_array)) { $content = "您预订的{出发日期}{出发地}-{目的地}{票种名}{张数}张,已成功出票,请在{出发时间}前十五分钟到达{上车站点}。出行前一天下午的18:00左右将会有导游和您联系,预祝您旅途愉快。"; } elseif (($now_time > "18: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},预祝您旅途愉快。"; if (in_array($run_info['parent_prod_id'], $dsn_arr_prod)) { $content = "您预订的{出发日期}{上车站点}-{下车站点}{票种名}{张数}张,已成功出票,请在{出发时间}前三十分钟到达{上车站点}。您的乘车订单号为{订单号}。请凭短信订单号乘车{$extra_message},预祝您旅途愉快。(如需咨询请致电:021-33280578)【zhizhuchuxing】Congratulations! Your ticket from hotel to Disney has been approved. Your order number is {订单号}. Please keep it and arrive at the place before {出发时间}. Enjoy your trip and have a nice day! If you have any questions, please call: 021-33280578."; $content = str_replace("{上车站点}", $run_info['res_name'], $content); $content = str_replace("{下车站点}", $run_info['end_res_name'], $content); $content = str_replace("{订单号}", $ORDER_ID, $content); } } else { // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车。"; $content = "您预订的{出发日期}{出发地}-{目的地}{票种名}{张数}张,已成功出票,请在{出发时间}前三十分钟到达{上车站点}。您的乘车订单号为{订单号},请凭短信订单号乘车。出行前一天下午的18:30会将车牌号与司机电话发送给您,预祝您旅途愉快。"; if (in_array($run_info['parent_prod_id'], $dsn_arr_prod)) { $ticket_url = TICKET_QR_URL . $ORDER_ID; $short_url = sinaShortenUrl($ticket_url); $extra_content = ""; if ($short_url != false) { $extra_content = "或点击以下链接获取乘车二维码扫码上车(" . $short_url . ")"; } $content = "您预订的{出发日期}{上车站点}-{下车站点}{票种名}{张数}张,已成功出票,请在{出发时间}前三十分钟到达{上车站点}。您的乘车订单号为{订单号}。请凭短信订单号乘车{$extra_content},预祝您旅途愉快。(如需咨询请致电:021-33280578)【zhizhuchuxing】Congratulations! Your ticket from hotel to Disney has been approved. Your order number is {订单号}. Please keep it and arrive at the place before {出发时间}. Enjoy your trip and have a nice day! If you have any questions, please call: 021-33280578."; $content = str_replace("{上车站点}", $run_info['res_name'], $content); $content = str_replace("{下车站点}", $run_info['end_res_name'], $content); $content = str_replace("{订单号}", $ORDER_ID, $content); } } // $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']; $parent_prod_id = $run_info['parent_prod_id']; $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); } /* if( $now_time < "18:30:00" ) { //判断是不是苏州或周庄 // 判断如果不是迪士尼的票就不发短信 if (!in_array($run_info['parent_prod_id'], $dsn_arr_prod) && !in_array($run_info['parent_prod_id'], $zhou_su_arr_prod)) { return array("", "-1", "不是迪士尼、苏州、周庄的票,目前不发送短信"); } }*/ return array(isset($customer_name) ? $customer_name : "", isset($customer_mobile) ? $customer_mobile : "", isset($content) ? $content : "短信错误,联系客服!!!"); } } //发短信 public function send_msg($ORDER_ID) { $send_pdo = conn(); $order_id = $ORDER_ID; $res_content = $this -> get_msg_info($order_id); $name = $res_content[0]; $tel = $res_content[1]; $content = $res_content[2]; writeLog("短信模板内容:【" . $content . "】"); //..发短信先取消 $response = $this -> sendTelMessage($tel, $name, $content, $order_id); writeLog(json_encode($response)); $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 = $send_pdo->query($sql1); $rowset1 = $result1->fetchAll(PDO::FETCH_ASSOC); $result1->closeCursor(); writeLog("hotel_order_status.php HT_ADD_MSG_COMMENT()::" . $sql1); //insert order extra $hotelPrice = isset($_GET['hotelPrice']) ? $_GET['hotelPrice'] : ""; $doorPrice = isset($_GET["doorPrice"]) ? $_GET["doorPrice"] : ""; if ($hotelPrice != "" || $doorPrice != "") { $sqlInsert = " INSERT INTO order_extra_info (order_id,hotel_price,gate_price) VALUE(" . $ORDER_ID . ",'" . $hotelPrice . "','" . $doorPrice . "') "; writeLog("insert extra info: " . $sqlInsert); $result = $send_pdo->exec($sqlInsert); } } //创建订单 public function create_order($sql, $price_list,$pdo) { if (is_object($pdo)) { $result = $pdo->query($sql); if (!$result) { return false; } // echo json_encode(array('aa'=>$sql));die; $rowset_create = $result->fetchAll(PDO::FETCH_ASSOC); $result->closeCursor(); writeLog('下订单成功'); writeLog(json_encode($rowset_create)); if (is_array($rowset_create) && $rowset_create[0]['errcode'] == 0 && SEND_MESSAGE == true) { //下订单成功再修改价格 writeLog('change_price.php' . json_encode($_POST)); $sql_up_price = "call SP_CHANGE_PRICE(" . $rowset_create[0]['order_id'] . ",'" . $price_list . "')"; //$sql="update order_main set order_price ='".$price_arr[$k]."' where PROD_ID=".$v." and PARENT_ORDER_ID=".$ordid." and RUN_ID>0"; $result_up_price = $pdo->query($sql_up_price); $rowset_up_price = $result_up_price->fetchAll(PDO::FETCH_ASSOC); writeLog("change_price.php sql:: " . $sql_up_price . "::rowset ::" . json_encode($rowset_up_price)); $result_up_price->closeCursor(); } } return $rowset_create; } //获取订单详情 public function get_order_info($order_id,$pdo) { //根据订单号查找订单详情 $sql = "SELECT a.order_id, a.create_time, a.order_price, a.order_pay_main_id, a.customer_name, a.customer_mobile, count(b.order_id) AS num, b.PROD_START_STATION_DATE AS run_date, b.PROD_START_STATION_TIME AS run_time, b.PROD_START_STATION_AREA_NAME AS start_area, b.PROD_END_STATION_AREA_NAME AS end_area, b.PROD_START_STATION_RES_NAME AS start_res, b.PROD_END_STATION_RES_NAME AS end_res FROM order_main a, order_main b WHERE a.order_id = b.PARENT_ORDER_ID AND a.order_id = " . $order_id . " GROUP BY a.order_id"; $result = $pdo->query($sql); $order_info = $result->fetchAll(PDO::FETCH_ASSOC); return $order_info; } //修改订单详情 public function update_order_info($order_id,$run_id,$bus_no,$member_id,$pay_main_id,$pdo) { $sql_pay = "UPDATE order_pay_detail SET pay_type_id_1 = 278 WHERE pay_main_id = " . $pay_main_id; $sql_cancel = "UPDATE order_main SET ORDER_BOOK_STATUS = 1, member_id = " . $member_id . " WHERE order_id = " . $order_id . " OR parent_order_id = " . $order_id; $sql_check = "INSERT into order_check_tickets(order_id,run_id,bus_no,check_status,check_time,check_station) VALUES(" . $order_id . "," . $run_id . "," . $bus_no . ",1,'" . date("Y-m-d H:i:s",time()) . "',0)"; $result = $pdo->exec($sql_cancel); $result = $pdo->exec($sql_pay); $result = $pdo->exec($sql_check); } } $prod_list = isset($_POST['prod_list'])?$_POST['prod_list']:'';//购票信息 $customer_info = isset($_POST['customer_info'])?$_POST['customer_info']:'';//乘客信息 $start_name = isset($_POST['start_name'])?$_POST['start_name']:'';//起点地名 $end_name = isset($_POST['end_name'])?$_POST['end_name']:'';//终点地名 $startx_y = isset($_POST['startx_y'])?$_POST['startx_y']:'';//起点纬经度 $endx_y = isset($_POST['endx_y'])?$_POST['endx_y']:'';//终点纬经度 $line_id = isset($_POST['line_id'])?$_POST['line_id']:'';;//线路ID $start_time = isset($_POST['start_time'])?$_POST['start_time']:'';//开始时间 $end_time = isset($_POST['end_time'])?$_POST['end_time']:'';//结束时间 //判断是否有时间 if(empty($start_time) || empty($end_time)){ echo json_encode(array('code' => '1', 'info' => '开始和结束时间均不能为空')); exit(); } $submit = new submit(); $res = $submit->execSubmit($prod_list, $customer_info, $start_name, $end_name, $startx_y, $endx_y, $line_id,$pdo); ?>