You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

refund.php 6.5 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /*
  3. * wechat 2.0
  4. * Copyright (c) 2016 yixi wei http://zhizhuchuxing.com/
  5. * Date: 2016.7.12
  6. * Something is to pay QQ1062140302
  7. */
  8. if (ALLOW_ORIGIN)
  9. header("Access-Control-Allow-Origin:*");
  10. date_default_timezone_set('PRC');
  11. //require_once '../../zz_wxsct/Common/Mysql.php';
  12. $user_id =1;//$_COOKIE['user_id'] ;//getUserId();
  13. $back_order_id='0';
  14. if($_POST){
  15. $method = isset($_POST['iffirst']) ? $_POST['iffirst'] : "2";
  16. $order_id = isset($_POST['order_id']) ? $_POST['order_id'] : "452067";
  17. $ifback = "0";
  18. $to_order_id=$order_id;
  19. $pdo = conn();
  20. $sql_s = "select * from to_from where to_orderid=".$order_id." or back_orderid=".$order_id;
  21. $result=$pdo->query($sql_s);
  22. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  23. $result -> closeCursor();
  24. if($rowset){
  25. $ifback=1;
  26. $to_order_id = $rowset[0]['to_orderid'];
  27. $back_order_id = $rowset[0]['back_orderid'];
  28. if ($method == "2") {
  29. $list['to'] = Find($to_order_id);
  30. $time_cut = strtotime($list['to']['run_time'])-time();
  31. $list['back'] = Find($back_order_id);
  32. $time_cut2 = strtotime($list['back']['run_time'])-time();
  33. if($time_cut<=1800){
  34. $code ='1';
  35. $info = '开车前30分钟禁止退票';
  36. $massge = '开车前30分钟禁止退票,请刷新页面确认时间';
  37. $list = "";
  38. }else{
  39. $sql = "CALL SP_CANCEL_ORDER(" . 0 . "," . $to_order_id . ")";
  40. $result = $pdo -> query($sql);
  41. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  42. $result -> closeCursor();
  43. $sql = "CALL SP_CANCEL_ORDER(" . 0 . "," . $back_order_id . ")";
  44. $result2 = $pdo -> query($sql);
  45. $rowset2 = $result2 -> fetchAll(PDO::FETCH_ASSOC);
  46. if(!isset($rowset[0]['errorinfo'])){
  47. $result -> closeCursor();
  48. $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']."')";
  49. $result = $pdo -> query($sql);
  50. $code = '0';
  51. $info = 'success';
  52. $massge = '成功';
  53. }else{
  54. $code = '1';
  55. $info = $rowset[0]['errorinfo'];
  56. $massge = $rowset[0]['errorinfo'];
  57. }
  58. }
  59. }
  60. // $time_cut = time()-strtotime($list['to']['run_time']); ///时间在开场30分钟前可以退票
  61. }else{
  62. //单程情况
  63. if ($method == "2") {
  64. $pdo = conn();
  65. $list = Find($order_id);
  66. $time_cut = strtotime($list['run_time'])-time();
  67. if($time_cut<=1800){
  68. $code ='1';
  69. $info = 'fail';
  70. $massge = '开车前30分钟禁止退票';
  71. $list = "";
  72. }else{
  73. $sql = "CALL SP_CANCEL_ORDER(" . 0 . "," . $order_id . ")";
  74. $result = $pdo -> query($sql);
  75. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  76. $result -> closeCursor();
  77. if(!isset($rowset[0]['errorinfo'])){
  78. $sql = " insert into order_refund(`order_id`,`price`,`pay_serial_number`) values(".$order_id.",".$list['order_price'].",'".$list['pay_num']."')";
  79. $pdo ->query($sql);
  80. $code = '0';
  81. $info = 'success';
  82. $massge = '订单已取消';
  83. }else{
  84. $code = '1';
  85. $info =$rowset[0]['errorinfo'];
  86. $massge = $rowset[0]['errorinfo'];
  87. }
  88. }
  89. $result -> closeCursor();
  90. }
  91. //$time_cut = time()-strtotime($list['run_time']); ///时间在开场30分钟前可以退票
  92. }
  93. } else {
  94. $code ='1';
  95. $info = 'fail';
  96. $massge = '失败';
  97. $list = "";
  98. }
  99. $json['ifback'] =$ifback;
  100. $json['code'] = $code;
  101. $json['info'] = $massge;
  102. $json['order_id']=$to_order_id;
  103. $json['back_order_id']=$back_order_id;
  104. echo json_encode($json);
  105. die;
  106. function Find($order_id){
  107. $pdo= conn();
  108. $sql = "select order_description,order_price,order_pay_main_id "
  109. . "from order_main "
  110. . "where order_id=".$order_id;
  111. $result=$pdo->query($sql);
  112. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  113. $order_price = $rowset[0];//订单总价格 订单票的数量
  114. $sql = "SELECT DISTINCT
  115. 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
  116. FROM `order_main`
  117. where PARENT_ORDER_ID=".$order_id;
  118. $result=$pdo->query($sql);
  119. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  120. $order_station = $rowset[0];//订单来往地址 订单时间 订单好
  121. if(empty($order_station))
  122. return false;
  123. $array_order_desc=array();
  124. $arr_temp = explode('|',$order_price['order_description']);
  125. $arr=array();
  126. foreach ($arr_temp as $k=>$v2) {
  127. if(!empty($v2))
  128. $array_order_desc[]= explode (',', $v2); //订单票 * 数量
  129. }
  130. $list = array();
  131. //上海(黄浦旅游集散站) - 乌镇(西栅1号停车场)//反的数组
  132. $list['station'] = $order_station['PROD_START_STATION_AREA_NAME'].'('.$order_station['PROD_START_STATION_RES_NAME'].')'
  133. .'-'.$order_station['PROD_END_STATION_AREA_NAME'].'('.$order_station['PROD_END_STATION_RES_NAME'].')';
  134. $list['start_station']=$order_station['PROD_START_STATION_AREA_NAME'];
  135. $list['end_station']=$order_station['PROD_END_STATION_AREA_NAME'];
  136. $list['start_res_name'] = $order_station['PROD_START_STATION_RES_NAME'];
  137. $list['end_res_name'] = $order_station['PROD_END_STATION_RES_NAME'];
  138. $list['run_date'] = $order_station['run_date'];
  139. $list['run_time'] = $order_station['run_date'].' '.$order_station['run_time'];
  140. $list['count']='';
  141. foreach ($array_order_desc as $v){
  142. $list['count'] .= ' '.$v[0].' × '.$v[2];
  143. }
  144. $list['order_price'] = $order_price['order_price'];
  145. $sql = "select pay_serial_number from order_pay_detail where pay_main_id =".$order_price['order_pay_main_id'];
  146. $result=$pdo->query($sql);
  147. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  148. $list['pay_num'] = $rowset[0]['pay_serial_number'];
  149. return $list;
  150. }