|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- /*
- * wechat 2.0
- * Copyright (c) 2016 yixi wei http://zhizhuchuxing.com/
- * Date: 2016.7.12
- * Something is to pay QQ1062140302
- */
- if (ALLOW_ORIGIN)
- header("Access-Control-Allow-Origin:*");
- date_default_timezone_set('PRC');
- //require_once '../../zz_wxsct/Common/Mysql.php';
- $user_id =1;//$_COOKIE['user_id'] ;//getUserId();
- $back_order_id='0';
- if($_POST){
- $method = isset($_POST['iffirst']) ? $_POST['iffirst'] : "2";
- $order_id = isset($_POST['order_id']) ? $_POST['order_id'] : "452067";
- $ifback = "0";
- $to_order_id=$order_id;
- $pdo = conn();
- $sql_s = "select * from to_from where to_orderid=".$order_id." or back_orderid=".$order_id;
- $result=$pdo->query($sql_s);
- $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
- $result -> closeCursor();
- if($rowset){
- $ifback=1;
- $to_order_id = $rowset[0]['to_orderid'];
- $back_order_id = $rowset[0]['back_orderid'];
- if ($method == "2") {
- $list['to'] = Find($to_order_id);
- $time_cut = strtotime($list['to']['run_time'])-time();
- $list['back'] = Find($back_order_id);
- $time_cut2 = strtotime($list['back']['run_time'])-time();
- if($time_cut<=1800){
-
- $code ='1';
- $info = '开车前30分钟禁止退票';
- $massge = '开车前30分钟禁止退票,请刷新页面确认时间';
- $list = "";
- }else{
-
- $sql = "CALL SP_CANCEL_ORDER(" . 0 . "," . $to_order_id . ")";
- $result = $pdo -> query($sql);
- $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
- $result -> closeCursor();
- $sql = "CALL SP_CANCEL_ORDER(" . 0 . "," . $back_order_id . ")";
- $result2 = $pdo -> query($sql);
- $rowset2 = $result2 -> fetchAll(PDO::FETCH_ASSOC);
- if(!isset($rowset[0]['errorinfo'])){
- $result -> closeCursor();
- $sql = " insert into order_refund(`order_id`,`price`,`pay_serial_number`) values(".$back_order_id.",".($list['back']['order_price']+$list['to']['order_price']).",'".$list['back']['pay_num']."')";
- $result = $pdo -> query($sql);
-
-
- $code = '0';
- $info = 'success';
- $massge = '成功';
- }else{
- $code = '1';
- $info = $rowset[0]['errorinfo'];
- $massge = $rowset[0]['errorinfo'];
- }
- }
-
-
- }
- // $time_cut = time()-strtotime($list['to']['run_time']); ///时间在开场30分钟前可以退票
- }else{
- //单程情况
- if ($method == "2") {
- $pdo = conn();
- $list = Find($order_id);
- $time_cut = strtotime($list['run_time'])-time();
- if($time_cut<=1800){
- $code ='1';
- $info = 'fail';
- $massge = '开车前30分钟禁止退票';
- $list = "";
- }else{
-
- $sql = "CALL SP_CANCEL_ORDER(" . 0 . "," . $order_id . ")";
- $result = $pdo -> query($sql);
- $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
- $result -> closeCursor();
- if(!isset($rowset[0]['errorinfo'])){
- $sql = " insert into order_refund(`order_id`,`price`,`pay_serial_number`) values(".$order_id.",".$list['order_price'].",'".$list['pay_num']."')";
- $pdo ->query($sql);
- $code = '0';
- $info = 'success';
- $massge = '订单已取消';
- }else{
- $code = '1';
- $info =$rowset[0]['errorinfo'];
- $massge = $rowset[0]['errorinfo'];
- }
-
-
- }
-
- $result -> closeCursor();
- }
- //$time_cut = time()-strtotime($list['run_time']); ///时间在开场30分钟前可以退票
- }
-
- } else {
- $code ='1';
- $info = 'fail';
- $massge = '失败';
- $list = "";
- }
- $json['ifback'] =$ifback;
- $json['code'] = $code;
- $json['info'] = $massge;
- $json['order_id']=$to_order_id;
- $json['back_order_id']=$back_order_id;
-
-
-
- echo json_encode($json);
- die;
- function Find($order_id){
- $pdo= conn();
- $sql = "select order_description,order_price,order_pay_main_id "
- . "from order_main "
- . "where order_id=".$order_id;
- $result=$pdo->query($sql);
- $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
- $order_price = $rowset[0];//订单总价格 订单票的数量
- $sql = "SELECT DISTINCT
- order_description,parent_order_id,run_date,run_time,PROD_START_STATION_AREA_NAME,PROD_START_STATION_RES_NAME,PROD_END_STATION_AREA_NAME,PROD_END_STATION_RES_NAME
- FROM `order_main`
- where PARENT_ORDER_ID=".$order_id;
- $result=$pdo->query($sql);
- $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
- $order_station = $rowset[0];//订单来往地址 订单时间 订单好
- if(empty($order_station))
- return false;
- $array_order_desc=array();
-
- $arr_temp = explode('|',$order_price['order_description']);
- $arr=array();
- foreach ($arr_temp as $k=>$v2) {
- if(!empty($v2))
- $array_order_desc[]= explode (',', $v2); //订单票 * 数量
- }
- $list = array();
- //上海(黄浦旅游集散站) - 乌镇(西栅1号停车场)//反的数组
- $list['station'] = $order_station['PROD_START_STATION_AREA_NAME'].'('.$order_station['PROD_START_STATION_RES_NAME'].')'
- .'-'.$order_station['PROD_END_STATION_AREA_NAME'].'('.$order_station['PROD_END_STATION_RES_NAME'].')';
- $list['start_station']=$order_station['PROD_START_STATION_AREA_NAME'];
- $list['end_station']=$order_station['PROD_END_STATION_AREA_NAME'];
- $list['start_res_name'] = $order_station['PROD_START_STATION_RES_NAME'];
- $list['end_res_name'] = $order_station['PROD_END_STATION_RES_NAME'];
- $list['run_date'] = $order_station['run_date'];
- $list['run_time'] = $order_station['run_date'].' '.$order_station['run_time'];
- $list['count']='';
- foreach ($array_order_desc as $v){
- $list['count'] .= ' '.$v[0].' × '.$v[2];
- }
- $list['order_price'] = $order_price['order_price'];
- $sql = "select pay_serial_number from order_pay_detail where pay_main_id =".$order_price['order_pay_main_id'];
- $result=$pdo->query($sql);
- $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
- $list['pay_num'] = $rowset[0]['pay_serial_number'];
- return $list;
- }
|