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.
 
 
 
 

264 lines
9.8 KiB

  1. <?php
  2. if (ALLOW_ORIGIN)
  3. header("Access-Control-Allow-Origin:*");
  4. date_default_timezone_set('PRC');
  5. //require_once '../../Common/Mysql.php';
  6. $user_id = $_COOKIE['user_id'];//getUserId();
  7. define( "CS1_DOMAIN", "cs1.zhizhuchuxing.com" );
  8. $cancel_url = 'http://'.CS1_DOMAIN.'/api/submit-order/cancel-bus-order';
  9. if (!$user_id) {
  10. echo json_encode(array("code" => 1, "iflogin" => 1, "info" => "用户未登录"));
  11. exit;
  12. }
  13. //$_POST['iffirst']='';
  14. //if(isset($_POST['order_id'])){};
  15. //require_once '../../Common/Mysql.php';
  16. //$_POST['ifback']=0;
  17. $back_order_id = 0;
  18. if ($_POST || 1) {
  19. $method = isset($_POST['iffirst']) ? $_POST['iffirst'] : "1";
  20. $order_id = isset($_POST['order_id']) ? $_POST['order_id'] : "452074";
  21. $ifback = "0";
  22. $to_order_id = $order_id;
  23. //$order_id=204351;
  24. $pdo = conn();
  25. $sql_s = "select * from to_from where to_orderid=" . $order_id . " or back_orderid=" . $order_id;
  26. $result = $pdo->query($sql_s);
  27. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  28. if ($rowset) {
  29. $ifback = 1;
  30. $to_order_id = $rowset[0]['to_orderid'];
  31. $back_order_id = $rowset[0]['back_orderid'];
  32. if ($method == "2") {
  33. // $sql = "CALL SP_CANCEL_ORDER(" . 0 . "," . $to_order_id . ")";
  34. // $result = $pdo->query($sql);
  35. // $return = $result->fetchAll(PDO::FETCH_ASSOC);
  36. //
  37. //
  38. // $sql = "CALL SP_CANCEL_ORDER(" . 0 . "," . $back_order_id . ")";
  39. // $result = $pdo->query($sql);
  40. // $return2 = $result->fetchAll(PDO::FETCH_ASSOC);
  41. $send_post_data = array(
  42. "order_id" => $to_order_id,
  43. "user_id" => $user_id,
  44. "if_link" => 0,
  45. "cancel_reason" => "分销商取消",
  46. 'opera_platform' => 'SFX系统'
  47. );
  48. $temp=httpRequest($cancel_url,$send_post_data);
  49. $result = json_decode($temp, true);
  50. $send_post_data2 = array(
  51. "order_id" => $back_order_id,
  52. "user_id" => $user_id,
  53. "if_link" => 0,
  54. "cancel_reason" => "分销商取消",
  55. 'opera_platform' => 'SFX系统'
  56. );
  57. $temp=httpRequest($cancel_url,$send_post_data2);
  58. //
  59. // if(isset($return[0]['@errorcode']) && $return[0]['@errorcode']=='-1'){
  60. // $code =1;
  61. // $info = 'fail';
  62. // $massge = '失败';
  63. // $list = "";
  64. // }else{
  65. $list['to'] = Find($to_order_id);
  66. $list['back'] = Find($back_order_id);
  67. if ($list['to'] && Find($back_order_id)) {
  68. if ( false != $result && isset($result['code']) && $result['code'] == 0) {
  69. $result->closeCursor();
  70. $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'] . "')";
  71. $result = $pdo->query($sql);
  72. $result->closeCursor();
  73. //取消订单
  74. // $post_data['order_id'] = $to_order_id . ',' . $back_order_id;
  75. // $post_data['order_status'] = 460;
  76. // httpRequest("http://cs.zhizhuchuxing.com/st-xm/Api/add_order_status_log.php", $post_data);
  77. $code = 0;
  78. $info = 'success';
  79. $massge = '订单已取消';
  80. $list = $list;
  81. } else {
  82. $code = 1;
  83. $info = 'fail';
  84. $massge = '失败';
  85. $list = "";
  86. }
  87. }
  88. // }
  89. $result->closeCursor();
  90. } else {
  91. $list['to'] = Find($to_order_id);
  92. $time_cut = strtotime($list['to']['run_time']) - time();
  93. $list['back'] = Find($back_order_id);
  94. if ($list['to'] && Find($back_order_id)) {
  95. $code = 0;
  96. $info = 'success';
  97. $massge = '成功';
  98. $list = $list;
  99. if ($time_cut <= 1800) {
  100. $code = 1;
  101. $info = 'fail';
  102. $massge = '开车前30分钟禁止退票,请刷新页面确认时间';
  103. $list = "";
  104. }
  105. } else {
  106. $code = 1;
  107. $info = 'fail';
  108. $massge = '失败';
  109. $list = "";
  110. }
  111. }
  112. // $time_cut = strtotime($list['to']['run_time'])-time(); ///时间在开场30分钟前可以退票
  113. } else {
  114. //单程情况
  115. if ($method == "2") {
  116. $pdo = conn();
  117. // $sql = "CALL SP_CANCEL_ORDER(" . 0 . "," . $order_id . ")";
  118. // $result = $pdo->query($sql);
  119. // $return = $result->fetchAll(PDO::FETCH_ASSOC);
  120. // if(isset($return[0]['@errorcode']) && $return[0]['@errorcode']=='-1'){
  121. // $code =1;
  122. // $info = 'fail';
  123. // $massge = '失败';
  124. // $list = "";
  125. // }else{
  126. $send_post_data = array(
  127. "order_id" => $order_id,
  128. "user_id" => $user_id,
  129. "if_link" => 0,
  130. "cancel_reason" => "分销商取消",
  131. 'opera_platform' => 'SFX系统'
  132. );
  133. $temp=httpRequest($cancel_url,$send_post_data);
  134. $result = json_decode($temp, true);
  135. $list = Find($order_id);
  136. if (false != $result && isset($result['code']) && $result['code'] == 0) {
  137. $result->closeCursor();
  138. $sql = " insert into order_refund(`order_id`,`price`,`pay_serial_number`) values(" . $order_id . "," . $list['order_price'] . ",'" . $list['pay_num'] . "')";
  139. $result = $pdo->query($sql);
  140. $result->closeCursor();
  141. //取消订单
  142. $post_data['order_id'] = $order_id;
  143. $post_data['order_status'] = 460;
  144. httpRequest("http://cs.zhizhuchuxing.com/st-xm/Api/add_order_status_log.php", $post_data);
  145. $code = 0;
  146. $info = 'success';
  147. $massge = '订单已取消';
  148. $list = $list;
  149. } else {
  150. $code = 1;
  151. $info = 'fail';
  152. $massge = '失败';
  153. $list = "";
  154. }
  155. // }
  156. } else {
  157. if ($list = Find($order_id)) {
  158. $code = 0;
  159. $info = 'success';
  160. $massge = '成功';
  161. $list = $list;
  162. $time_cut = strtotime($list['run_time']) - time();
  163. if ($time_cut <= 1800) {
  164. $code = 1;
  165. $info = 'fail';
  166. $massge = '开车前30分钟禁止退票';
  167. $list = "";
  168. }
  169. } else {
  170. $code = 1;
  171. $info = 'fail';
  172. $massge = '失败';
  173. $list = "";
  174. }
  175. }
  176. //$time_cut = strtotime($list['run_time'])-time(); ///时间在开场30分钟前可以退票
  177. }
  178. } else {
  179. $code = 1;
  180. $info = 'fail';
  181. $massge = '失败';
  182. $list = "";
  183. }
  184. $json['ifback'] = $ifback;
  185. $json['code'] = $code;
  186. $json['info'] = $massge;
  187. $json['order_id'] = $to_order_id;
  188. $json['back_order_id'] = $back_order_id;
  189. $json['massge'] = $massge;
  190. $json['list'] = $list;
  191. echo json_encode($json);
  192. die;
  193. function Find($order_id)
  194. {
  195. $pdo = conn();
  196. $sql = "select order_description,order_price,order_pay_main_id "
  197. . "from order_main "
  198. . "where order_id=" . $order_id;
  199. $result = $pdo->query($sql);
  200. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  201. $order_price = $rowset[0];//订单总价格 订单票的数量
  202. $sql = "SELECT DISTINCT
  203. 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
  204. FROM `order_main`
  205. where PARENT_ORDER_ID=" . $order_id;
  206. $result = $pdo->query($sql);
  207. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  208. $order_station = $rowset[0];//订单来往地址 订单时间 订单好
  209. if (empty($order_station))
  210. return false;
  211. $array_order_desc = array();
  212. $arr_temp = explode('|', $order_price['order_description']);
  213. $arr = array();
  214. foreach ($arr_temp as $k => $v2) {
  215. if (!empty($v2))
  216. $array_order_desc[] = explode(',', $v2); //订单票 * 数量
  217. }
  218. $list = array();
  219. //上海(黄浦旅游集散站) - 乌镇(西栅1号停车场)//反的数组
  220. $list['station'] = $order_station['PROD_START_STATION_AREA_NAME'] . '(' . $order_station['PROD_START_STATION_RES_NAME'] . ')'
  221. . '-' . $order_station['PROD_END_STATION_AREA_NAME'] . '(' . $order_station['PROD_END_STATION_RES_NAME'] . ')';
  222. $list['start_station'] = $order_station['PROD_START_STATION_AREA_NAME'];
  223. $list['end_station'] = $order_station['PROD_END_STATION_AREA_NAME'];
  224. $list['start_res_name'] = $order_station['PROD_START_STATION_RES_NAME'];
  225. $list['end_res_name'] = $order_station['PROD_END_STATION_RES_NAME'];
  226. $list['run_date'] = $order_station['run_date'];
  227. $list['run_time'] = $order_station['run_date'] . ' ' . $order_station['run_time'];
  228. $list['count'] = '';
  229. foreach ($array_order_desc as $v) {
  230. if( !isset($v[2]) ) {
  231. continue;
  232. }
  233. $list['count'] .= ' ' . $v[0] . ' × ' . $v[2];
  234. }
  235. $list['order_price'] = $order_price['order_price'];
  236. $sql = "select pay_serial_number from order_pay_detail where pay_main_id =" . $order_price['order_pay_main_id'];
  237. $result = $pdo->query($sql);
  238. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  239. $list['pay_num'] = $rowset[0]['pay_serial_number'];
  240. return $list;
  241. }