Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

send_messege.php 13 KiB

před 3 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. header("Access-Control-Allow-Origin:*");
  3. date_default_timezone_set('PRC');
  4. //载入配置文件和连接数据库
  5. require_once '/usr/share/nginx/XMWX/ZZDZ2/config/Mysql.php';///usr/share/nginx/XMWX/ZZDZ2/config/Mysql.php
  6. $pdo = conn();
  7. $sql ="SELECT ORDER_ID,ORDER_DESCRIPTION FROM order_main where prod_id in(450541,450546) and PARENT_ORDER_ID=0 and order_status=146 and CREATE_TIME >'".date('Y-m-d H:i:s', time()-300)."';";//". date('Y-m-d H:i:s', time()-300)."
  8. $result=$pdo->query($sql);
  9. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  10. foreach ($rowset as $v) {
  11. send_msg($v['ORDER_ID']);
  12. }
  13. function send_msg($ORDER_ID) {
  14. $send_pdo=conn();
  15. $order_id = $ORDER_ID;
  16. $res_content = get_msg_info($order_id);
  17. $name = $res_content[0];
  18. $tel = $res_content[1];
  19. $content = $res_content[2];
  20. writeLog("短信模板内容:【" . $content . "】");
  21. //..发短信先取消
  22. $response = sendTelMessage('17798507108', $name, $content, $order_id);
  23. writeLog(json_encode($response));
  24. $comment_type = 0;
  25. $comment_text = "";
  26. $send_success = (int)$response;
  27. $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})";
  28. $result1 = $send_pdo -> query($sql1);
  29. $rowset1 = $result1 -> fetchAll(PDO::FETCH_ASSOC);
  30. $result1 -> closeCursor();
  31. writeLog("hotel_order_status.php HT_ADD_MSG_COMMENT()::" . $sql1);
  32. //insert order extra
  33. $hotelPrice = isset($_GET['hotelPrice']) ? $_GET['hotelPrice'] : "";
  34. $doorPrice = isset($_GET["doorPrice"]) ? $_GET["doorPrice"] : "";
  35. if ($hotelPrice != "" || $doorPrice != "") {
  36. $sqlInsert = " INSERT INTO order_extra_info (order_id,hotel_price,gate_price) VALUE(" . $ORDER_ID . ",'" . $hotelPrice . "','" . $doorPrice . "') ";
  37. writeLog("insert extra info: " . $sqlInsert);
  38. $result = $send_pdo -> exec($sqlInsert);
  39. }
  40. }
  41. //..短信模板-改为17:30后OK,当天下单也OK
  42. function get_msg_info($ORDER_ID) {
  43. $msg_pdo = conn();
  44. $msg_sql = "CALL SP_GET_MESSAGE_TEMPLATE('" . $ORDER_ID . "')";
  45. $content = '';
  46. if (is_object($msg_pdo)) {
  47. $msg_result = $msg_pdo -> query($msg_sql);
  48. $i = 1;
  49. $data = array();
  50. if ($msg_result) {
  51. $data['code'] = "0";
  52. $data['info'] = "";
  53. do {
  54. $row = $msg_result -> fetchAll(PDO::FETCH_ASSOC);
  55. if ($i == 1) {
  56. $data['seat'] = isset($row) ? $row : array();
  57. } else if ($i == 2) {
  58. $data['run_info'] = isset($row) ? $row : array();
  59. } else if ($i == 3) {
  60. $data['driver'] = isset($row) ? $row : array();
  61. } else if($i==4){
  62. $data['dsn_prod']=isset($row) ? $row : array();
  63. }else if($i==5){
  64. $data['zhou_su_prod']=isset($row) ? $row : array();
  65. }
  66. $i++;
  67. } while($msg_result->nextRowset());
  68. }
  69. $json_obj = json_decode(json_encode($data), TRUE);
  70. $seat = isset($json_obj['seat'][0]) ? $json_obj['seat'][0] : array();
  71. $run_info = isset($json_obj['run_info'][0]) ? $json_obj['run_info'][0] : array();
  72. $driver = isset($json_obj['driver'][0]) ? $json_obj['driver'][0] : array();
  73. $dsn_prod = isset($json_obj['dsn_prod'])?$json_obj['dsn_prod']:array();
  74. $zhou_su_prod=isset($json_obj['zhou_su_prod'])?$json_obj['zhou_su_prod']:array();
  75. $bus_res_id = isset($json_obj['driver'][0]) ? $json_obj['driver'][0]["bus_res_id"] : 0;
  76. $short_url = false;
  77. if( $bus_res_id != 0 ) {
  78. $ary_sell_ary = array(916,917);
  79. if( in_array( $bus_res_id, $ary_sell_ary ) ) {
  80. $ticket_url = TICKET_QR_URL.$ORDER_ID;
  81. $short_url = sinaShortenUrl($ticket_url);
  82. }
  83. }
  84. $extra_message = "";
  85. if( $short_url != false ) {
  86. $extra_message = "点击以下链接获取您的电子票扫码上车:{$short_url}";
  87. }
  88. //出票成功
  89. // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车,车牌号{车牌号},司机电话{司机姓司机电话}。";
  90. // 得到明天的时间
  91. date_default_timezone_set('PRC');
  92. //解决时区问题
  93. $tomorrow = date("Y-m-d", strtotime("+1 day"));
  94. $now_time = date('H:i:s', time());
  95. //判断当前时间是否在17:30:00之后
  96. $cur_date = date('Y-m-d', time());
  97. //迪士尼特殊情况parent_prod_id
  98. // $dsn_arr_prod = array(152752, 152759, 152763, 152770, 152777, 152784, 152791, 152801, 152808, 152815, 152822, 152832, 152842, 152852, 152859, 152866, 152873, 152877, 152884, 152891, 152898, 152905, 152915, 152922, 152929, 152936, 152946, 152956, 152966, 152973, 152980, 152990, 153003, 153016, 153023, 153033, 153034, 153044, 153057, 153070, 153083, 153090, 153100, 153110);
  99. $dsn_arr_prod = array(); //用来保存迪士尼产品的prod_id
  100. foreach($dsn_prod as $temp){
  101. $dsn_arr_prod[]=$temp['prod_id'];
  102. }
  103. $zhou_su_arr_prod = array();
  104. foreach($zhou_su_prod as $temp){
  105. $zhou_su_arr_prod[]=$temp['prod_id'];
  106. }
  107. $new_message_array = array(448569,448568);
  108. $new_message_array2 = array(449860,449865,450036,450037);
  109. if (($now_time > "18:30:00" && $run_info['start_date'] == $tomorrow) || $cur_date == $run_info['start_date']) {//17:30之后的订单或者下单时间为今天出行为今天下午 发送短信模板
  110. // if("18:30:00">"17:30:00" && $run_info['start_date']==$tomorrow){ //17:30之后的订单 发送短信模板
  111. // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车,车牌号{车牌号},司机电话{司机姓司机电话}。";
  112. if( in_array( $run_info['parent_prod_id'], $new_message_array ) ) {
  113. $content = "您预订的{出发日期}{出发地}-{目的地}{票种名}{张数}张,已成功出票,请在{出发时间}前十五分钟到达{上车站点}。您的乘车订单号为{订单号},车牌号{车牌号},司机电话{司机姓司机电话},请凭短信订单号乘车{$extra_message},预祝您旅途愉快。";
  114. } elseif( in_array( $run_info['parent_prod_id'], $new_message_array2 )){
  115. $content = "您已成功预订{出发地}-{目的地}城际商务车{张数}张车票,车型为奔驰7座,发车时间为{出发日期} {出发时间},请提前10分钟到达{上车站点}。您的乘车订单号为{订单号},车牌号{车牌号},司机电话{司机姓司机电话},请凭短信订单号乘车{$extra_message},预祝您旅途愉快。";
  116. }else
  117. {$content = "您预订的{出发日期}{出发地}-{目的地}{票种名}{张数}张,已成功出票,请在{出发时间}前三十分钟到达{上车站点}。您的乘车订单号为{订单号},车牌号{车牌号},司机电话{司机姓司机电话},请凭短信订单号乘车{$extra_message},预祝您旅途愉快。";
  118. }
  119. if (in_array($run_info['parent_prod_id'], $dsn_arr_prod)) {
  120. $content = "您预订的{上车站点}-{下车站点}车票{张数}张(订单号{订单号})已经预订成功。发车时间为{出发日期} {出发时间},请提前10分钟到达并向司机出示手机二维码/预订号乘车。上车地址为{上车站点}:{上车站点详细地址}。{$extra_message}请关注微信公众号“蜘蛛出行”,可以实时查询大巴定位、司机号码、车牌号等。";
  121. $start_station_address = $run_info['start_station_address'];
  122. $content = str_replace("{上车站点详细地址}", $start_station_address, $content);
  123. $content = str_replace("{上车站点}", $run_info['res_name'], $content);
  124. $content = str_replace("{下车站点}", $run_info['end_res_name'], $content);
  125. $content = str_replace("{订单号}", $ORDER_ID, $content);
  126. }
  127. } else {
  128. // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车。";
  129. $content = "您预订的{出发日期}{出发地}-{目的地}{票种名}{张数}张,已成功出票,请在{出发时间}前十分钟到达{上车站点}。您的乘车订单号为{订单号},请凭短信订单号乘车。出行前一天下午的18:30会将车牌号与司机电话发送给您,预祝您旅途愉快。";
  130. if (in_array($run_info['parent_prod_id'], $dsn_arr_prod)) {
  131. $ticket_url = TICKET_QR_URL.$ORDER_ID;
  132. $short_url = sinaShortenUrl($ticket_url);
  133. $extra_content = "";
  134. if( $short_url != false ) {
  135. $extra_content = "或点击以下链接获取乘车二维码扫码上车(".$short_url.")";
  136. }
  137. $content = "您预订的{上车站点}-{下车站点}车票{张数}张(订单号{订单号})已经预订成功。发车时间为{出发日期} {出发时间},请提前10分钟到达并向司机出示手机二维码/预订号乘车。上车地址为{上车站点}:{上车站点详细地址}。{$extra_message}请关注微信公众号“蜘蛛出行”,可以实时查询大巴定位、司机号码、车牌号等。";
  138. $start_station_address = $run_info['start_station_address'];
  139. $content = str_replace("{上车站点详细地址}", $start_station_address, $content);
  140. $content = str_replace("{上车站点}", $run_info['res_name'], $content);
  141. $content = str_replace("{下车站点}", $run_info['end_res_name'], $content);
  142. $content = str_replace("{订单号}", $ORDER_ID, $content);
  143. }
  144. }
  145. // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车。";
  146. if ($seat) {
  147. $seat_x = isset($seat['seat_x']) ? $seat['seat_x'] : "";
  148. $seat_y = isset($seat['seat_y']) ? $seat['seat_y'] : "";
  149. $seat_name = isset($seat['seat_name']) ? $seat['seat_name'] : "";
  150. $order_main_id = isset($seat['order_main_id']) ? $seat['order_main_id'] : "";
  151. } else {
  152. }
  153. if ($run_info) {
  154. $order_count = $run_info['order_count'];
  155. $start_date = $run_info['start_date'];
  156. $start_time = $run_info['start_time'];
  157. $parent_order_id = $run_info['parent_order_id'];
  158. $end_date = $run_info['end_date'];
  159. $start_area = $run_info['start_area'];
  160. $end_area = $run_info['end_area'];
  161. $res_name = $run_info['res_name'];
  162. $parent_prod_id = $run_info['parent_prod_id'];
  163. $prod_name = $run_info['prod_name'];
  164. $prod_name = "标准票";
  165. $customer_name = $run_info['customer_name'];
  166. $customer_mobile = $run_info['customer_mobile'];
  167. $start_end_date = $start_date . "," . $start_time;
  168. $content = str_replace("{出发日期}", $start_date, $content);
  169. $content = str_replace("{出发时间}", $start_time, $content);
  170. $content = str_replace("{上车站点}", $res_name, $content);
  171. $content = str_replace("{出发地}", $start_area, $content);
  172. $content = str_replace("{目的地}", $end_area, $content);
  173. $content = str_replace("{票种名}", $prod_name, $content);
  174. $content = str_replace("{张数}", $order_count, $content);
  175. $content = str_replace("{订单号}", $ORDER_ID, $content);
  176. } else {
  177. $content = str_replace("{出发日期}", "", $content);
  178. $content = str_replace("{出发时间}", "", $content);
  179. $content = str_replace("{出发地}", "", $content);
  180. $content = str_replace("{目的地}", "", $content);
  181. $content = str_replace("{票种名}", "", $content);
  182. $content = str_replace("{张数}", "", $content);
  183. $content = str_replace("{订单号}", "", $content);
  184. }
  185. if ($driver) {
  186. $bus_no = isset($driver['bus_no']) ? $driver['bus_no'] : "";
  187. $driver_name = isset($driver['driver_name']) ? $driver['driver_name'] : "";
  188. $driver_mobile = isset($driver['driver_mobile']) ? $driver['driver_mobile'] : "";
  189. if ($bus_no == "") {
  190. $content = str_replace(",车牌号{车牌号}", "", $content);
  191. } else {
  192. $content = str_replace("{车牌号}", $bus_no, $content);
  193. }
  194. if ($driver_name == "") {
  195. $content = str_replace(",司机电话{司机姓司机电话},", "。", $content);
  196. } else {
  197. $driver_xing = mb_substr($driver_name, 0, 1, 'utf-8');
  198. $driver_name_mobile = $driver_xing . $driver_mobile;
  199. $content = str_replace("{司机姓司机电话}", $driver_name_mobile, $content);
  200. }
  201. } else {
  202. $content = str_replace("车牌号{车牌号},", "", $content);
  203. $content = str_replace("司机电话{司机姓司机电话},", "", $content);
  204. }
  205. /*
  206. if( $now_time < "18:30:00" ) {
  207. //判断是不是苏州或周庄
  208. // 判断如果不是迪士尼的票就不发短信
  209. if (!in_array($run_info['parent_prod_id'], $dsn_arr_prod) && !in_array($run_info['parent_prod_id'], $zhou_su_arr_prod)) {
  210. return array("", "-1", "不是迪士尼、苏州、周庄的票,目前不发送短信");
  211. }
  212. }*/
  213. return array(isset($customer_name) ? $customer_name : "", isset($customer_mobile) ? $customer_mobile : "", isset($content) ? $content : "短信错误,联系客服!!!");
  214. }
  215. }