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.
 
 
 
 

235 lines
12 KiB

  1. <?php
  2. /*
  3. Author:XM
  4. Update:Redstop
  5. Compeny:Spiders Travel
  6. Descript:添加录入订单时的备注
  7. */
  8. define( "BASE_TICKET_URL", "http://api.zhizhuchuxing.com/api1.0/ticket.php?orderid=" );
  9. require_once __DIR__.'/../st-xm/Common/Mysql.php';
  10. require_once __DIR__.'/../st-xm/Common/sinaAPI.php';
  11. $return_array = array();
  12. $pdo=conn();
  13. $order_id = isset($_POST['order_id']) ? $_POST['order_id'] : false;
  14. if( $order_id == false ) {
  15. $return_array["code"] = -1;
  16. $return_array["info"] = "无效订单号";
  17. echo json_encode($return_array);
  18. exit();
  19. }
  20. send_msg($order_id);
  21. $return_array["code"] = 0;
  22. $return_array["info"] = "发送成功";
  23. echo json_encode($return_array);
  24. exit();
  25. //发短信
  26. function send_msg($ORDER_ID) {
  27. $send_pdo = conn();
  28. $order_id = $ORDER_ID;
  29. $res_content = get_msg_info($order_id);
  30. if( false == $res_content ) {
  31. return false;
  32. }
  33. //$url = BASE_TICKET_URL.$order_id;
  34. //$short_url = sinaShortenUrl(filterUrl($url)); //根据传入的长网址生产短网址
  35. $name = $res_content[0];
  36. $tel = $res_content[1];
  37. $content = $res_content[2];
  38. $response=null;
  39. $send_success="-100"; // 默认-100
  40. writeLog("短信模板内容:".$name."tel".$tel."【" . $content . "】");
  41. if($tel!="-1"){
  42. $send_success="-90"; // 说明手机号不是-1
  43. $response = sendTelMessage($tel, $name, $content, $order_id);
  44. writeLog(json_encode($response));
  45. }else{
  46. $send_success="-1"; // 说明手机号为-1
  47. writeLog('send_msg==tel==='.$tel.":内容:==》".$content);
  48. }
  49. $comment_type = 0;
  50. $comment_text = "";
  51. if($response!=null){
  52. $send_success=(int)$response;
  53. }
  54. $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})";
  55. $result1 = $send_pdo -> query($sql1);
  56. $rowset1 = $result1 -> fetchAll(PDO::FETCH_ASSOC);
  57. $result1 -> closeCursor();
  58. writeLog("hotel_order_status.php HT_ADD_MSG_COMMENT()::" . $sql1);
  59. }
  60. //..短信模板-改为17:30后OK,当天下单也OK
  61. function get_msg_info($ORDER_ID) {
  62. $not_send_prod = array(451023,451024,451025,451026,451027,451028);
  63. $msg_pdo = conn();
  64. $msg_sql = "CALL SP_GET_MESSAGE_TEMPLATE('" . $ORDER_ID . "')";
  65. $content = '';
  66. if (is_object($msg_pdo)) {
  67. $msg_result = $msg_pdo -> query($msg_sql);
  68. $i = 1;
  69. $data = array();
  70. if ($msg_result) {
  71. $data['code'] = "0";
  72. $data['info'] = "";
  73. do {
  74. $row = $msg_result -> fetchAll(PDO::FETCH_ASSOC);
  75. if ($i == 1) {
  76. $data['seat'] = isset($row) ? $row : array();
  77. } else if ($i == 2) {
  78. $data['run_info'] = isset($row) ? $row : array();
  79. } else if ($i == 3) {
  80. $data['driver'] = isset($row) ? $row : array();
  81. } else if($i==4){
  82. $data['dsn_prod']=isset($row) ? $row : array();
  83. }else if($i==5){
  84. $data['zhou_su_prod']=isset($row) ? $row : array();
  85. }
  86. $i++;
  87. } while($msg_result->nextRowset());
  88. }
  89. $json_obj = json_decode(json_encode($data), TRUE);
  90. $seat = isset($json_obj['seat'][0]) ? $json_obj['seat'][0] : array();
  91. $run_info = isset($json_obj['run_info'][0]) ? $json_obj['run_info'][0] : array();
  92. $driver = isset($json_obj['driver'][0]) ? $json_obj['driver'][0] : array();
  93. $dsn_prod = isset($json_obj['dsn_prod'])?$json_obj['dsn_prod']:array();
  94. $zhou_su_prod=isset($json_obj['zhou_su_prod'])?$json_obj['zhou_su_prod']:array();
  95. $bus_res_id = isset($json_obj['driver'][0]) ? $json_obj['driver'][0]["bus_res_id"] : 0;
  96. if (in_array($run_info['parent_prod_id'], $not_send_prod)) {
  97. return false;
  98. }
  99. // 得到明天的时间
  100. date_default_timezone_set('PRC');
  101. //解决时区问题
  102. $tomorrow = date("Y-m-d", strtotime("+1 day"));
  103. $now_time = date('H:i:s', time());
  104. //判断当前时间是否在17:30:00之后
  105. $cur_date = date('Y-m-d', time());
  106. //迪士尼特殊情况parent_prod_id
  107. $dsn_arr_prod = array(); //用来保存迪士尼产品的prod_id
  108. foreach($dsn_prod as $temp){
  109. $dsn_arr_prod[]=$temp['prod_id'];
  110. }
  111. $zhou_su_arr_prod = array();
  112. foreach($zhou_su_prod as $temp){
  113. $zhou_su_arr_prod[]=$temp['prod_id'];
  114. }
  115. $short_url = false;
  116. $ticket_url = TICKET_QR_URL.$ORDER_ID;
  117. $short_url = sinaShortenUrl($ticket_url);
  118. $extra_message = "";
  119. if( $short_url != false ) {
  120. $extra_message = "您的电子车票链接 {$short_url} ,请在上车前点开,扫码乘车。";
  121. }
  122. $new_message_array5 = array(451440,451441);
  123. $new_message_array6 = array(448780,450008,448781);
  124. if( in_array( $run_info['parent_prod_id'], $new_message_array5 ) ) {
  125. $content = "订单号{订单号},{出发日期} {出发时间}{上车站点}—{目的地}标准票{张数}张预定成功。发车前一天19点会短信通知您车牌号及司机电话,如未收到短信请拨打客服电话021-33280519。";
  126. } else if( in_array( $run_info['parent_prod_id'], $new_message_array6 ) ) {
  127. $content = "订单号{订单号},{出发日期} {出发时间}{上车站点}—{目的地}标准票{张数}张预定成功。发车前一天19点会短信通知您乘车信息,如未收到短信请拨打客服电话021-33280519。";
  128. } else if (($now_time > "18:30:00" && $run_info['start_date'] == $tomorrow) || $cur_date == $run_info['start_date']) {//17:30之后的订单或者下单时间为今天出行为今天下午 发送短信模板
  129. $content = "订单号{订单号},{出发地}—{目的地}标准票{张数}张将于{出发日期} {出发时间}准点发车。车牌号{车牌号},司机电话{司机姓司机电话},请提前10分钟抵达上车地点:{上车站点详细地址}并点开电子车票 {$short_url} 进行验票。如有疑问请拨打客服电话021-33280519。";
  130. } else {
  131. $content = "订单号{订单号},{出发日期} {出发时间}{出发地}—{目的地}标准票{张数}张预定成功。发车前一天19点会短信通知您车牌号及司机电话,如未收到短信请拨打客服电话021-33280519。";
  132. }
  133. $new_message_array3 = array(450517,450522);
  134. if( in_array( $run_info['parent_prod_id'], $new_message_array3 ) ) {
  135. if( $run_info['parent_prod_id'] == 450517 ) {
  136. $address_txt = "上车地点:吴山广场西侧河坊巷8号(吴山广场旅游集散中心候车室); 上车方式:请至吴山广场旅游集散中心候车室服务台,凭预定姓名和手机号码上车。";
  137. } else {
  138. $address_txt = "上车地点:普陀城北长途客运中心;取票方式:请提前到达(学运路18号)普陀城北长途客运中心候车大厅服务台报预订名字和电话取票。";
  139. }
  140. $content = "您已成功预定{出发日期} {出发时间} {出发地}-{目的地}汽车票{张数}张(请最晚提前10分钟到达)。{$address_txt}紧急电话:15888866564。";
  141. }
  142. $new_message_array4 = array(450588,450589);
  143. if( in_array( $run_info['parent_prod_id'], $new_message_array4 ) ) {
  144. $content .= "紧急联系电话:18100158199。";
  145. }
  146. $new_message_array5 = array(451437,451438);
  147. if( in_array( $run_info['parent_prod_id'], $new_message_array5 ) ) {
  148. $content .= "司机会提前与您联系,如有疑问,请联系021-33280578 。";
  149. }
  150. if ($seat) {
  151. $seat_x = isset($seat['seat_x']) ? $seat['seat_x'] : "";
  152. $seat_y = isset($seat['seat_y']) ? $seat['seat_y'] : "";
  153. $seat_name = isset($seat['seat_name']) ? $seat['seat_name'] : "";
  154. $order_main_id = isset($seat['order_main_id']) ? $seat['order_main_id'] : "";
  155. } else {
  156. }
  157. if ($run_info) {
  158. $order_count = $run_info['order_count'];
  159. $start_date = $run_info['start_date'];
  160. $start_time = $run_info['start_time'];
  161. $parent_order_id = $run_info['parent_order_id'];
  162. $end_date = $run_info['end_date'];
  163. $start_area = $run_info['start_area'];
  164. $end_area = $run_info['end_area'];
  165. $res_name = $run_info['res_name'];
  166. $parent_prod_id = $run_info['parent_prod_id'];
  167. $prod_name = $run_info['prod_name'];
  168. $prod_name = "标准票";
  169. $customer_name = $run_info['customer_name'];
  170. $customer_mobile = $run_info['customer_mobile'];
  171. $start_station_address = $run_info['start_station_address'];
  172. $start_end_date = $start_date . "," . $start_time;
  173. if( $parent_prod_id == 450504 && $start_date >= "2017-01-27" && $start_date <= "2017-02-02" ) {
  174. $res_name = "迪士尼唐老鸭P停车场";
  175. $start_station_address = "上海迪士尼度假区迪士尼唐老鸭P停车场";
  176. }
  177. $content = str_replace("{下车站点}", $run_info['end_res_name'], $content);
  178. $content = str_replace("{出发日期}", $start_date, $content);
  179. $content = str_replace("{出发时间}", $start_time, $content);
  180. $content = str_replace("{上车站点}", $res_name, $content);
  181. $content = str_replace("{出发地}", $start_area, $content);
  182. $content = str_replace("{目的地}", $end_area, $content);
  183. $content = str_replace("{票种名}", $prod_name, $content);
  184. $content = str_replace("{张数}", $order_count, $content);
  185. $content = str_replace("{上车站点详细地址}", $start_station_address, $content);
  186. $content = str_replace("{订单号}", $ORDER_ID, $content);
  187. } else {
  188. $content = str_replace("{下车站点}", "", $content);
  189. $content = str_replace("{出发日期}", "", $content);
  190. $content = str_replace("{出发时间}", "", $content);
  191. $content = str_replace("{出发地}", "", $content);
  192. $content = str_replace("{目的地}", "", $content);
  193. $content = str_replace("{票种名}", "", $content);
  194. $content = str_replace("{张数}", "", $content);
  195. $content = str_replace("{订单号}", "", $content);
  196. $content = str_replace("{上车站点详细地址}", "", $content);
  197. }
  198. if ($driver) {
  199. $bus_no = isset($driver['bus_no']) ? $driver['bus_no'] : "";
  200. $driver_name = isset($driver['driver_name']) ? $driver['driver_name'] : "";
  201. $driver_mobile = isset($driver['driver_mobile']) ? $driver['driver_mobile'] : "";
  202. if ($bus_no == "") {
  203. $content = str_replace(",车牌号{车牌号}", "", $content);
  204. } else {
  205. $content = str_replace("{车牌号}", $bus_no, $content);
  206. }
  207. if ($driver_name == "") {
  208. $content = str_replace(",司机电话{司机姓司机电话},", "。", $content);
  209. } else {
  210. $driver_xing = mb_substr($driver_name, 0, 1, 'utf-8');
  211. $driver_name_mobile = $driver_xing . $driver_mobile;
  212. $content = str_replace("{司机姓司机电话}", $driver_name_mobile, $content);
  213. }
  214. } else {
  215. $content = str_replace("车牌号{车牌号},", "", $content);
  216. $content = str_replace("司机电话{司机姓司机电话},", "", $content);
  217. }
  218. $content .= "提前一天19点之前,如未收到司机电话,请速与021-52218088联系。";
  219. return array(isset($customer_name) ? $customer_name : "", isset($customer_mobile) ? $customer_mobile : "", isset($content) ? $content : "短信错误,联系客服!!!");
  220. }
  221. }