|
- <?php
- if (ALLOW_ORIGIN)
- header("Access-Control-Allow-Origin:*");
- date_default_timezone_set('PRC');
- //require_once '../../Common/Mysql.php';
-
- $user_id =getUserId();
- $order_from_org_id = 0;
- $top_org_id=0;
- //echo $order_from_org_id;die;
- if (!$user_id) {
- echo json_encode(array("code" => 1,"iflogin"=>1, "info" => "用户未登录"));
- exit ;
- }
- $list_tic = get_memcache('disney_ticket_info');
- if( $list_tic == false ) {
- //echo json_encode(array("code" => 1,"iflogin"=>1, "info" => "获取迪士尼门票信息失败,请联系技术部"));
- //get from db
- $current_day = date("Y-m-d");
- $pdo = conn1();
- $sql = " SELECT * FROM outside_ticket WHERE prod_code IN('SHDSN','SHDSN2') AND ticket_date >= '{$current_day}' AND cancel_flag = 0 ORDER BY ticket_date ";
- $result = $pdo->query($sql);
- $rowset = $result->fetchAll();
- $disney_ticket_array = array();
- foreach( $rowset as $row_info ) {
- $ticket_date = $row_info["ticket_date"];
- if( !isset($disney_ticket_array[$ticket_date]) ) {
- $disney_ticket_array[$ticket_date] = array();
- $disney_ticket_array[$ticket_date]["tic_info"] = array(0,0,0,0,0,0);
- $disney_ticket_array[$ticket_date]["price"] = array(0,0,0,0,0,0);
- $disney_ticket_array[$ticket_date]["ticket_array"] = array();
- $disney_ticket_array[$ticket_date]["ticket_array"][] = array( "ticketid" => "", "ticketname" => "单日成人票", "ticketprice" => 499, "ticketcount" => 0, "agentprice" => 464 );
- $disney_ticket_array[$ticket_date]["ticket_array"][] = array( "ticketid" => "", "ticketname" => "单日儿童票", "ticketprice" => 499, "ticketcount" => 0, "agentprice" => 464 );
- $disney_ticket_array[$ticket_date]["ticket_array"][] = array( "ticketid" => "", "ticketname" => "单日老人票", "ticketprice" => 499, "ticketcount" => 0, "agentprice" => 464 );
- $disney_ticket_array[$ticket_date]["ticket_array"][] = array( "ticketid" => "", "ticketname" => "二日成人票", "ticketprice" => 900, "ticketcount" => 0, "agentprice" => 845 );
- $disney_ticket_array[$ticket_date]["ticket_array"][] = array( "ticketid" => "", "ticketname" => "二日儿童票", "ticketprice" => 900, "ticketcount" => 0, "agentprice" => 845 );
- $disney_ticket_array[$ticket_date]["ticket_array"][] = array( "ticketid" => "", "ticketname" => "二日老人票", "ticketprice" => 900, "ticketcount" => 0, "agentprice" => 845 );
- }
- $ticket_name = $row_info["ticket_name"];
- $ticket_index = 0;
- if( mb_strpos($ticket_name, "儿童") ) {
- $ticket_index = 1;
- } else if( mb_strpos($ticket_name, "老人") ) {
- $ticket_index = 2;
- }
- if( $row_info["prod_code"] == 'SHDSN2' ) {
- $ticket_index += 3;
- }
- $ticket_info_temp = $disney_ticket_array[$ticket_date];
- $ticket_info_temp["tic_info"][$ticket_index] = $row_info["ticket_num"];
- $ticket_info_temp["price"][$ticket_index] = (int)$row_info["ticket_price"];
- $ticket_info_temp["ticket_array"][$ticket_index]["ticketid"] = $row_info["ticket_code"];
- $ticket_info_temp["ticket_array"][$ticket_index]["ticketprice"] = (int)$row_info["ticket_price"];
- $ticket_info_temp["ticket_array"][$ticket_index]["ticketcount"] = $row_info["ticket_num"];
- $ticket_info_temp["ticket_array"][$ticket_index]["agentprice"] = (int)$row_info["agent_price"];
- $disney_ticket_array[$ticket_date] = $ticket_info_temp;
- }
- foreach( $disney_ticket_array as $disney_date => $disney_ticket ) {
- $disney_memory[$disney_date] = $disney_ticket;
- }
- set_memcache('disney_ticket_info', $disney_memory);
- $list_tic = $disney_memory;
- }
-
- if(isset($_POST['get_tic'])){
- $date=$_POST['get_tic'];
- $tic_info = $list_tic[$date];
- //$tic_info = get_disney_all_info($date);
- echo json_encode(array("code" => 0,"info" => $tic_info['tic_info'],'price'=>$tic_info['price'] ));
- exit ;
- }
-
-
-
- $pay_status =146;
- $pay_type = 275;
-
-
-
- if(isset($_POST)){
- $date = isset($_POST['date_time'])?$_POST['date_time']:'0';
- $outside_no = isset($_POST['outside_no'])?$_POST['outside_no']:'';
- $order_from_org_id = isset($_POST['outside_org_id'])?$_POST['outside_org_id']:'0';
-
- $current_day = date('Y-m-d', time());
- $diff_seconds = strtotime($date) - strtotime($current_day);
- $diff_day = floor($diff_seconds/3600/24);
-
- if($diff_day < 0){
- echo json_encode(array("code" => 1, "info" => "不在预定时间段"));
- exit ;
- }
- $cust_name = isset($_POST['customer_name'])?$_POST['customer_name']:'匿名者';
- $cust_phone = isset($_POST['customer_phone'])?$_POST['customer_phone']:'123456789';
- $id_type = isset($_POST['customer_id_type'])? $_POST['customer_id_type']:'150'; // 150身份证 153 护照
- $customer_id = isset($_POST['customer_id'])?$_POST['customer_id']:'123456789';
- //票种和数量价格 prod_id=>票的数量
- $ticket=array(
- 'D'=>isset($_POST['D'])?$_POST['D']:0,
- 'C'=>isset($_POST['C'])?$_POST['C']:0,
- 'O'=>isset($_POST['O'])?$_POST['O']:0,
- 'D2'=>isset($_POST['D2'])?$_POST['D2']:0,
- 'C2'=>isset($_POST['C2'])?$_POST['C2']:0,
- 'O2'=>isset($_POST['O2'])?$_POST['O2']:0,
- );
- $ticket_no=array(
- '0'=>isset($_POST['D'])?$_POST['D']:0,
- '1'=>isset($_POST['C'])?$_POST['C']:0,
- '2'=>isset($_POST['O'])?$_POST['O']:0,
- '3'=>isset($_POST['D2'])?$_POST['D2']:0,
- '4'=>isset($_POST['C2'])?$_POST['C2']:0,
- '5'=>isset($_POST['O2'])?$_POST['O2']:0,
- );
-
-
-
- }
-
- //check ticket num
- foreach( $ticket_no as $buy_key => $buy_count ) {
- $ticket_remain_count = $list_tic[$date]['tic_info'][$buy_key];
- if( $ticket_remain_count < $buy_count ) {
- echo json_encode(array("code" => 1, "info" => '预订票数超出余票数量'));
- exit ;
- }
- }
-
- $num1=0;
- $num2=0;
- foreach ($ticket_no as $k=>$v) {
- if($k<=2){
- $num1+=$v;
- }else{
- $num2+=$v;
- }
- }
- if($num1 && $num2){
- echo json_encode(array("code" => 1, "info" => '单日票和双日票不可在同一订单'));
- exit ;
- }
- $disney_all_array = $list_tic[$date]["ticket_array"];
- $return_info = array();
- $return_no = buy_disney_ticket( $cust_name, $cust_phone, $customer_id, $ticket_no, $date, $disney_all_array, $return_info );
- if($return_no == '-1' || $return_no == '0'){
- echo json_encode(array("code" => 1, "info" => '出票失败|'.json_encode($return_info) ));
- exit ;
- }
- //echo $return_no;die;
-
- $order_customer_memo = "自在订单号({$return_no})";
-
- $pdo = conn();
- $sql = "select a.prod_id,a.prod_name,b.prod_price,b.prod_type_id "
- . "from opera_product a inner join opera_product_price b on a.prod_id = b.prod_id "
- . "where a.parent_id = 387267";
- $result=$pdo->query($sql);
- $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
- $info = array();
- foreach ($rowset as $v) {
- $info[$v['prod_id']] = $v;
- }
- $sql_p = "select prod_id,prod_name "
- . " from opera_product "
- . " where prod_id = 387267";
- $result_p=$pdo->query($sql_p);
- $rowset_p = $result_p -> fetchAll(PDO::FETCH_ASSOC);
- $info_p = $rowset_p[0];
- /**
- * 迪士尼票种信息
- * 152990 =>
- array
- 'prod_id' => string '152990' (length=6)
- 'prod_name' => string '迪士尼门票(成人票)' (length=30)
- 'prod_price' => string '20.00' (length=5)
- 'prod_type_id' => string '262' (length=3)
- */
-
- //$tic_info = get_disney_all_info($date);
- $tic_info = $list_tic[$date];
-
- $num=0;
- $order_description = "";
- $price=0;
- $return_info='';
- foreach ($ticket as $k=>$v) {
- $num+=$v;
- if($v){
- switch ($k){
- case 'D':
- $price+=$tic_info['price'][0]*$v;
- $return_info.='标准一日票 × '.$v;
- $order_description.=" 标准一日票,". date('Y-m-d',time()).",".$v."|";
- break;
- case 'C':
- $price+=$tic_info['price'][1]*$v;
- $return_info.=' 儿童一日票 × '.$v;
- $order_description.="儿童一日票,". date('Y-m-d',time()).",".$v."|";
- break;
- case 'O':
- $price+=$tic_info['price'][2]*$v;
- $return_info.=' 老人一日票 × '.$v;
- $order_description.="老人一日票,". date('Y-m-d',time()).",".$v."|";
- break;
- case 'C2':
- $price+=$tic_info['price'][4]*$v;
- $return_info.=' 儿童两日票 × '.$v;
- $order_description.="儿童两日票,". date('Y-m-d',time()).",".$v."|";
- break;
- case 'D2':
- $price+=$tic_info['price'][3]*$v;
- $return_info.=' 标准两日票 × '.$v;
- $order_description.="标准两日票,". date('Y-m-d',time()).",".$v."|";
- break;
- case 'O2':
- $price+=$tic_info['price'][5]*$v;
- $return_info.=' 老人两日票 × '.$v;
- $order_description.="老人两日票,". date('Y-m-d',time()).",".$v."|";
- break;
- }
- }
- }
-
- if($num>5 || $num<=0){
- echo json_encode(array("code" => 1, "info" => "最多定票五张"));
- exit ;
- }
-
- //订单插入需要的字段 id = order_id create_time update_time order_pay_satatus 0 未支付 order_description order_price order_prod_type
- // prod_name order_status customer_name customer_mobile customer_id_type customer_id _no
- // 至订单需要的之短 parent_order_id prod_id parent_prod_id prod_name parent_prod_name order_price
- //function getUniqeId(){
- // $pdo= conn();
- // $result=$pdo->query("select FUNC_GET_UNIQUE_ID('1','1') id");
- // $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
- // return $rowset[0]['id'];
- //}
- $id_p = getUniqeId();
- $order_id_p = $id_p;
- $pay_main_id = getUniqeId();
- $create_time = date('Y-m-d H:i:s',time());
- $update_time = $create_time;
- $order_pay_status = 0;
- //查找数据库中关于迪士尼的信息
-
-
-
- $sql_in=" insert into order_main
- (`id`,
- `order_id`,
- `create_time`,`update_time`,
- `order_pay_status`,`order_description`,`customer_memo`,
- `order_price`,`order_prod_type`,`prod_name`,`order_status`,
- `customer_name`,`customer_mobile`,`customer_id_type`,`customer_id_no`,
- `order_book_status`,`PROD_START_STATION_TIME_MINUTES`,`prod_id`,`run_date`,`main_create_user_id`,`order_pay_main_id`,`outside_sale_org_id`,`outside_order_no`)
- values ('".$id_p."','".$order_id_p."','".$create_time."','".$update_time."','0','".$order_description."','{$order_customer_memo}','"
- .$price."','258','".$info_p['prod_name']."','".$pay_status."','
- ".$cust_name."','".$cust_phone."','".$id_type."','".$customer_id."','1','0','".$info_p['prod_id']."','".$date."','".$user_id."','".$pay_main_id."','".$order_from_org_id."','{$outside_no}')";
- for_insert($sql_in);
- //插入支付方式等信息
- $sql_pay="insert INTO"
- . " `order_pay_main`(id,CREATe_user_id,CREATE_time,update_user_id,pay_total) "
- . "VALUES(".$pay_main_id.",".$user_id.",'".date('Y-m-d H-i-s', time())."',".$user_id.",".$price.");"
- . "insert INTO `order_pay_detail`
- (id,CREATe_user_id,CREATE_time,update_user_id,pay_main_id,pay_type_id_1,pay_money)
- VALUES(".$pay_main_id.",".$user_id.",'".date('Y-m-d H-i-s', time())."',".$user_id.",".$pay_main_id.",".$pay_type.",".$price.");";
- for_insert($sql_pay);
-
- foreach ($ticket as $k => $v) {
- if($v){
- switch ($k){
- case 'D':
- for($i=1;$i<=$v;$i++){
- $id =$order_id =getUniqeId();
- $sql = " insert into order_main
- (`id`,
- `order_id`,`customer_memo`,
- `create_time`,`update_time`,
- `order_pay_status`,
- `order_prod_type`,`order_status`,
- `customer_name`,`customer_mobile`,`customer_id_type`,`customer_id_no`,
- `order_book_status`,`PROD_START_STATION_TIME_MINUTES`,`parent_order_id`,`prod_id`,`parent_prod_id`,`prod_name`,`parent_prod_name`,`order_price`,`run_date`,`order_pay_main_id`,`outside_sale_org_id`,`outside_order_no`,`main_create_user_id`)
- values ('".$id."','"
- .$order_id."','{$order_customer_memo}',
- '".$create_time."','".$update_time."',
- '0','258','".$pay_status."','
- ".$cust_name."','".$cust_phone."','".$id_type."','".$customer_id."',
- '0','0','".$id_p."','".$info['387538']['prod_id']."','".$info_p['prod_id']."','".$info['387538']['prod_name']."','".$info_p['prod_name']."','".$tic_info['price'][0]."','".$date."','".$pay_main_id."','".$order_from_org_id."','{$outside_no}','".$user_id."')";
- for_insert($sql);
- }
- break;
-
- case 'C':
- for($i=1;$i<=$v;$i++){
- $id =$order_id =getUniqeId();
- $sql = " insert into order_main
- (`id`,
- `order_id`,`customer_memo`,
- `create_time`,`update_time`,
- `order_pay_status`,
- `order_prod_type`,`order_status`,
- `customer_name`,`customer_mobile`,`customer_id_type`,`customer_id_no`,
- `order_book_status`,`PROD_START_STATION_TIME_MINUTES`,`parent_order_id`,`prod_id`,`parent_prod_id`,`prod_name`,`parent_prod_name`,`order_price`,`run_date`,`order_pay_main_id`,`outside_sale_org_id`,`outside_order_no`,`main_create_user_id`)
- values ('".$id."','"
- .$order_id."','{$order_customer_memo}',
- '".$create_time."','".$update_time."',
- '0','258','".$pay_status."','
- ".$cust_name."','".$cust_phone."','".$id_type."','".$customer_id."',
- '0','0','".$id_p."','".$info['387540']['prod_id']."','".$info_p['prod_id']."','".$info['387540']['prod_name']."','".$info_p['prod_name']."','".$tic_info['price'][1]."','".$date."','".$pay_main_id."','".$order_from_org_id."','{$outside_no}','".$user_id."')";
- for_insert($sql);
- }
- break;
- case 'O':
- for($i=1;$i<=$v;$i++){
- $id =$order_id =getUniqeId();
- $sql = " insert into order_main
- (`id`,
- `order_id`,`customer_memo`,
- `create_time`,`update_time`,
- `order_pay_status`,
- `order_prod_type`,`order_status`,
- `customer_name`,`customer_mobile`,`customer_id_type`,`customer_id_no`,
- `order_book_status`,`PROD_START_STATION_TIME_MINUTES`,`parent_order_id`,`prod_id`,`parent_prod_id`,`prod_name`,`parent_prod_name`,`order_price`,`run_date`,`order_pay_main_id`,`outside_sale_org_id`,`outside_order_no`,`main_create_user_id`)
- values ('".$id."','"
- .$order_id."','{$order_customer_memo}',
- '".$create_time."','".$update_time."',
- '0','258','".$pay_status."','
- ".$cust_name."','".$cust_phone."','".$id_type."','".$customer_id."',
- '0','0','".$id_p."','".$info['387539']['prod_id']."','".$info_p['prod_id']."','".$info['387539']['prod_name']."','".$info_p['prod_name']."','".$tic_info['price'][2]."','".$date."','".$pay_main_id."','".$order_from_org_id."','{$outside_no}','".$user_id."')";
- for_insert($sql);
- }
- break;
- case 'C2':
- for($i=1;$i<=$v;$i++){
- $id =$order_id =getUniqeId();
- $sql = " insert into order_main
- (`id`,
- `order_id`,`customer_memo`,
- `create_time`,`update_time`,
- `order_pay_status`,
- `order_prod_type`,`order_status`,
- `customer_name`,`customer_mobile`,`customer_id_type`,`customer_id_no`,
- `order_book_status`,`PROD_START_STATION_TIME_MINUTES`,`parent_order_id`,`prod_id`,`parent_prod_id`,`prod_name`,`parent_prod_name`,`order_price`,`run_date`,`order_pay_main_id`,`outside_sale_org_id`,`outside_order_no`,`main_create_user_id`)
- values ('".$id."','"
- .$order_id."','{$order_customer_memo}',
- '".$create_time."','".$update_time."',
- '0','258','".$pay_status."','
- ".$cust_name."','".$cust_phone."','".$id_type."','".$customer_id."',
- '0','0','".$id_p."','".$info['387543']['prod_id']."','".$info_p['prod_id']."','".$info['387543']['prod_name']."','".$info_p['prod_name']."','".$tic_info['price'][4]."','".$date."','".$pay_main_id."','".$order_from_org_id."','{$outside_no}','".$user_id."')";
- for_insert($sql);
- }
- break;
- case 'D2':
- for($i=1;$i<=$v;$i++){
- $id =$order_id =getUniqeId();
- $sql = " insert into order_main
- (`id`,
- `order_id`,`customer_memo`,
- `create_time`,`update_time`,
- `order_pay_status`,
- `order_prod_type`,`order_status`,
- `customer_name`,`customer_mobile`,`customer_id_type`,`customer_id_no`,
- `order_book_status`,`PROD_START_STATION_TIME_MINUTES`,`parent_order_id`,`prod_id`,`parent_prod_id`,`prod_name`,`parent_prod_name`,`order_price`,`run_date`,`order_pay_main_id`,`outside_sale_org_id`,`outside_order_no`,`main_create_user_id`)
- values ('".$id."','"
- .$order_id."','{$order_customer_memo}',
- '".$create_time."','".$update_time."',
- '0','258','".$pay_status."','
- ".$cust_name."','".$cust_phone."','".$id_type."','".$customer_id."',
- '0','0','".$id_p."','".$info['387541']['prod_id']."','".$info_p['prod_id']."','".$info['387541']['prod_name']."','".$info_p['prod_name']."','".$tic_info['price'][3]."','".$date."','".$pay_main_id."','".$order_from_org_id."','{$outside_no}','".$user_id."')";
- for_insert($sql);
- }
- break;
- case 'O2':
- for($i=1;$i<=$v;$i++){
- $id =$order_id =getUniqeId();
- $sql = " insert into order_main
- (`id`,
- `order_id`,`customer_memo`,
- `create_time`,`update_time`,
- `order_pay_status`,
- `order_prod_type`,`order_status`,
- `customer_name`,`customer_mobile`,`customer_id_type`,`customer_id_no`,
- `order_book_status`,`PROD_START_STATION_TIME_MINUTES`,`parent_order_id`,`prod_id`,`parent_prod_id`,`prod_name`,`parent_prod_name`,`order_price`,`run_date`,`order_pay_main_id`,`outside_sale_org_id`,`outside_order_no`,`main_create_user_id`)
- values ('".$id."','"
- .$order_id."','{$order_customer_memo}',
- '".$create_time."','".$update_time."',
- '0','258','".$pay_status."','
- ".$cust_name."','".$cust_phone."','".$id_type."','".$customer_id."',
- '0','0','".$id_p."','".$info['387542']['prod_id']."','".$info_p['prod_id']."','".$info['387542']['prod_name']."','".$info_p['prod_name']."','".$tic_info['price'][5]."','".$date."','".$pay_main_id."','".$order_from_org_id."','{$outside_no}','".$user_id."')";
- for_insert($sql);
- }
- break;
- }
- }
- }
- function for_insert($sql){
- $pdo = conn();
- $re = $pdo->exec($sql);
- if($re==0){
- echo json_encode(array("code" => 1, "info" => $sql));
- exit ;
- }
- }
- // $json=array();
- // $code =0;
- // $info = 0;
- // $massge = 'success';
- // $list = "";
- // $json['code'] = $code;
- // $json['info'] = $info;
- // $json['massge'] = $massge;
- // $json['list'] = $list;
- $list =array();
- $list['type'] = $info_p['prod_name'];
- $list['date'] = $date;
- $list['desc'] = $return_info;
- $list['price'] = $price;
- $list['name'] = $cust_name;
- $list['phone'] = $cust_phone;
- $list['order_id'] = $id_p;
-
- $return_true_buy = true_buy_disney($return_no);
- if( $return_true_buy == 0 ) {
- echo json_encode(array("code" => 1, 'order_id' => $id_p, "info" => "最终确认失败,请检查自在余额。自在订单号:".$return_no));
- } else {
- echo json_encode(array("code" => 0, 'order_id' => $id_p, "info" => date('H:i:s', time()), 'ifdisney' => 1, "list" => $list));
- }
- exit ;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|