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.
 
 
 
 
 

362 lines
20 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 '订单号没有接收到';
  12. die;
  13. }
  14. $sql_s = "select * from to_from where to_orderid=" . $order_id . " or back_orderid=" . $order_id;
  15. $result = $pdo->query($sql_s);
  16. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  17. //发送短信
  18. if ($rowset) {
  19. $ifback = 1;
  20. $to_order_id = $rowset[0]['to_orderid'];
  21. $back_order_id = $rowset[0]['back_orderid'];
  22. $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'] . ")";
  23. $result = $pdo->query($sql);
  24. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  25. foreach ($rowset as $v) {
  26. $list[] = $v['order_id'];
  27. }
  28. } else {
  29. $sql = "select order_id from order_main where order_id = " . $order_id . " or parent_order_id = " . $order_id;
  30. $result = $pdo->query($sql);
  31. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  32. foreach ($rowset as $v) {
  33. $list[] = $v['order_id'];
  34. }
  35. }
  36. //是否有至订单
  37. $list = implode(",", $list);
  38. $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 "
  39. . "from order_main a,order_main b "
  40. . "where a.order_id = b.PARENT_ORDER_ID and a.order_id in (" . $list . ") group by a.order_id";
  41. $result = $pdo->query($sql);
  42. $order_info = $result->fetchAll(PDO::FETCH_ASSOC);
  43. foreach ($order_info as $v) {
  44. $list_P[] = $v['order_pay_main_id'];
  45. }
  46. $list_P = implode(",", $list_P);
  47. $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 . ")";
  48. $rs = $pdo->query($sql_pay);
  49. $sql_order_status = "update order_main set order_status =146 where order_id in(" . $list . ")";
  50. $rs2 = $pdo->query($sql_order_status);
  51. $sql = "update `disney_order` set yet =0 where order_id =" . $order_id;
  52. $res = $pdo->query($sql);
  53. $sql_s = "select * from disney_order where order_id = " . $order_id;
  54. $result = $pdo->query($sql_s);
  55. $rows_d = $result->fetchAll(PDO::FETCH_ASSOC);
  56. $list_d = Find($order_id);
  57. if (!isset($rows_d[0]['order_id']) && $list_d['prod_id'] != 450517 && $list_d['prod_id'] != 450522) {
  58. if (isset($ifback)) {
  59. send_msg($to_order_id);
  60. send_msg($back_order_id);
  61. } else {
  62. send_msg($order_id);
  63. }
  64. }
  65. $log = $sql . '##' . $sql_pay . "##" . $sql_order_status;
  66. success_notify($log);
  67. function success_notify($result)
  68. {
  69. file_put_contents('./order_confirm.txt', date("Y-m-d H:i:s") . " " . $result . PHP_EOL, FILE_APPEND);//订单成功后通知后台日志
  70. }
  71. echo "支付成功";
  72. die;
  73. function send_msg($ORDER_ID)
  74. {
  75. $send_pdo = conn();
  76. $order_id = $ORDER_ID;
  77. $res_content = get_msg_info($order_id);
  78. $name = $res_content[0];
  79. $tel = $res_content[1];
  80. $content = $res_content[2];
  81. writeLog("短信模板内容:【" . $content . "】");
  82. //..发短信先取消
  83. $response = sendTelMessage($tel, $name, $content, $order_id);
  84. writeLog(json_encode($response));
  85. $comment_type = 0;
  86. $comment_text = "";
  87. $send_success = (int)$response;
  88. $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})";
  89. $result1 = $send_pdo->query($sql1);
  90. $rowset1 = $result1->fetchAll(PDO::FETCH_ASSOC);
  91. $result1->closeCursor();
  92. writeLog("hotel_order_status.php HT_ADD_MSG_COMMENT()::" . $sql1);
  93. //insert order extra
  94. $hotelPrice = isset($_GET['hotelPrice']) ? $_GET['hotelPrice'] : "";
  95. $doorPrice = isset($_GET["doorPrice"]) ? $_GET["doorPrice"] : "";
  96. if ($hotelPrice != "" || $doorPrice != "") {
  97. $sqlInsert = " INSERT INTO order_extra_info (order_id,hotel_price,gate_price) VALUE(" . $ORDER_ID . ",'" . $hotelPrice . "','" . $doorPrice . "') ";
  98. writeLog("insert extra info: " . $sqlInsert);
  99. $result = $send_pdo->exec($sqlInsert);
  100. }
  101. }
  102. //..短信模板-改为17:30后OK,当天下单也OK
  103. function get_msg_info($ORDER_ID)
  104. {
  105. $msg_pdo = conn();
  106. $msg_sql = "CALL SP_GET_MESSAGE_TEMPLATE('" . $ORDER_ID . "')";
  107. $content = '';
  108. if (is_object($msg_pdo)) {
  109. $msg_result = $msg_pdo->query($msg_sql);
  110. $i = 1;
  111. $data = array();
  112. if ($msg_result) {
  113. $data['code'] = "0";
  114. $data['info'] = "";
  115. do {
  116. $row = $msg_result->fetchAll(PDO::FETCH_ASSOC);
  117. if ($i == 1) {
  118. $data['seat'] = isset($row) ? $row : array();
  119. } else if ($i == 2) {
  120. $data['run_info'] = isset($row) ? $row : array();
  121. } else if ($i == 3) {
  122. $data['driver'] = isset($row) ? $row : array();
  123. } else if ($i == 4) {
  124. $data['dsn_prod'] = isset($row) ? $row : array();
  125. } else if ($i == 5) {
  126. $data['zhou_su_prod'] = isset($row) ? $row : array();
  127. }
  128. $i++;
  129. } while ($msg_result->nextRowset());
  130. }
  131. $json_obj = json_decode(json_encode($data), TRUE);
  132. $seat = isset($json_obj['seat'][0]) ? $json_obj['seat'][0] : array();
  133. $run_info = isset($json_obj['run_info'][0]) ? $json_obj['run_info'][0] : array();
  134. $driver = isset($json_obj['driver'][0]) ? $json_obj['driver'][0] : array();
  135. $dsn_prod = isset($json_obj['dsn_prod']) ? $json_obj['dsn_prod'] : array();
  136. $zhou_su_prod = isset($json_obj['zhou_su_prod']) ? $json_obj['zhou_su_prod'] : array();
  137. $bus_res_id = isset($json_obj['driver'][0]) ? $json_obj['driver'][0]["bus_res_id"] : 0;
  138. $short_url = false;
  139. if ($bus_res_id != 0) {
  140. $ary_sell_ary = array(916, 917);
  141. if (in_array($bus_res_id, $ary_sell_ary)) {
  142. $ticket_url = TICKET_QR_URL . $ORDER_ID;
  143. $short_url = sinaShortenUrl($ticket_url);
  144. }
  145. }
  146. $extra_message = "";
  147. if ($short_url != false) {
  148. $extra_message = "点击以下链接获取您的电子票扫码上车:{$short_url}";
  149. }
  150. //出票成功
  151. // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车,车牌号{车牌号},司机电话{司机姓司机电话}。";
  152. // 得到明天的时间
  153. date_default_timezone_set('PRC');
  154. //解决时区问题
  155. $tomorrow = date("Y-m-d", strtotime("+1 day"));
  156. $now_time = date('H:i:s', time());
  157. //判断当前时间是否在17:30:00之后
  158. $cur_date = date('Y-m-d', time());
  159. //迪士尼特殊情况parent_prod_id
  160. // $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);
  161. $dsn_arr_prod = array(); //用来保存迪士尼产品的prod_id
  162. foreach ($dsn_prod as $temp) {
  163. $dsn_arr_prod[] = $temp['prod_id'];
  164. }
  165. $zhou_su_arr_prod = array();
  166. foreach ($zhou_su_prod as $temp) {
  167. $zhou_su_arr_prod[] = $temp['prod_id'];
  168. }
  169. $new_message_array = array(448569, 448568);
  170. $new_message_array2 = array(449860, 449865, 450036, 450037);
  171. if (($now_time > "18:30:00" && $run_info['start_date'] == $tomorrow) || $cur_date == $run_info['start_date']) {//17:30之后的订单或者下单时间为今天出行为今天下午 发送短信模板
  172. // if("18:30:00">"17:30:00" && $run_info['start_date']==$tomorrow){ //17:30之后的订单 发送短信模板
  173. // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车,车牌号{车牌号},司机电话{司机姓司机电话}。";
  174. if (in_array($run_info['parent_prod_id'], $new_message_array)) {
  175. $content = "您预订的{出发日期}{出发地}-{目的地}{票种名}{张数}张,已成功出票,请在{出发时间}前十五分钟到达{上车站点}。您的乘车订单号为{订单号},车牌号{车牌号},司机电话{司机姓司机电话},请凭短信订单号乘车{$extra_message},预祝您旅途愉快。";
  176. } elseif (in_array($run_info['parent_prod_id'], $new_message_array2)) {
  177. $content = "您已成功预订{出发地}-{目的地}城际商务车{张数}张车票,车型为奔驰7座,发车时间为{出发日期} {出发时间},请提前10分钟到达{上车站点}。您的乘车订单号为{订单号},车牌号{车牌号},司机电话{司机姓司机电话},请凭短信订单号乘车{$extra_message},预祝您旅途愉快。";
  178. } else {
  179. $content = "您预订的{出发日期}{出发地}-{目的地}{票种名}{张数}张,已成功出票,请在{出发时间}前三十分钟到达{上车站点}。您的乘车订单号为{订单号},车牌号{车牌号},司机电话{司机姓司机电话},请凭短信订单号乘车{$extra_message},预祝您旅途愉快。";
  180. }
  181. if (in_array($run_info['parent_prod_id'], $dsn_arr_prod)) {
  182. $content = "您预订的{上车站点}-{下车站点}车票{张数}张(订单号{订单号})已经预订成功。发车时间为{出发日期} {出发时间},请提前10分钟到达并向司机出示手机二维码/预订号乘车。上车地址为{上车站点}:{上车站点详细地址}。{$extra_message}请关注微信公众号“蜘蛛出行”,可以实时查询大巴定位、司机号码、车牌号等。";
  183. $start_station_address = $run_info['start_station_address'];
  184. $content = str_replace("{上车站点详细地址}", $start_station_address, $content);
  185. $content = str_replace("{上车站点}", $run_info['res_name'], $content);
  186. $content = str_replace("{下车站点}", $run_info['end_res_name'], $content);
  187. $content = str_replace("{订单号}", $ORDER_ID, $content);
  188. }
  189. } else {
  190. // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车。";
  191. $content = "您预订的{出发日期}{出发地}-{目的地}{票种名}{张数}张,已成功出票,请在{出发时间}前十分钟到达{上车站点}。您的乘车订单号为{订单号},请凭短信订单号乘车。出行前一天下午的18:30会将车牌号与司机电话发送给您,预祝您旅途愉快。";
  192. if (in_array($run_info['parent_prod_id'], $dsn_arr_prod)) {
  193. $ticket_url = TICKET_QR_URL . $ORDER_ID;
  194. $short_url = sinaShortenUrl($ticket_url);
  195. $extra_content = "";
  196. if ($short_url != false) {
  197. $extra_content = "或点击以下链接获取乘车二维码扫码上车(" . $short_url . ")";
  198. }
  199. $content = "您预订的{上车站点}-{下车站点}车票{张数}张(订单号{订单号})已经预订成功。发车时间为{出发日期} {出发时间},请提前10分钟到达并向司机出示手机二维码/预订号乘车。上车地址为{上车站点}:{上车站点详细地址}。{$extra_message}请关注微信公众号“蜘蛛出行”,可以实时查询大巴定位、司机号码、车牌号等。";
  200. $start_station_address = $run_info['start_station_address'];
  201. $content = str_replace("{上车站点详细地址}", $start_station_address, $content);
  202. $content = str_replace("{上车站点}", $run_info['res_name'], $content);
  203. $content = str_replace("{下车站点}", $run_info['end_res_name'], $content);
  204. $content = str_replace("{订单号}", $ORDER_ID, $content);
  205. }
  206. }
  207. $new_message_array3 = array(450517, 450522);
  208. if (in_array($run_info['parent_prod_id'], $new_message_array3)) {
  209. if ($run_info['parent_prod_id'] == 450517) {
  210. $address_txt = "上车地点:吴山广场西侧河坊巷8号(吴山广场旅游集散中心候车室); 上车方式:请至吴山广场旅游集散中心候车室服务台,凭预定姓名和手机号码上车。";
  211. } else {
  212. $address_txt = "上车地点:普陀城北长途客运中心; 上车方式:请提前到达,凭票上车。取票方式:(学运路18号)普陀城北长途客运中心旅客出口处,97自驾服务中心,报预订名字取票。";
  213. }
  214. $content = "您已成功预定{出发日期} {出发时间} {出发地}-{目的地}汽车票{张数}张(请最晚提前10分钟到达)。{$address_txt}联系电话4006-726-756。";
  215. }
  216. // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车。";
  217. if ($seat) {
  218. $seat_x = isset($seat['seat_x']) ? $seat['seat_x'] : "";
  219. $seat_y = isset($seat['seat_y']) ? $seat['seat_y'] : "";
  220. $seat_name = isset($seat['seat_name']) ? $seat['seat_name'] : "";
  221. $order_main_id = isset($seat['order_main_id']) ? $seat['order_main_id'] : "";
  222. } else {
  223. }
  224. if ($run_info) {
  225. $order_count = $run_info['order_count'];
  226. $start_date = $run_info['start_date'];
  227. $start_time = $run_info['start_time'];
  228. $parent_order_id = $run_info['parent_order_id'];
  229. $end_date = $run_info['end_date'];
  230. $start_area = $run_info['start_area'];
  231. $end_area = $run_info['end_area'];
  232. $res_name = $run_info['res_name'];
  233. $parent_prod_id = $run_info['parent_prod_id'];
  234. $prod_name = $run_info['prod_name'];
  235. $prod_name = "标准票";
  236. $customer_name = $run_info['customer_name'];
  237. $customer_mobile = $run_info['customer_mobile'];
  238. $start_end_date = $start_date . "," . $start_time;
  239. $content = str_replace("{出发日期}", $start_date, $content);
  240. $content = str_replace("{出发时间}", $start_time, $content);
  241. $content = str_replace("{上车站点}", $res_name, $content);
  242. $content = str_replace("{出发地}", $start_area, $content);
  243. $content = str_replace("{目的地}", $end_area, $content);
  244. $content = str_replace("{票种名}", $prod_name, $content);
  245. $content = str_replace("{张数}", $order_count, $content);
  246. $content = str_replace("{订单号}", $ORDER_ID, $content);
  247. } else {
  248. $content = str_replace("{出发日期}", "", $content);
  249. $content = str_replace("{出发时间}", "", $content);
  250. $content = str_replace("{出发地}", "", $content);
  251. $content = str_replace("{目的地}", "", $content);
  252. $content = str_replace("{票种名}", "", $content);
  253. $content = str_replace("{张数}", "", $content);
  254. $content = str_replace("{订单号}", "", $content);
  255. }
  256. if ($driver) {
  257. $bus_no = isset($driver['bus_no']) ? $driver['bus_no'] : "";
  258. $driver_name = isset($driver['driver_name']) ? $driver['driver_name'] : "";
  259. $driver_mobile = isset($driver['driver_mobile']) ? $driver['driver_mobile'] : "";
  260. if ($bus_no == "") {
  261. $content = str_replace(",车牌号{车牌号}", "", $content);
  262. } else {
  263. $content = str_replace("{车牌号}", $bus_no, $content);
  264. }
  265. if ($driver_name == "") {
  266. $content = str_replace(",司机电话{司机姓司机电话},", "。", $content);
  267. } else {
  268. $driver_xing = mb_substr($driver_name, 0, 1, 'utf-8');
  269. $driver_name_mobile = $driver_xing . $driver_mobile;
  270. $content = str_replace("{司机姓司机电话}", $driver_name_mobile, $content);
  271. }
  272. } else {
  273. $content = str_replace("车牌号{车牌号},", "", $content);
  274. $content = str_replace("司机电话{司机姓司机电话},", "", $content);
  275. }
  276. /*
  277. if( $now_time < "18:30:00" ) {
  278. //判断是不是苏州或周庄
  279. // 判断如果不是迪士尼的票就不发短信
  280. if (!in_array($run_info['parent_prod_id'], $dsn_arr_prod) && !in_array($run_info['parent_prod_id'], $zhou_su_arr_prod)) {
  281. return array("", "-1", "不是迪士尼、苏州、周庄的票,目前不发送短信");
  282. }
  283. }*/
  284. return array(isset($customer_name) ? $customer_name : "", isset($customer_mobile) ? $customer_mobile : "", isset($content) ? $content : "短信错误,联系客服!!!");
  285. }
  286. }
  287. function Find($order_id)
  288. {
  289. $pdo = conn();
  290. $sql = "select order_description,order_price,order_status "
  291. . "from order_main "
  292. . "where order_id=" . $order_id;
  293. $result = $pdo->query($sql);
  294. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  295. $order_price = $rowset[0];//订单总价格 订单票的数量
  296. $sql = "SELECT DISTINCT
  297. order_description,parent_order_id,create_time,parent_prod_id,prod_name,run_date,run_time,PROD_START_STATION_AREA_NAME,PROD_START_STATION_RES_NAME,PROD_END_STATION_AREA_NAME,PROD_END_STATION_RES_NAME
  298. FROM `order_main`
  299. where PARENT_ORDER_ID=" . $order_id;
  300. $result = $pdo->query($sql);
  301. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  302. $order_station = $rowset[0];//订单来往地址 订单时间 订单好
  303. if (empty($order_station))
  304. return false;
  305. $array_order_desc = array();
  306. $arr_temp = explode('|', $order_price['order_description']);
  307. $arr = array();
  308. foreach ($arr_temp as $k => $v2) {
  309. if (!empty($v2))
  310. $array_order_desc[] = explode(',', $v2); //订单票 * 数量
  311. }
  312. $list = array();
  313. //上海(黄浦旅游集散站) - 乌镇(西栅1号停车场)//反的数组
  314. $list['station'] = $order_station['PROD_START_STATION_AREA_NAME'] . '(' . $order_station['PROD_START_STATION_RES_NAME'] . ')'
  315. . '-' . $order_station['PROD_END_STATION_AREA_NAME'] . '(' . $order_station['PROD_END_STATION_RES_NAME'] . ')';
  316. $list['start_station'] = $order_station['PROD_START_STATION_AREA_NAME'];
  317. $list['end_station'] = $order_station['PROD_END_STATION_AREA_NAME'];
  318. $list['start_res_name'] = $order_station['PROD_START_STATION_RES_NAME'];
  319. $list['end_res_name'] = $order_station['PROD_END_STATION_RES_NAME'];
  320. $list['run_date'] = $order_station['run_date'];
  321. $list['prod_name'] = $order_station['prod_name'];
  322. $list['prod_id'] = $order_station['parent_prod_id'];
  323. $list['create_time'] = $order_station['create_time'];
  324. $list['run_time'] = $order_station['run_date'] . ' ' . $order_station['run_time'];
  325. $list['count'] = '';
  326. foreach ($array_order_desc as $v) {
  327. $list['count'] .= ' ' . $v[0] . ' × ' . $v[2];
  328. }
  329. $list['order_price'] = $order_price['order_price'];
  330. $list['order_status'] = $order_price['order_status'];
  331. return $list;
  332. }