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.
 
 
 
 

197 lines
8.1 KiB

  1. <?php
  2. /*
  3. Author:XM
  4. Compeny:Spiders Travel
  5. */
  6. //酒店订单状态修改 ,确认、支付、通知、安排
  7. require_once __DIR__ . '/../Common/Mysql.php';
  8. if (ALLOW_ORIGIN)
  9. header("Access-Control-Allow-Origin:*");
  10. $order_id = isset($_GET['order_id']) ? $_GET['order_id'] : '';
  11. $method = isset($_GET['method']) ? $_GET['method'] : '';
  12. $comment_code = isset($_GET['comment_code']) ? $_GET['comment_code'] : '';
  13. $comment_text = isset($_GET['comment_text']) ? $_GET['comment_text'] : '';
  14. $pay_type = isset($_GET['pay_type']) ? (empty($_GET['pay_type']) ? 0 : $_GET['pay_type']) : 0;
  15. $serial_number = isset($_GET['serial_number']) ? $_GET['serial_number'] : '';
  16. $comment_type = isset($_GET['comment_type']) ? (empty($_GET['comment_type']) ? 0 : $_GET['comment_type']) : 0;
  17. if ($order_id == '' || $method == '') {
  18. echo json_encode(array("errcode" => 2, "errinfo" => "参数不能为空"));
  19. exit ;
  20. }
  21. if ($method == 'pay' && $pay_type == 0) {
  22. echo json_encode(array("errcode" => 2, "errinfo" => "参数不能为空"));
  23. exit ;
  24. } else if ($method == 'confirmnum' && ($comment_code == '' || $comment_text == '')) {
  25. echo json_encode(array("errcode" => 2, "errinfo" => "参数不能为空"));
  26. exit ;
  27. } else if ($method == 'addcomment' && ($comment_text == '')) {
  28. echo json_encode(array("errcode" => 2, "errinfo" => "参数不能为空"));
  29. exit ;
  30. }
  31. $userid = getUserId();
  32. if ($userid === false) {
  33. echo json_encode(array("errcode" => 1, "errinfo" => "用户未登录"));
  34. exit ;
  35. }
  36. $pdo = conn();
  37. if (is_object($pdo)) {
  38. if ($method == 'addcomment') {
  39. $sql = "CALL HT_ADD_MSG_COMMENT(" . $userid . ",'" . $method . "'," . $order_id . "," . $comment_type . ",'" . $comment_text . "','','','',0)";
  40. $result = $pdo -> query($sql);
  41. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  42. writeLog("hotel_order_status.php HT_ADD_MSG_COMMENT()::" . $sql);
  43. } else {
  44. $sql = "CALL HT_ORDER_STATUS_MODIFY(" . $userid . ",'" . $method . "'," . $order_id . ",'" . $comment_code . "','" . $comment_text . "'," . $pay_type . ",'" . $serial_number . "')";
  45. writeLog('hotel_order_status.php ::' . $sql);
  46. $result = $pdo -> query($sql);
  47. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  48. $result -> closeCursor();
  49. writeLog(json_encode($rowset));
  50. if (is_array($rowset[0]) && $rowset[0]['code'] == 0 && SEND_MESSAGE == true) {
  51. $rowset_order_status=$rowset[0]['ORDER_STATUS'];
  52. if($rowset_order_status==145 || $rowset_order_status==198 || $rowset_order_status==199 || $rowset_order_status==201 ||$rowset_order_status==238 || $rowset_order_status==148){
  53. $res_content=get_msg_info($order_id);
  54. $name=$res_content[0];
  55. $tel=$res_content[1];
  56. $content=$res_content[2];
  57. // $content = "单号:" . $order_id . ',订单状态变更为' . $order_status . "随机数" . rand(1, 10000);
  58. writeLog("短信模板内容:【" . $content . "】");
  59. $response = sendTelMessage($tel, $name, $content, $order_id);
  60. writeLog(json_encode($response));
  61. $send_success = (int)$response;
  62. $sql1 = "CALL HT_ADD_MSG_COMMENT(" . $userid . ",'addmsg'," . $order_id . "," . $comment_type . ",'" . $comment_text . "','" . $tel . "','" . $content . "','" . date("Y-m-d H:i:s") . "',".$send_success.")";
  63. $result1 = $pdo -> query($sql1);
  64. $rowset1 = $result1 -> fetchAll(PDO::FETCH_ASSOC);
  65. $result1 -> closeCursor();
  66. writeLog("hotel_order_status.php HT_ADD_MSG_COMMENT()::" . $sql1);
  67. }
  68. }
  69. //unset($rowset[0]['CUSTOMER_NAME']);
  70. //unset($rowset[0]['CUSTOMER_MOBILE']);
  71. writeLog("hotel_order_status.php HT_ORDER_STATUS_MODIFY()::" . $sql);
  72. }
  73. }
  74. function get_msg_info($order_id) {
  75. $msg_sql = "CALL HT_GET_MESSAGE_TEMPLATE(" . $order_id . ");";
  76. $msg_pdo = conn();
  77. $msg_result = $msg_pdo -> query($msg_sql);
  78. $msg_re_da = array();
  79. do {
  80. $msg_rowset = $msg_result -> fetchAll(PDO::FETCH_ASSOC);
  81. if ($msg_rowset) {
  82. $msg_re_da[] = $msg_rowset;
  83. }
  84. } while($msg_result->nextRowset());
  85. $data['code'] = "0";
  86. $data['info'] = "";
  87. if (!$msg_re_da) {
  88. $data['code'] = "-1";
  89. $data['info'] = "没有查询到结果";
  90. if (is_array($data)) {
  91. echo json_encode($data);
  92. exit();
  93. }
  94. }
  95. $data['message_info'] = isset($msg_re_da[1]) ? $msg_re_da[1] : array();
  96. if (!isset($msg_re_da[1])) {
  97. $data['code'] = "-1";
  98. $data['info'] = "失败";
  99. if (is_array($data)) {
  100. echo json_encode($data);
  101. exit();
  102. }
  103. }
  104. $data['days'] = $msg_re_da[0][0]['days'];
  105. $data['all_price'] = $msg_re_da[0][0]['all_price'];
  106. $data['message_info'] = $msg_re_da[1];
  107. writeLog("get_msg_info:::".json_encode($data));
  108. $json_obj = json_decode(json_encode($data), TRUE);
  109. $message_info = $json_obj['message_info'];
  110. //$msg_customer_name=$message_info[0]['customer_name'];//用户姓名
  111. $name = $message_info[0]['customer_name'];
  112. $tel = $message_info[0]['customer_mobile'];
  113. $order_status = $message_info[0]['order_status'];
  114. //入住日期-主订单的入住日期=子订单第一个的日期
  115. $check_in_date = $message_info[0]['check_in_date'];
  116. //产品名称-所有日期的产品名称相同
  117. $prod_name = $message_info[0]['prod_name'];
  118. $ht_rooms = $message_info[0]['ht_rooms'];
  119. //酒店间数 -1表示没有
  120. for ($i = 0, $m = count($message_info); $i < $m; $i++) {
  121. $tm_day = $message_info[$i]['ht_rooms'];
  122. if ($ht_rooms == $tm_day) {
  123. continue;
  124. } else {
  125. $ht_rooms = "-1";
  126. break;
  127. }
  128. }
  129. $days = $json_obj['days'];
  130. //预订天数
  131. $all_price = $json_obj['all_price'];
  132. //总价格
  133. $breakfast = $message_info[0]['breakfast'];
  134. //早餐
  135. for ($i = 0, $m = count($message_info); $i < $m; $i++) {
  136. $tm_breakfast = $message_info[$i]['breakfast'];
  137. if ($breakfast == $tm_breakfast) {
  138. continue;
  139. } else {
  140. $breakfast = "-1";
  141. break;
  142. }
  143. }
  144. $content = "";
  145. //判断order_status的值
  146. if ($order_status == "145") {//待支付
  147. $content = "{customer_name}预订的{check_in_date}{prod_name},{ht_rooms}间{days}晚,总价{order_price}({breakfast}),订单已生成,请尽快支付以免影响您的出行。";
  148. } else if ($order_status == "198") {//待确定
  149. $content = "已支付,待确认:{customer_name}预订的{check_in_date}{prod_name},{ht_rooms}间{days}晚,总价{order_price}({breakfast}),房间将在2小时内确认,请耐心等待确认信息。";
  150. } else if ($order_status == "199") {//待通知
  151. $content = "已确认:{customer_name}预订的{check_in_date}{prod_name},{ht_rooms}间{days}晚,总价{order_price}({breakfast}),已安排房间。";
  152. } else if ($order_status == "201") {//退改中
  153. $content = "{customer_name}预订的{check_in_date}{prod_name},{ht_rooms}间{days}晚,总价{order_price}({breakfast}),酒店方确认当日无房,正在安排退款,请耐心等待。联系客服:021-33280578。";
  154. } else if ($order_status == "238") {//已退单
  155. $content = "退款成功:{customer_name}预订的{check_in_date}{prod_name},{ht_rooms}间{days}晚,总价{order_price}({breakfast}),酒店方确认当日无房,已成功退款,请留意银行相关退款信息。联系客服:021-33280578。";
  156. } else if ($order_status == "148") {
  157. $content = "已取消:{customer_name}预订的{check_in_date}{prod_name},{ht_rooms}间{days}晚,总价{order_price}({breakfast}),已取消。联系客服:021-33280578。";
  158. } else {
  159. $content = "短信模板错误---严重错误:500当前状态".$order_status;
  160. writeLog($content);
  161. exit();
  162. }
  163. $content = str_replace("{customer_name}", $name, $content);
  164. $content = str_replace("{check_in_date}", $check_in_date, $content);
  165. $content = str_replace("{prod_name}", $prod_name, $content);
  166. //判断房间数是否该显示
  167. if ($ht_rooms != "-1") {
  168. $content = str_replace("{ht_rooms}", $ht_rooms, $content);
  169. } else {
  170. $content = str_replace("{ht_rooms}间", "", $content);
  171. }
  172. $content = str_replace("{days}", $days, $content);
  173. $content = str_replace("{order_price}", $all_price, $content);
  174. //判断早餐是否该显示
  175. if ($breakfast != "-1") {
  176. $content = str_replace("{breakfast}", $breakfast, $content);
  177. } else {
  178. $content = str_replace("({breakfast})", "", $content);
  179. }
  180. return array($name,$tel,$content);
  181. }
  182. if (is_array($rowset[0])) {
  183. writeLog("hotel_order_status.php HT_ORDER_STATUS_MODIFY()::" . json_encode($rowset[0]));
  184. echo json_encode($rowset[0]);
  185. }
  186. exit ;