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.
 
 
 
 

283 lines
14 KiB

  1. <?php
  2. require_once '../wechat/Common_fx/Mysql.php';
  3. require_once '../wechat/Common_fx/zizai_api.inc';
  4. require_once '../wechat/Common_fx/sinaAPI.php';
  5. if (ALLOW_ORIGIN)
  6. header("Access-Control-Allow-Origin:*");
  7. $pdo=conn();
  8. $order_id =$_GET['orderno'];
  9. $paynum = $_GET['paynum'];
  10. if(!$order_id){
  11. echo '订单号没有接收到';die;
  12. }
  13. $sql_s = "select * from to_from where to_orderid=".$order_id." or back_orderid=".$order_id;
  14. $result=$pdo->query($sql_s);
  15. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  16. //发送短信
  17. if($rowset){
  18. $sql = "select order_id from order_main where order_id in (".$rowset[0]['to_orderid'].",".$rowset[0]['back_orderid'].") or parent_order_id in (".$rowset[0]['to_orderid'].",".$rowset[0]['back_orderid'].")";
  19. $result=$pdo->query($sql);
  20. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  21. foreach($rowset as $v){
  22. $list[] = $v['order_id'];
  23. }
  24. }else{
  25. $sql = "select order_id from order_main where order_id = ".$order_id." or parent_order_id = ".$order_id;
  26. $result=$pdo->query($sql);
  27. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  28. foreach($rowset as $v){
  29. $list[] = $v['order_id'];
  30. }
  31. }
  32. //是否有至订单
  33. $list = implode(",", $list);
  34. $sql = "select a.order_id,a.order_price,a.outside_order_no,a.order_pay_main_id,a.customer_name,a.customer_mobile,count(b.order_id) as num,b.run_date,b.run_time,b.PROD_START_STATION_AREA_NAME AS start_area,b.PROD_END_STATION_AREA_NAME AS end_area,b.PROD_START_STATION_RES_NAME AS start_res,b.PROD_END_STATION_RES_NAME AS end_res "
  35. . "from order_main a,order_main b "
  36. . "where a.order_id = b.PARENT_ORDER_ID and a.order_id in (" . $list . ") group by a.order_id";
  37. $result = $pdo->query($sql);
  38. $order_info = $result->fetchAll(PDO::FETCH_ASSOC);
  39. foreach ($order_info as $v){
  40. $list_P[]=$v['order_pay_main_id'];
  41. }
  42. $list_P = implode(",", $list_P);
  43. $sql_pay = "update order_pay_detail set pay_type_id_1 =278,PAY_SERIAL_NUMBER='".$order_id."-".$paynum."' where pay_main_id in (".$list_P.")";
  44. $rs = $pdo->query($sql_pay);
  45. $sql_order_status = "update order_main set order_status =146 where order_id in(".$list.")";
  46. $rs2 = $pdo->query($sql_order_status);
  47. $sql = "update `disney_order` set yet =0 where order_id =".$order_id;
  48. $res=$pdo->query($sql);
  49. if(!$res){
  50. if(isset($rowset[0]['to_orderid'])){
  51. send_msg($rowset[0]['to_orderid']);
  52. send_msg($rowset[0]['back_orderid']);
  53. }else{
  54. send_msg($order_id);
  55. }
  56. }
  57. $log = $sql.'##'.$sql_pay."##".$sql_order_status;
  58. success_notify($log);
  59. function success_notify($result){
  60. file_put_contents('./order_confirm.txt', date("Y-m-d H:i:s")." ".$result.PHP_EOL,FILE_APPEND);//订单成功后通知后台日志
  61. }
  62. echo "支付成功";
  63. die;
  64. function send_msg($ORDER_ID) {
  65. $send_pdo=conn();
  66. $order_id = $ORDER_ID;
  67. $res_content = get_msg_info($order_id);
  68. $name = $res_content[0];
  69. $tel = $res_content[1];
  70. $content = $res_content[2];
  71. writeLog("短信模板内容:【" . $content . "】");
  72. //..发短信先取消
  73. $response = sendTelMessage($tel, $name, $content, $order_id);
  74. writeLog(json_encode($response));
  75. $comment_type = 0;
  76. $comment_text = "";
  77. $send_success = (int)$response;
  78. $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})";
  79. $result1 = $send_pdo -> query($sql1);
  80. $rowset1 = $result1 -> fetchAll(PDO::FETCH_ASSOC);
  81. $result1 -> closeCursor();
  82. writeLog("hotel_order_status.php HT_ADD_MSG_COMMENT()::" . $sql1);
  83. //insert order extra
  84. $hotelPrice = isset($_GET['hotelPrice']) ? $_GET['hotelPrice'] : "";
  85. $doorPrice = isset($_GET["doorPrice"]) ? $_GET["doorPrice"] : "";
  86. if ($hotelPrice != "" || $doorPrice != "") {
  87. $sqlInsert = " INSERT INTO order_extra_info (order_id,hotel_price,gate_price) VALUE(" . $ORDER_ID . ",'" . $hotelPrice . "','" . $doorPrice . "') ";
  88. writeLog("insert extra info: " . $sqlInsert);
  89. $result = $send_pdo -> exec($sqlInsert);
  90. }
  91. }
  92. //..短信模板-改为17:30后OK,当天下单也OK
  93. function get_msg_info($ORDER_ID) {
  94. $msg_pdo = conn();
  95. $msg_sql = "CALL SP_GET_MESSAGE_TEMPLATE('" . $ORDER_ID . "')";
  96. $content = '';
  97. if (is_object($msg_pdo)) {
  98. $msg_result = $msg_pdo -> query($msg_sql);
  99. $i = 1;
  100. $data = array();
  101. if ($msg_result) {
  102. $data['code'] = "0";
  103. $data['info'] = "";
  104. do {
  105. $row = $msg_result -> fetchAll(PDO::FETCH_ASSOC);
  106. if ($i == 1) {
  107. $data['seat'] = isset($row) ? $row : array();
  108. } else if ($i == 2) {
  109. $data['run_info'] = isset($row) ? $row : array();
  110. } else if ($i == 3) {
  111. $data['driver'] = isset($row) ? $row : array();
  112. } else if($i==4){
  113. $data['dsn_prod']=isset($row) ? $row : array();
  114. }else if($i==5){
  115. $data['zhou_su_prod']=isset($row) ? $row : array();
  116. }
  117. $i++;
  118. } while($msg_result->nextRowset());
  119. }
  120. $json_obj = json_decode(json_encode($data), TRUE);
  121. $seat = isset($json_obj['seat'][0]) ? $json_obj['seat'][0] : array();
  122. $run_info = isset($json_obj['run_info'][0]) ? $json_obj['run_info'][0] : array();
  123. $driver = isset($json_obj['driver'][0]) ? $json_obj['driver'][0] : array();
  124. $dsn_prod = isset($json_obj['dsn_prod'])?$json_obj['dsn_prod']:array();
  125. $zhou_su_prod=isset($json_obj['zhou_su_prod'])?$json_obj['zhou_su_prod']:array();
  126. $bus_res_id = isset($json_obj['driver'][0]) ? $json_obj['driver'][0]["bus_res_id"] : 0;
  127. $short_url = false;
  128. if( $bus_res_id != 0 ) {
  129. $ary_sell_ary = array(916,917);
  130. if( in_array( $bus_res_id, $ary_sell_ary ) ) {
  131. $ticket_url = TICKET_QR_URL.$ORDER_ID;
  132. $short_url = sinaShortenUrl($ticket_url);
  133. }
  134. }
  135. $extra_message = "";
  136. if( $short_url != false ) {
  137. $extra_message = "点击以下链接获取您的电子票扫码上车:{$short_url}";
  138. }
  139. //出票成功
  140. // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车,车牌号{车牌号},司机电话{司机姓司机电话}。";
  141. // 得到明天的时间
  142. date_default_timezone_set('PRC');
  143. //解决时区问题
  144. $tomorrow = date("Y-m-d", strtotime("+1 day"));
  145. $now_time = date('H:i:s', time());
  146. //判断当前时间是否在17:30:00之后
  147. $cur_date = date('Y-m-d', time());
  148. //迪士尼特殊情况parent_prod_id
  149. // $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);
  150. $dsn_arr_prod = array(); //用来保存迪士尼产品的prod_id
  151. foreach($dsn_prod as $temp){
  152. $dsn_arr_prod[]=$temp['prod_id'];
  153. }
  154. $zhou_su_arr_prod = array();
  155. foreach($zhou_su_prod as $temp){
  156. $zhou_su_arr_prod[]=$temp['prod_id'];
  157. }
  158. $new_message_array = array(448569,448568);
  159. if( in_array( $run_info['parent_prod_id'], $new_message_array ) ) {
  160. $content = "您预订的{出发日期}{出发地}-{目的地}{票种名}{张数}张,已成功出票,请在{出发时间}前十五分钟到达{上车站点}。出行前一天下午的18:00左右将会有导游和您联系,预祝您旅途愉快。";
  161. } else if (($now_time > "18:30:00" && $run_info['start_date'] == $tomorrow) || $cur_date == $run_info['start_date']) {//17:30之后的订单或者下单时间为今天出行为今天下午 发送短信模板
  162. // if("18:30:00">"17:30:00" && $run_info['start_date']==$tomorrow){ //17:30之后的订单 发送短信模板
  163. // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车,车牌号{车牌号},司机电话{司机姓司机电话}。";
  164. $content = "您预订的{出发日期}{出发地}-{目的地}{票种名}{张数}张,已成功出票,请在{出发时间}前三十分钟到达{上车站点}。您的乘车订单号为{订单号},车牌号{车牌号},司机电话{司机姓司机电话},请凭短信订单号乘车{$extra_message},预祝您旅途愉快。";
  165. if (in_array($run_info['parent_prod_id'], $dsn_arr_prod)) {
  166. $content = "您预订的{出发日期}{上车站点}-{下车站点}{票种名}{张数}张,已成功出票,请在{出发时间}前三十分钟到达{上车站点}。您的乘车订单号为{订单号}。请凭短信订单号乘车{$extra_message},预祝您旅途愉快。(如需咨询请致电:021-33280578)【zhizhuchuxing】Congratulations! Your ticket from hotel to Disney has been approved. Your order number is {订单号}. Please keep it and arrive at the place before {出发时间}. Enjoy your trip and have a nice day! If you have any questions, please call: 021-33280578.";
  167. $content = str_replace("{上车站点}", $run_info['res_name'], $content);
  168. $content = str_replace("{下车站点}", $run_info['end_res_name'], $content);
  169. $content = str_replace("{订单号}", $ORDER_ID, $content);
  170. }
  171. } else {
  172. // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车。";
  173. $content = "您预订的{出发日期}{出发地}-{目的地}{票种名}{张数}张,已成功出票,请在{出发时间}前三十分钟到达{上车站点}。您的乘车订单号为{订单号},请凭短信订单号乘车。出行前一天下午的18:30会将车牌号与司机电话发送给您,预祝您旅途愉快。";
  174. if (in_array($run_info['parent_prod_id'], $dsn_arr_prod)) {
  175. $ticket_url = TICKET_QR_URL.$ORDER_ID;
  176. $short_url = sinaShortenUrl($ticket_url);
  177. $extra_content = "";
  178. if( $short_url != false ) {
  179. $extra_content = "或点击以下链接获取乘车二维码扫码上车(".$short_url.")";
  180. }
  181. $content = "您预订的{出发日期}{上车站点}-{下车站点}{票种名}{张数}张,已成功出票,请在{出发时间}前三十分钟到达{上车站点}。您的乘车订单号为{订单号}。请凭短信订单号乘车{$extra_content},预祝您旅途愉快。(如需咨询请致电:021-33280578)【zhizhuchuxing】Congratulations! Your ticket from hotel to Disney has been approved. Your order number is {订单号}. Please keep it and arrive at the place before {出发时间}. Enjoy your trip and have a nice day! If you have any questions, please call: 021-33280578.";
  182. $content = str_replace("{上车站点}", $run_info['res_name'], $content);
  183. $content = str_replace("{下车站点}", $run_info['end_res_name'], $content);
  184. $content = str_replace("{订单号}", $ORDER_ID, $content);
  185. }
  186. }
  187. // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车。";
  188. if ($seat) {
  189. $seat_x = isset($seat['seat_x']) ? $seat['seat_x'] : "";
  190. $seat_y = isset($seat['seat_y']) ? $seat['seat_y'] : "";
  191. $seat_name = isset($seat['seat_name']) ? $seat['seat_name'] : "";
  192. $order_main_id = isset($seat['order_main_id']) ? $seat['order_main_id'] : "";
  193. } else {
  194. }
  195. if ($run_info) {
  196. $order_count = $run_info['order_count'];
  197. $start_date = $run_info['start_date'];
  198. $start_time = $run_info['start_time'];
  199. $parent_order_id = $run_info['parent_order_id'];
  200. $end_date = $run_info['end_date'];
  201. $start_area = $run_info['start_area'];
  202. $end_area = $run_info['end_area'];
  203. $res_name = $run_info['res_name'];
  204. $parent_prod_id = $run_info['parent_prod_id'];
  205. $prod_name = $run_info['prod_name'];
  206. $prod_name = "标准票";
  207. $customer_name = $run_info['customer_name'];
  208. $customer_mobile = $run_info['customer_mobile'];
  209. $start_end_date = $start_date . "," . $start_time;
  210. $content = str_replace("{出发日期}", $start_date, $content);
  211. $content = str_replace("{出发时间}", $start_time, $content);
  212. $content = str_replace("{上车站点}", $res_name, $content);
  213. $content = str_replace("{出发地}", $start_area, $content);
  214. $content = str_replace("{目的地}", $end_area, $content);
  215. $content = str_replace("{票种名}", $prod_name, $content);
  216. $content = str_replace("{张数}", $order_count, $content);
  217. $content = str_replace("{订单号}", $ORDER_ID, $content);
  218. } else {
  219. $content = str_replace("{出发日期}", "", $content);
  220. $content = str_replace("{出发时间}", "", $content);
  221. $content = str_replace("{出发地}", "", $content);
  222. $content = str_replace("{目的地}", "", $content);
  223. $content = str_replace("{票种名}", "", $content);
  224. $content = str_replace("{张数}", "", $content);
  225. $content = str_replace("{订单号}", "", $content);
  226. }
  227. if ($driver) {
  228. $bus_no = isset($driver['bus_no']) ? $driver['bus_no'] : "";
  229. $driver_name = isset($driver['driver_name']) ? $driver['driver_name'] : "";
  230. $driver_mobile = isset($driver['driver_mobile']) ? $driver['driver_mobile'] : "";
  231. if ($bus_no == "") {
  232. $content = str_replace(",车牌号{车牌号}", "", $content);
  233. } else {
  234. $content = str_replace("{车牌号}", $bus_no, $content);
  235. }
  236. if ($driver_name == "") {
  237. $content = str_replace(",司机电话{司机姓司机电话},", "。", $content);
  238. } else {
  239. $driver_xing = mb_substr($driver_name, 0, 1, 'utf-8');
  240. $driver_name_mobile = $driver_xing . $driver_mobile;
  241. $content = str_replace("{司机姓司机电话}", $driver_name_mobile, $content);
  242. }
  243. } else {
  244. $content = str_replace("车牌号{车牌号},", "", $content);
  245. $content = str_replace("司机电话{司机姓司机电话},", "", $content);
  246. }
  247. /*
  248. if( $now_time < "18:30:00" ) {
  249. //判断是不是苏州或周庄
  250. // 判断如果不是迪士尼的票就不发短信
  251. if (!in_array($run_info['parent_prod_id'], $dsn_arr_prod) && !in_array($run_info['parent_prod_id'], $zhou_su_arr_prod)) {
  252. return array("", "-1", "不是迪士尼、苏州、周庄的票,目前不发送短信");
  253. }
  254. }*/
  255. $content.="【重要提示】:因G20峰会影响,7月1号开始实名登记安检,出行时请所有游客携带有效证件(身份证或户口本),凭有效证件上车,如被查出无有效证件,导致无法出行,责任自行承担,谢谢配合!";
  256. return array(isset($customer_name) ? $customer_name : "", isset($customer_mobile) ? $customer_mobile : "", isset($content) ? $content : "短信错误,联系客服!!!");
  257. }
  258. }