25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

156 satır
5.8 KiB

  1. <?php
  2. require_once '../st-xm/Common/Mysql.php';
  3. header("Access-Control-Allow-Origin:*");
  4. //test
  5. //$_POST['auth_code'] = "abcdefg";
  6. //$_POST['ctrip_order_no'] = "1234567890";
  7. //end of test
  8. $auth_code=isset($_POST['auth_code'])? $_POST['auth_code']:false;
  9. $ctrip_order_no=isset($_POST['ctrip_order_no'])? $_POST['ctrip_order_no']:false;
  10. $return_data = array();
  11. $return_data['code']='201';
  12. if( $auth_code == false || $ctrip_order_no == false ) {
  13. $return_data['code']='401';
  14. echo json_encode($return_data);
  15. exit();
  16. }
  17. $pdo=conn();
  18. $sql=" SELECT user_name,user_psd,user_auth_code FROM api_auth_code WHERE user_auth_code='".$auth_code."' ";
  19. $result=$pdo->query($sql);
  20. $rowset=$result->fetchAll();
  21. $result->closeCursor();
  22. if( false == $rowset ) {
  23. $return_data['code']='400';
  24. echo json_encode($return_data);
  25. exit();
  26. }
  27. $sql1 = " SELECT * FROM order_main WHERE OUTSIDE_ORDER_NO = '{$ctrip_order_no}' AND ORDER_STATUS != 238 ";
  28. $result=$pdo->query($sql1);
  29. $result_array=$result->fetchAll();
  30. $result->closeCursor();
  31. $order_array = array();
  32. $run_id_array = array();
  33. foreach( $result_array as $order_info ) {
  34. if( $order_info["PARENT_ORDER_ID"] == 0 ) {
  35. $order_array[$order_info["ORDER_ID"]] = $order_info;
  36. } else {
  37. if( !in_array( $order_info["RUN_ID"], $run_id_array ) ) { $run_id_array[] = $order_info["RUN_ID"]; }
  38. }
  39. }
  40. $sql2 = " SELECT * FROM run_main WHERE RUN_ID IN (".implode(",",$run_id_array).") ";
  41. $result=$pdo->query($sql2);
  42. $result_array=$result->fetchAll();
  43. $result->closeCursor();
  44. if( $result_array == false ) {
  45. $return_data['code']='501';
  46. $return_data['msg']='该班次为无效班次';
  47. echo json_encode($return_data);
  48. exit();
  49. }
  50. foreach( $result_array as $run_main_info ) {
  51. if( $run_main_info["RUN_STATUS"] != 138 ) {
  52. $return_data['code']='501';
  53. $return_data['msg']='该班次已准备发车无法退单';
  54. echo json_encode($return_data);
  55. exit();
  56. }
  57. }
  58. $user_id = 1;
  59. foreach( $order_array as $order_main_info ) {
  60. $order_id = $order_main_info["ORDER_ID"];
  61. $sql = "CALL SP_CANCEL_ORDER(" . $user_id . "," . $order_id . ")";
  62. $result = $pdo->query($sql);
  63. $result->closeCursor();
  64. $res_content = get_msg_info($order_id);
  65. $name = isset($res_content[0])?$res_content[0]:"";
  66. $tel = isset($res_content[1])?$res_content[1]:"";
  67. $content = isset($res_content[2])?$res_content[2]:"";
  68. $response = sendTelMessage($tel, $name, $content, $order_id);
  69. $comment_type=0;
  70. $comment_text="";
  71. $send_success = (int)$response;
  72. $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})";
  73. $result1 = $pdo -> query($sql1);
  74. $rowset1 = $result1 -> fetchAll(PDO::FETCH_ASSOC);
  75. $result1 -> closeCursor();
  76. }
  77. $return_data["code"] = "201";
  78. $return_data["msg"] = "";
  79. echo json_encode($return_data);
  80. exit();
  81. function get_msg_info($ORDER_ID) {
  82. $msg_pdo = conn();
  83. $msg_sql = "CALL SP_GET_MESSAGE_TEMPLATE('" . $ORDER_ID . "')";
  84. $content = '';
  85. if (is_object($msg_pdo)) {
  86. $msg_result = $msg_pdo -> query($msg_sql);
  87. $i = 1;
  88. $data = array();
  89. if ($msg_result) {
  90. $data['code'] = "0";
  91. $data['info'] = "";
  92. do {
  93. $row = $msg_result -> fetchAll(PDO::FETCH_ASSOC);
  94. if ($i == 1) {
  95. $data['seat'] = isset($row) ? $row : array();
  96. } else if ($i == 2) {
  97. $data['run_info'] = isset($row) ? $row : array();
  98. } else if ($i == 3) {
  99. $data['driver'] = isset($row) ? $row : array();
  100. } else {
  101. }
  102. $i++;
  103. } while($msg_result->nextRowset());
  104. }
  105. $json_obj = json_decode(json_encode($data), TRUE);
  106. $seat = isset($json_obj['seat'][0])?$json_obj['seat'][0]:array();
  107. $run_info = isset($json_obj['run_info'][0])?$json_obj['run_info'][0]:array();
  108. $driver = isset($json_obj['driver'][0])?$json_obj['driver'][0]:array();
  109. //取消
  110. $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已成功退票,期待下次再为您服务!";
  111. if ($seat) {
  112. $seat_x = $seat['seat_x'];
  113. $seat_y = $seat['seat_y'];
  114. $seat_name = $seat['seat_name'];
  115. $order_main_id = $seat['order_main_id'];
  116. }
  117. if ($run_info) {
  118. $order_count = $run_info['order_count'];
  119. $start_date = $run_info['start_date'];
  120. $start_time = $run_info['start_time'];
  121. $parent_order_id = $run_info['parent_order_id'];
  122. $end_date = $run_info['end_date'];
  123. $start_area = $run_info['start_area'];
  124. $end_area = $run_info['end_area'];
  125. $res_name = $run_info['res_name'];
  126. $prod_name=$run_info['prod_name'];
  127. $prod_name="标准票";
  128. $customer_name = $run_info['customer_name'];
  129. $customer_mobile = $run_info['customer_mobile'];
  130. $start_end_date = $start_date . "," . $start_time;
  131. $content = str_replace("{出发地}", $start_area, $content);
  132. $content = str_replace("{目的地}", $end_area, $content);
  133. $content = str_replace("{出发日期 出发时间}", $start_end_date, $content);
  134. $content = str_replace("{票种名}", $prod_name, $content);
  135. $content = str_replace("{张数}", $order_count, $content);
  136. }
  137. if ($driver) {
  138. $bus_no = $driver['bus_no'];
  139. $driver_name = $driver['driver_name'];
  140. $driver_mobile = $driver['driver_mobile'];
  141. }
  142. return array(isset($customer_name)?$customer_name:"", isset($customer_mobile)?$customer_mobile:"", isset($content)?$content:"短信错误!!!");
  143. }
  144. }