Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

cancel_order.php 12 KiB

3 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <?php
  2. require_once '../st-xm/Common/Mysql.php';
  3. require_once '../st-xm/Common/dictionary.php';
  4. header("Access-Control-Allow-Origin:*");
  5. //test
  6. //$_POST['auth_code'] = "abcdefg";
  7. //$_POST['ctrip_order_no'] = "abcdefg1234";
  8. //end of test
  9. $auth_code=isset($_POST['auth_code'])? $_POST['auth_code']:false;
  10. $ctrip_order_no=isset($_POST['ctrip_order_no'])? $_POST['ctrip_order_no']:false;
  11. $return_data = array();
  12. $return_data['code']='201';
  13. $cancel_limit_time = date("Y-m-d H:i",strtotime("+30 minutes"));
  14. if( $auth_code == false || $ctrip_order_no == false ) {
  15. $return_data['code']='401';
  16. echo json_encode($return_data);
  17. exit();
  18. }
  19. $pdo=conn1();
  20. $sql=" SELECT user_name,user_psd,user_auth_code FROM api_auth_code WHERE user_auth_code='".$auth_code."' ";
  21. $result=$pdo->query($sql);
  22. $rowset=$result->fetchAll();
  23. $result->closeCursor();
  24. if( false == $rowset ) {
  25. $return_data['code']='400';
  26. echo json_encode($return_data);
  27. exit();
  28. }
  29. $sql1 = " SELECT * FROM outside_submit_order WHERE outside_order_no = '{$ctrip_order_no}' ";
  30. $result=$pdo->query($sql1);
  31. $result_array=$result->fetchAll();
  32. $result->closeCursor();
  33. if( false == $result_array ) {
  34. $return_data['code']='601';
  35. $return_data['msg']='该订单并未下单成功';
  36. echo json_encode($return_data);
  37. exit();
  38. }
  39. $outside_submit_order_info = $result_array[0];
  40. $submit_status = $result_array[0]["submit_status"];
  41. if( $submit_status == 0 ) {
  42. $return_data['code']='601';
  43. $return_data['msg']='该订单并未下单成功';
  44. echo json_encode($return_data);
  45. exit();
  46. } else if( $submit_status == 99 ) {
  47. $return_data['code']='801';
  48. $return_data['msg']='该订单号已在之前的处理中退单成功';
  49. echo json_encode($return_data);
  50. exit();
  51. }
  52. $sql1 = " SELECT * FROM order_main WHERE OUTSIDE_ORDER_NO = '{$ctrip_order_no}' AND ORDER_STATUS != 238 ";
  53. $result=$pdo->query($sql1);
  54. $result_array=$result->fetchAll();
  55. $result->closeCursor();
  56. $order_array = array();
  57. $run_id_array = array();
  58. $outside_run_flag = false;
  59. foreach( $result_array as $order_info ) {
  60. if( $order_info["PROD_ID"] == 380001 ) {
  61. $outside_run_flag = true;
  62. }
  63. if ($order_info["PARENT_ORDER_ID"] == 0) {
  64. $order_array[$order_info["ORDER_ID"]] = $order_info;
  65. } else {
  66. if (!in_array($order_info["RUN_ID"], $run_id_array)) {
  67. $run_id_array[] = $order_info["RUN_ID"];
  68. }
  69. }
  70. }
  71. if( false == $outside_run_flag ) {
  72. $cancel_limit_time = date("Y-m-d H:i",strtotime("+24 hours"));//test
  73. $sql2 = " SELECT * FROM run_main WHERE RUN_ID IN (" . implode(",", $run_id_array) . ") ";
  74. $result = $pdo->query($sql2);
  75. $result_array = $result->fetchAll();
  76. $result->closeCursor();
  77. if ($result_array == false) {
  78. $return_data['code'] = '501';
  79. $return_data['msg'] = '该班次为无效班次';
  80. echo json_encode($return_data);
  81. exit();
  82. }
  83. foreach ($result_array as $run_main_info) {
  84. if ($run_main_info["RUN_STATUS"] != 138) {
  85. $return_data['code'] = '501';
  86. $return_data['msg']='该班次已无法退单,详细情况请联系客服。';
  87. echo json_encode($return_data);
  88. exit();
  89. }
  90. $run_start_time = $run_main_info["RUN_DATE"] . " " . $run_main_info["RUN_TIME"];
  91. if ($run_start_time <= $cancel_limit_time) {
  92. $return_data['code'] = '501';
  93. $return_data['msg'] = '该班次已过最后退票截止时间(发车前24小时)无法退单';
  94. echo json_encode($return_data);
  95. exit();
  96. }
  97. }
  98. $run_main_info = $result_array[0];
  99. } else {
  100. $cancel_limit_time = date("Y-m-d H:i",strtotime("+24 hours"));
  101. $sql2 = " SELECT * FROM outside_run WHERE prod_code = '{$outside_submit_order_info["prod_id"]}' ";
  102. $result = $pdo->query($sql2);
  103. $result_array = $result->fetchAll();
  104. $result->closeCursor();
  105. $run_main_info = $result_array[0];
  106. $run_start_time = $run_main_info["start_date"] . " " . $run_main_info["start_time"];
  107. if ($run_start_time <= $cancel_limit_time) {
  108. $return_data['code'] = '501';
  109. $return_data['msg'] = '该班次已过最后退票截止时间(发车前24小时)无法退单';
  110. echo json_encode($return_data);
  111. exit();
  112. }
  113. }
  114. $current_time = date("Y-m-d H:i:s");
  115. $user_id = 1;
  116. foreach( $order_array as $order_main_info ) {
  117. $order_id = $order_main_info["ORDER_ID"];
  118. if( isset($run_main_info['PROD_ID']) && in_array($run_main_info['PROD_ID'], $__ary_special_line_array) ){
  119. $result = post2('wx.zhizhuchuxing.com/ZZDZ2/application/custom_made/control.php',array('type' =>'order_refund','order_id'=>$order_id));
  120. $return_array = json_decode( $result, true );
  121. if($return_array["code"] == 0 ){
  122. $tel = "13816608252";
  123. $name = "";
  124. $content = "订单号:【" . $order_id . "】已被取消(定制巴士)";
  125. $response = sendTelMessage($tel, $name, $content, $order_id);
  126. //cancel log
  127. $pdo_insert2 = conn1();
  128. $cancel_reason = "取消原因:渠道取消";
  129. $sql = "insert into order_opera_log(order_id,opera_user_id,opera_type,opera_time,opera_detail,opera_platform) VALUES ({$order_id},2,2,'{$current_time}','{$cancel_reason}','OTA对接')";
  130. $result = $pdo_insert2->exec($sql);
  131. break;
  132. } else {
  133. $return_data['code'] = '501';
  134. $return_data['msg'] = '该班次已无法退单,详细情况请联系客服。';
  135. echo json_encode($return_data);
  136. exit();
  137. }
  138. } else {
  139. $sql = "CALL SP_CANCEL_ORDER(" . $user_id . "," . $order_id . ")";
  140. $result = $pdo->query($sql);
  141. if (false == $result) {
  142. $return_data['code'] = '501';
  143. $return_data['msg'] = '该班次已无法退单,详细情况请联系客服。';
  144. echo json_encode($return_data);
  145. exit();
  146. }
  147. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  148. $result->closeCursor();
  149. if ($rowset[0]['errorcode'] != 0) {
  150. $return_data['code'] = '501';
  151. $return_data['msg'] = '该班次已无法退单,详细情况请联系客服。';
  152. echo json_encode($return_data);
  153. exit();
  154. }
  155. if ($outside_run_flag == true) {
  156. $tel = "18321097335,15938561301";
  157. $name = "";
  158. $content = "订单号:【" . $order_id . "】已被取消(自在产品订单号:【" . $outside_submit_order_info["supply_order_id"] . "】)";
  159. $response = sendTelMessage($tel, $name, $content, $order_id);
  160. }
  161. //cancel log
  162. $pdo_insert2 = conn1();
  163. $cancel_reason = "取消原因:渠道取消";
  164. $sql = "insert into order_opera_log(order_id,opera_user_id,opera_type,opera_time,opera_detail,opera_platform) VALUES ({$order_id},2,2,'{$current_time}','{$cancel_reason}','OTA对接')";
  165. $result = $pdo_insert2->exec($sql);
  166. $status_post_data = array();
  167. $status_post_data['order_id'] = $order_id;
  168. $status_post_data['order_status'] = "460";
  169. post2("http://". CS_DOMAIN. "/st-xm/Api/add_order_status_log.php",$status_post_data);
  170. }
  171. /*
  172. $res_content = get_msg_info($order_id);
  173. $name = isset($res_content[0])?$res_content[0]:"";
  174. $tel = isset($res_content[1])?$res_content[1]:"";
  175. $content = isset($res_content[2])?$res_content[2]:"";
  176. $response = sendTelMessage($tel, $name, $content, $order_id);
  177. $comment_type=0;
  178. $comment_text="";
  179. $send_success = (int)$response;
  180. $sql1 = "CALL HT_ADD_MSG_COMMENT(2,'addmsg'," . $order_id . "," . $comment_type . ",'" . $comment_text . "','" . $tel . "','" . $content . "','" . date("Y-m-d H:i:s") . "',{$send_success})";
  181. $result1 = $pdo -> query($sql1);
  182. $rowset1 = $result1 -> fetchAll(PDO::FETCH_ASSOC);
  183. $result1 -> closeCursor();*/
  184. }
  185. $pdo_update = conn1();
  186. $sql_update = " UPDATE outside_submit_order set submit_status=99 WHERE outside_order_no='{$ctrip_order_no}'";
  187. $pdo_update->exec($sql_update);
  188. $return_data["code"] = "201";
  189. $return_data["return_money"] = $outside_submit_order_info["all_price"];
  190. //舟山线路退票规则
  191. //1.发车前72h以外收取5%手续费
  192. //2.发车前72h以内收取10%手续费
  193. //3.发车前1h以内收取50%手续费
  194. //if( $outside_run_flag == true ) {
  195. $before_24hours = date("Y-m-d H:i:s", strtotime($run_start_time." -24 hours"));
  196. //if( $current_time >= $before_24hours ) {
  197. $return_data["return_money"] = $outside_submit_order_info["all_price"] * 0.9;
  198. //} else {
  199. // $return_data["return_money"] = $outside_submit_order_info["all_price"];
  200. //}
  201. //}
  202. $return_data["msg"] = "订单已成功取消";
  203. echo json_encode($return_data);
  204. exit();
  205. function post2($url, $post_data = '', $timeout = 5){//curl
  206. $ch = curl_init();
  207. curl_setopt ($ch, CURLOPT_URL, $url);
  208. curl_setopt ($ch, CURLOPT_POST, 1);
  209. if($post_data != ''){
  210. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  211. }
  212. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  213. curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  214. curl_setopt($ch, CURLOPT_HEADER, false);
  215. $file_contents = curl_exec($ch);
  216. curl_close($ch);
  217. return $file_contents;
  218. }
  219. /*
  220. function get_msg_info($ORDER_ID) {
  221. $msg_pdo = conn1();
  222. $msg_sql = "CALL SP_GET_MESSAGE_TEMPLATE('" . $ORDER_ID . "')";
  223. $content = '';
  224. if (is_object($msg_pdo)) {
  225. $msg_result = $msg_pdo -> query($msg_sql);
  226. $i = 1;
  227. $data = array();
  228. if ($msg_result) {
  229. $data['code'] = "0";
  230. $data['info'] = "";
  231. do {
  232. $row = $msg_result -> fetchAll(PDO::FETCH_ASSOC);
  233. if ($i == 1) {
  234. $data['seat'] = isset($row) ? $row : array();
  235. } else if ($i == 2) {
  236. $data['run_info'] = isset($row) ? $row : array();
  237. } else if ($i == 3) {
  238. $data['driver'] = isset($row) ? $row : array();
  239. } else {
  240. }
  241. $i++;
  242. } while($msg_result->nextRowset());
  243. }
  244. $json_obj = json_decode(json_encode($data), TRUE);
  245. $seat = isset($json_obj['seat'][0])?$json_obj['seat'][0]:array();
  246. $run_info = isset($json_obj['run_info'][0])?$json_obj['run_info'][0]:array();
  247. $driver = isset($json_obj['driver'][0])?$json_obj['driver'][0]:array();
  248. //取消
  249. $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已成功退票,期待下次再为您服务!";
  250. if ($seat) {
  251. $seat_x = $seat['seat_x'];
  252. $seat_y = $seat['seat_y'];
  253. $seat_name = $seat['seat_name'];
  254. $order_main_id = $seat['order_main_id'];
  255. }
  256. if ($run_info) {
  257. $order_count = $run_info['order_count'];
  258. $start_date = $run_info['start_date'];
  259. $start_time = $run_info['start_time'];
  260. $parent_order_id = $run_info['parent_order_id'];
  261. $end_date = $run_info['end_date'];
  262. $start_area = $run_info['start_area'];
  263. $end_area = $run_info['end_area'];
  264. $res_name = $run_info['res_name'];
  265. $prod_name=$run_info['prod_name'];
  266. $prod_name="标准票";
  267. $customer_name = $run_info['customer_name'];
  268. $customer_mobile = $run_info['customer_mobile'];
  269. $start_end_date = $start_date . "," . $start_time;
  270. $content = str_replace("{出发地}", $start_area, $content);
  271. $content = str_replace("{目的地}", $end_area, $content);
  272. $content = str_replace("{出发日期 出发时间}", $start_end_date, $content);
  273. $content = str_replace("{票种名}", $prod_name, $content);
  274. $content = str_replace("{张数}", $order_count, $content);
  275. }
  276. if ($driver) {
  277. $bus_no = $driver['bus_no'];
  278. $driver_name = $driver['driver_name'];
  279. $driver_mobile = $driver['driver_mobile'];
  280. }
  281. return array(isset($customer_name)?$customer_name:"", isset($customer_mobile)?$customer_mobile:"", isset($content)?$content:"短信错误!!!");
  282. }
  283. }*/