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.
 
 
 
 

252 lines
10 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. $result->closeCursor();
  29. if ($rowset) {
  30. $ifback = 1;
  31. $to_order_id = $rowset[0]['to_orderid'];
  32. $back_order_id = $rowset[0]['back_orderid'];
  33. if ($method == "0") {
  34. // $sql = "CALL SP_CANCEL_ORDER(" . 0 . "," . $to_order_id . ")";
  35. // $result = $pdo->query($sql);
  36. // $return = $result->fetchAll(PDO::FETCH_ASSOC);
  37. //
  38. //
  39. // $sql = "CALL SP_CANCEL_ORDER(" . 0 . "," . $back_order_id . ")";
  40. // $result = $pdo->query($sql);
  41. // $return2 = $result->fetchAll(PDO::FETCH_ASSOC);
  42. $send_post_data = array(
  43. "order_id" => $to_order_id,
  44. "user_id" => $user_id,
  45. "if_link" => 0,
  46. "cancel_reason" => "分销商取消",
  47. 'opera_platform' => 'SFX系统'
  48. );
  49. $temp=httpRequest($cancel_url,$send_post_data);
  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. $list['to'] = Find($to_order_id);
  59. $list['back'] = Find($back_order_id);
  60. if ($list['to'] && Find($back_order_id)) {
  61. $result->closeCursor();
  62. $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'] . "')";
  63. $result = $pdo->query($sql);
  64. $result->closeCursor();
  65. //取消订单
  66. // $post_data['order_id'] = $to_order_id . ',' . $back_order_id;
  67. // $post_data['order_status'] = 460;
  68. // httpRequest("http://cs.zhizhuchuxing.com/st-xm/Api/add_order_status_log.php", $post_data);
  69. //
  70. // $pdo_insert = conn();
  71. // $current_time = date("Y-m-d H:i:s");
  72. // $cancel_reason = "取消原因:分销商取消";
  73. // $sql = "insert into order_opera_log(order_id,opera_user_id,opera_type,opera_time,opera_detail,opera_platform) VALUES ({$to_order_id},$user_id,2,'{$current_time}','{$cancel_reason}','分销系统')";
  74. // $result = $pdo_insert->exec($sql);
  75. // $sql = "insert into order_opera_log(order_id,opera_user_id,opera_type,opera_time,opera_detail,opera_platform) VALUES ({$back_order_id},$user_id,2,'{$current_time}','{$cancel_reason}','分销系统')";
  76. // $result = $pdo_insert->exec($sql);
  77. $code = 0;
  78. $info = 'success';
  79. $massge = '订单已取消';
  80. $list = $list;
  81. }
  82. // }
  83. } else {
  84. $list['to'] = Find($to_order_id);
  85. $time_cut = strtotime($list['to']['run_time']) - time();
  86. $list['back'] = Find($back_order_id);
  87. if ($list['to'] && Find($back_order_id)) {
  88. $code = 0;
  89. $info = 'success';
  90. $massge = '成功';
  91. $list = $list;
  92. if ($time_cut <= 1800) {
  93. $code = 1;
  94. $info = 'fail';
  95. $massge = '开车前30分钟禁止退票,请刷新页面确认时间';
  96. $list = "";
  97. }
  98. } else {
  99. $code = 1;
  100. $info = 'fail';
  101. $massge = '失败';
  102. $list = "";
  103. }
  104. }
  105. // $time_cut = strtotime($list['to']['run_time'])-time(); ///时间在开场30分钟前可以退票
  106. } else {
  107. //单程情况
  108. if ($method == "0") {
  109. $pdo = conn();
  110. // $sql = "CALL SP_CANCEL_ORDER(" . 0 . "," . $order_id . ")";
  111. // $result = $pdo->query($sql);
  112. // $return = $result->fetchAll(PDO::FETCH_ASSOC);
  113. // if(isset($return[0]['@errorcode']) && $return[0]['@errorcode']=='-1'){
  114. // $code =1;
  115. // $info = 'fail';
  116. // $massge = '失败';
  117. // $list = "";
  118. // }else{
  119. $send_post_data = array(
  120. "order_id" => $order_id,
  121. "user_id" => $user_id,
  122. "if_link" => 0,
  123. "cancel_reason" => "分销商取消",
  124. 'opera_platform' => 'SFX系统'
  125. );
  126. $temp=httpRequest($cancel_url,$send_post_data);
  127. $list = Find($order_id);
  128. //
  129. // $result->closeCursor();
  130. $sql = " insert into order_refund(`order_id`,`price`,`pay_serial_number`) values(" . $order_id . "," . $list['order_price'] . ",'" . $list['pay_num'] . "')";
  131. $result = $pdo->query($sql);
  132. $result->closeCursor();
  133. //取消订单
  134. // $post_data['order_id'] = $order_id;
  135. // $post_data['order_status'] = 460;
  136. // httpRequest("http://cs.zhizhuchuxing.com/st-xm/Api/add_order_status_log.php", $post_data);
  137. //
  138. // $pdo_insert = conn();
  139. // $current_time = date("Y-m-d H:i:s");
  140. // $cancel_reason = "取消原因:分销商取消";
  141. // $sql = "insert into order_opera_log(order_id,opera_user_id,opera_type,opera_time,opera_detail,opera_platform) VALUES ({$order_id},$user_id,2,'{$current_time}','{$cancel_reason}','分销系统')";
  142. // $result = $pdo_insert->exec($sql);
  143. $code = 0;
  144. $info = 'success';
  145. $massge = '订单已取消';
  146. $list = $list;
  147. // }
  148. } else {
  149. if ($list = Find($order_id)) {
  150. $code = 0;
  151. $info = 'success';
  152. $massge = '成功';
  153. $list = $list;
  154. $time_cut = strtotime($list['run_time']) - time();
  155. if ($time_cut <= 1800) {
  156. $code = 1;
  157. $info = 'fail';
  158. $massge = '开车前30分钟禁止退票';
  159. $list = "";
  160. }
  161. } else {
  162. $code = 1;
  163. $info = 'fail';
  164. $massge = '失败';
  165. $list = "";
  166. }
  167. }
  168. //$time_cut = strtotime($list['run_time'])-time(); ///时间在开场30分钟前可以退票
  169. }
  170. } else {
  171. $code = 1;
  172. $info = 'fail';
  173. $massge = '失败';
  174. $list = "";
  175. }
  176. $json['ifback'] = $ifback;
  177. $json['code'] = $code;
  178. $json['info'] = $massge;
  179. $json['order_id'] = $to_order_id;
  180. $json['back_order_id'] = $back_order_id;
  181. $json['massge'] = $massge;
  182. $json['list'] = $list;
  183. echo json_encode($json);
  184. die;
  185. function Find($order_id)
  186. {
  187. $pdo = conn();
  188. $sql = "select order_description,order_price,order_pay_main_id "
  189. . "from order_main "
  190. . "where order_id=" . $order_id;
  191. $result = $pdo->query($sql);
  192. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  193. $order_price = $rowset[0];//订单总价格 订单票的数量
  194. $sql = "SELECT DISTINCT
  195. 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
  196. FROM `order_main`
  197. where PARENT_ORDER_ID=" . $order_id;
  198. $result = $pdo->query($sql);
  199. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  200. $order_station = $rowset[0];//订单来往地址 订单时间 订单好
  201. if (empty($order_station))
  202. return false;
  203. $array_order_desc = array();
  204. $arr_temp = explode('|', $order_price['order_description']);
  205. $arr = array();
  206. foreach ($arr_temp as $k => $v2) {
  207. if (!empty($v2))
  208. $array_order_desc[] = explode(',', $v2); //订单票 * 数量
  209. }
  210. $list = array();
  211. //上海(黄浦旅游集散站) - 乌镇(西栅1号停车场)//反的数组
  212. $list['station'] = $order_station['PROD_START_STATION_AREA_NAME'] . '(' . $order_station['PROD_START_STATION_RES_NAME'] . ')'
  213. . '-' . $order_station['PROD_END_STATION_AREA_NAME'] . '(' . $order_station['PROD_END_STATION_RES_NAME'] . ')';
  214. $list['start_station'] = $order_station['PROD_START_STATION_AREA_NAME'];
  215. $list['end_station'] = $order_station['PROD_END_STATION_AREA_NAME'];
  216. $list['start_res_name'] = $order_station['PROD_START_STATION_RES_NAME'];
  217. $list['end_res_name'] = $order_station['PROD_END_STATION_RES_NAME'];
  218. $list['run_date'] = $order_station['run_date'];
  219. $list['run_time'] = $order_station['run_date'] . ' ' . $order_station['run_time'];
  220. $list['count'] = '';
  221. foreach ($array_order_desc as $v) {
  222. if( !isset($v[2]) ) { continue; }
  223. $list['count'] .= ' ' . $v[0] . ' × ' . $v[2];
  224. }
  225. $list['order_price'] = $order_price['order_price'];
  226. $sql = "select pay_serial_number from order_pay_detail where pay_main_id =" . $order_price['order_pay_main_id'];
  227. $result = $pdo->query($sql);
  228. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  229. $list['pay_num'] = $rowset[0]['pay_serial_number'];
  230. return $list;
  231. }