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.
 
 
 
 

232 line
8.7 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['run_code'] = "201743_152691";
  7. //$_POST['ticket_num'] = 3;
  8. //$_POST['per_price'] = 17.50;
  9. //$_POST['all_price'] = 52.50;
  10. //$_POST['customer_name'] = "测试员001";
  11. //$_POST['customer_mobile'] = "13816608252";
  12. //$_POST['customer_id_no'] = "12345678901245678";
  13. //$_POST['ctrip_order_no'] = "abcdefg";
  14. //end of test
  15. $auth_code=isset($_POST['auth_code'])? $_POST['auth_code']:false;
  16. $run_code=isset($_POST['run_code'])? $_POST['run_code']:false;
  17. $ticket_num=isset($_POST['ticket_num'])? $_POST['ticket_num']:false;
  18. $per_price=isset($_POST['per_price'])? $_POST['per_price']:false;
  19. $all_price=isset($_POST['all_price'])? $_POST['all_price']:false;
  20. $customer_name=isset($_POST['customer_name'])? $_POST['customer_name']:false;
  21. $customer_mobile=isset($_POST['customer_mobile'])? $_POST['customer_mobile']:false;
  22. $customer_id_no=isset($_POST['customer_id_no'])? $_POST['customer_id_no']:false;
  23. $ctrip_order_no=isset($_POST['ctrip_order_no'])? $_POST['ctrip_order_no']:false;
  24. $return_data = array();
  25. $return_data['code']='201';
  26. if( $auth_code == false || $run_code == false || $ticket_num == false || $per_price == false || $all_price == false || $customer_name == false || $customer_id_no == false || $ctrip_order_no == false ) {
  27. $return_data['code']='401';
  28. echo json_encode($return_data);
  29. exit();
  30. }
  31. $pdo=conn();
  32. $sql=" SELECT user_name,user_psd,user_auth_code FROM api_auth_code WHERE user_auth_code='".$auth_code."' ";
  33. $result=$pdo->query($sql);
  34. $rowset=$result->fetchAll();
  35. $result->closeCursor();
  36. if( false == $rowset ) {
  37. $return_data['code']='400';
  38. echo json_encode($return_data);
  39. exit();
  40. }
  41. $param_run_code = $run_code;
  42. $run_code_array = explode("_",$run_code);
  43. $run_code = $run_code_array[0];
  44. $prod_id = $run_code_array[1];
  45. $sql2 = " SELECT * FROM run_main WHERE RUN_ID = {$run_code} ";
  46. $result=$pdo->query($sql2);
  47. $rowset=$result->fetchAll();
  48. $result->closeCursor();
  49. $return_data['code']='201';
  50. if( $rowset == false ) {
  51. $return_data['code']='501';
  52. $return_data['msg']='该班次为无效班次';
  53. echo json_encode($return_data);
  54. exit();
  55. }
  56. $run_main_info = $rowset[0];
  57. $sql3 = " SELECT * FROM run_bus WHERE RUN_ID = {$run_code} ";
  58. $result=$pdo->query($sql3);
  59. $result_array=$result->fetchAll();
  60. $result->closeCursor();
  61. if( $result == false ) {
  62. $return_data['code'] = '402';
  63. $return_data['msg'] = '发送参数不符合定义';
  64. echo json_encode($return_data);exit();
  65. }
  66. $run_bus_array = array();
  67. foreach( $result_array as $run_bus_info ) {
  68. if( !isset($run_bus_array[$run_bus_info["RUN_ID"]]) ) {
  69. $run_bus_array[$run_bus_info["RUN_ID"]] = array();
  70. }
  71. $run_bus_array[$run_bus_info["RUN_ID"]][] = $run_bus_info;
  72. }
  73. $data_array = array();
  74. if( !$run_bus_array[$run_main_info["RUN_ID"]] ) {
  75. $total_count = 0;
  76. $saled_count = 0;
  77. $remain_count = 0;
  78. } else {
  79. $total_count = 0;
  80. $saled_count = 0;
  81. $remain_count = 0;
  82. foreach( $run_bus_array[$run_main_info["RUN_ID"]] as $run_bus_info ) {
  83. $total_count += $run_bus_info["SEAT_COUNT"];
  84. $saled_count += $run_bus_info["SALED_COUNT"];
  85. }
  86. $remain_count = $total_count - $saled_count;
  87. }
  88. if( $remain_count < $ticket_num ) {
  89. $return_data['code'] = '500';
  90. $return_data['msg'] = '该班次剩余库存不足';
  91. echo json_encode($return_data);exit();
  92. }
  93. $sql4 = " SELECT opera_product.PROD_ID FROM opera_product WHERE PARENT_ID={$run_main_info["PROD_ID"]} AND PROD_TYPE=82";
  94. $result=$pdo->query($sql4);
  95. $result_array=$result->fetchAll();
  96. $result->closeCursor();
  97. if( $result_array == false ) {
  98. $return_data['code'] = '500';
  99. $return_data['msg'] = '该班次剩余库存不足';
  100. echo json_encode($return_data);exit();
  101. }
  102. $match_prod_flag = 0;
  103. foreach( $result_array as $ticket_info ) {
  104. if( $ticket_info["PROD_ID"] == $prod_id ) {
  105. $match_prod_flag = 1;
  106. break;
  107. }
  108. }
  109. if( $match_prod_flag == 0 ) {
  110. $return_data['code'] = '402';
  111. $return_data['msg'] = '发送参数不符合定义';
  112. echo json_encode($return_data);exit();
  113. }
  114. $userid = 1;
  115. $myprod = '{m'.$prod_id.'p'.$ticket_num.'|r'.$run_code.'}';
  116. $mycustomer = '{,'.$customer_name.',,'.$customer_mobile.',150,'.$customer_id_no.',,,,}';
  117. $sql_insert="call sp_make_order(".$userid.",'".$myprod."','".$mycustomer."', 17, '".$ctrip_order_no."')";
  118. $result=$pdo->query($sql_insert);
  119. $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
  120. $result->closeCursor();
  121. if (is_array($rowset) && $rowset[0]['errcode'] == 0 ) {
  122. $order_id=$rowset[0]['order_id'];
  123. $res_content=get_msg_info($order_id);
  124. $name=$res_content[0];
  125. $tel=$res_content[1];
  126. $content=$res_content[2];
  127. $response = sendTelMessage($tel, $name, $content, $order_id);
  128. $comment_type=0;
  129. $comment_text="";
  130. $send_success = (int)$response;
  131. $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})";
  132. $result1 = $pdo -> query($sql1);
  133. $rowset1 = $result1 -> fetchAll(PDO::FETCH_ASSOC);
  134. $result1 -> closeCursor();
  135. } else {
  136. $return_data["code"] = $rowset[0]['errcode'];
  137. $return_data["msg"] = $rowset[0]['errinfo'];
  138. echo json_encode($return_data);
  139. exit();
  140. }
  141. $return_data["code"] = "201";
  142. $return_data["order_no"] = $rowset[0]['order_id'];
  143. $return_data["msg"] = "";
  144. echo json_encode($return_data);
  145. exit();
  146. function get_msg_info($ORDER_ID) {
  147. $msg_pdo = conn();
  148. $msg_sql = "CALL SP_GET_MESSAGE_TEMPLATE('" . $ORDER_ID . "')";
  149. $content='';
  150. if (is_object($msg_pdo)) {
  151. $msg_result = $msg_pdo -> query($msg_sql);
  152. $i = 1;
  153. $data = array();
  154. if ($msg_result) {
  155. $data['code'] = "0";
  156. $data['info'] = "";
  157. do {
  158. $row = $msg_result -> fetchAll(PDO::FETCH_ASSOC);
  159. if ($i == 1) {
  160. $data['seat'] = isset($row) ? $row : array();
  161. } else if ($i == 2) {
  162. $data['run_info'] = isset($row) ? $row : array();
  163. } else if ($i == 3) {
  164. $data['driver'] = isset($row) ? $row : array();
  165. } else {
  166. }
  167. $i++;
  168. } while($msg_result->nextRowset());
  169. }
  170. $json_obj = json_decode(json_encode($data), TRUE);
  171. $seat = isset($json_obj['seat'][0])?$json_obj['seat'][0]:array();
  172. $run_info = isset($json_obj['run_info'][0])?$json_obj['run_info'][0]:array();
  173. $driver = isset($json_obj['driver'][0])?$json_obj['driver'][0]:array();
  174. //出票成功
  175. $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},凭短信上车。";
  176. if ($seat) {
  177. $seat_x = isset($seat['seat_x'])?$seat['seat_x']:"";
  178. $seat_y = isset($seat['seat_y'])?$seat['seat_y']:"";
  179. $seat_name = isset($seat['seat_name'])?$seat['seat_name']:"";
  180. $order_main_id = isset($seat['order_main_id'])?$seat['order_main_id']:"";
  181. }else{
  182. }
  183. if ($run_info) {
  184. $order_count = $run_info['order_count'];
  185. $start_date = $run_info['start_date'];
  186. $start_time = $run_info['start_time'];
  187. $parent_order_id = $run_info['parent_order_id'];
  188. $end_date = $run_info['end_date'];
  189. $start_area = $run_info['start_area'];
  190. $end_area = $run_info['end_area'];
  191. $res_name = $run_info['res_name'];
  192. $prod_name=$run_info['prod_name'];
  193. $customer_name=$run_info['customer_name'];
  194. $customer_mobile=$run_info['customer_mobile'];
  195. $start_end_date = $start_date . "," . $start_time;
  196. $content = str_replace("{出发日期 出发时间}", $start_end_date, $content);
  197. $content = str_replace("{出发地}", $start_area, $content);
  198. $content = str_replace("{目的地}", $end_area, $content);
  199. $content = str_replace("{票种名}", $prod_name, $content);
  200. $content = str_replace("{张数}", $order_count, $content);
  201. $content = str_replace("{订单号}", $ORDER_ID, $content);
  202. }else{
  203. $content = str_replace("{出发日期 出发时间}", "", $content);
  204. $content = str_replace("{出发地}", "", $content);
  205. $content = str_replace("{目的地}", "", $content);
  206. $content = str_replace("{票种名}", "", $content);
  207. $content = str_replace("{张数}", "", $content);
  208. $content = str_replace("{订单号}", "", $content);
  209. }
  210. return array(isset($customer_name)?$customer_name:"",isset($customer_mobile)?$customer_mobile:"",isset($content)?$content:"短信错误!!!");
  211. }
  212. }