|
- <?php
- require_once '../Common/Mysql.php';
- require_once '../Common/zizai_orderAPI.php';
- $pdo=conn();
-
- $prod_id = $_GET['prod'];
- $prod = explode("|",$prod_id);
- $prod = $prod[0];
- $prod = explode("p",$prod);
- $prod_id = str_replace("{m",'',$prod[0]);
- $ticket_num = $prod[1];
-
- $customer = $_GET['customer'];
- $customer = str_replace("{",'',$customer);
- $customer = str_replace("}",'',$customer);
- $customer = explode("^",$customer);
- $customer_name = $customer[1];
- $customer_mobile = $customer[3];
- $customer_id_no = $customer[5];
- $passenger_txt = $customer[9];
-
-
- $from_order_no = $_GET['order_from_org_id'];
- $ctrip_order_no = $_GET['outside_order_id'];
-
- $from_org_name = "";
- $sql = " SELECT SUPPLIER_NAME FROM base_supplier WHERE ID={$from_order_no} ";
- $sql = " SELECT ORG_NAME as SUPPLIER_NAME FROM base_organization WHERE ORG_ID={$from_order_no} ";//
- $result=$pdo->query($sql);
- if( $result != false ) {
- $rowset = $result->fetchAll();
- $result->closeCursor();
- if( $rowset != false && count($rowset) > 0 ) {
- $from_org_name = $rowset[0]["SUPPLIER_NAME"];
- }
- }
-
- $sql = " SELECT * FROM outside_run WHERE prod_code='".$prod_id."' AND cancel_flag = 0 ";
- $result=$pdo->query($sql);
- $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
- $result->closeCursor();
- $return_data = array();
- if( $result == false ) {
- $return_data['errcode']='501';
- $return_data['errinfo']='该班次为无效班次';
- echo json_encode($return_data);
- exit();
- }
- $run_info = $rowset[0];
- $remain_count = $run_info['remain_count'];
- if( $remain_count < $ticket_num ) {
- $return_data['errcode'] = '500';
- $return_data['errinfo'] = '该班次剩余库存不足';
- echo json_encode($return_data);exit();
- }
- $run_code = $run_info["run_code"];
-
-
- //出发地和目的地的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(PDO::FETCH_ASSOC);
- $result->closeCursor();
- if( $rowset == false ) {
- $end_area_id = 791;
- } else {
- $end_area_id = $rowset[0]["ID"];
- }
-
- $current_time = date("Y-m-d H:i:s");
- $userid = getUserId();
- $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."',". $from_order_no.", '".$ctrip_order_no."',".$run_info["cus_price"].", '".$run_info_txt."')";
-
- writeLog($sql_insert);
- $result=$pdo->query($sql_insert);
- $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
- $result->closeCursor();
-
- $prod_id = $run_info['prod_code'];
- $setOrder = new orderService();
- $lock_order = $setOrder->createOrder(zizaiArgs::$USER, $prod_id."P".$ticket_num."|", $customer_name,$customer_mobile,$customer_id_no,'', 0);
- if ($lock_order['code'] != 0) {
- $post_data = array();
- $post_data["errcode"] = 1;
- $post_data["errinfo"] = "出票失败:该线路已停售";
- echo json_encode($post_data);exit();
- } else {
- $tradeno = $lock_order['tradeno'];
- $customerlist = "";
- $passengers = explode("/", $passenger_txt);
- foreach( $passengers as $passenger_info ) {
- $passenger_array = explode("*",$passenger_info);
- if( isset($passenger_array[1]) ) {
- $customerlist .= '{'.$prod_id.'|'.$passenger_array[0].'|'.$customer_mobile.'|'.$passenger_array[1].'}';
- }
- }
- if( mb_strlen($customerlist) > 0 ) {
- $return_info = $setOrder->customer(zizaiArgs::$USER, $tradeno, $customerlist);
- }
- $post_data = array();
- $order_id=$rowset[0]['order_id'];
- $post_data['errcode'] = $rowset[0]['errcode'];
- $post_data['errinfo'] = "订票成功";
- $post_data['order_id'] = $order_id;
- $line_name = str_replace("舟山","普陀山",$run_info["line_name"]);
- $send_usr_message = "您已成功订购了{$line_name}[{$run_info["prod_name"]}]{$ticket_num}张。出发时间:{$run_info["start_date"]} {$run_info["start_time"]}。上车地点:{$run_info["start_res"]}。请于发车前到上车站点的服务台领票。咨询电话4008872626";
- $response = sendTelMessage($customer_mobile, $customer_name, $send_usr_message, $order_id);
- $comment_type=0;
- $comment_text="";
- $send_success = 0;
- $sql1 = "CALL HT_ADD_MSG_COMMENT(2,'addmsg'," . $order_id . "," . $comment_type . ",'" . $comment_text . "','" . $tel . "','" . $send_usr_message . "','" . date("Y-m-d H:i:s") . "',{$send_success})";
- $pdo_update3 = conn();
- $result1 = $pdo_update3->query($sql1);
- $rowset1 = $result1->fetchAll(PDO::FETCH_ASSOC);
- $result1->closeCursor();
-
- $sql_order_status = "update order_main set order_status =146 where order_id= ".$order_id." or parent_order_id = ".$order_id;
- $pdo_update3->exec($sql_order_status);
-
- $opera_all_price = $run_info["cus_price"] * $ticket_num;
- $pdo_insert2 = conn();
- $opera_detail = "创建订单,出发日期{$run_info["start_date"]},订单渠道{$from_org_name},单价{$run_info["cus_price"]},总额{$opera_all_price},联系人信息:{$customer_name},{$customer_mobile},{$customer_id_no},备注信息:";
- $sql_log = "insert into order_opera_log(order_id,opera_user_id,opera_type,opera_time,opera_detail,opera_platform) VALUES ({$order_id},{$userid},1,'{$current_time}','{$opera_detail}','CS系统')";
- $pdo_insert2->exec($sql_log);
-
-
- echo json_encode($post_data);exit();
- }
- ?>
|