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.
 
 
 
 

261 lines
11 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. $prod_id=isset($_POST['prod_id'])?$_POST['prod_id']:'';
  11. $prod_name=isset($_POST['prod_name'])?$_POST['prod_name']:'';
  12. $method=isset($_POST['method'])?$_POST['method']:'';
  13. $order_from=isset($_POST['order_from']) && !empty($_POST['order_from'])?$_POST['order_from']:0;
  14. $distributors=isset($_POST['distributors']) && !empty($_POST['distributors']) ?$_POST['distributors']:0;
  15. $out_order_id=isset($_POST['outside_order_id'])?$_POST['outside_order_id']:'';
  16. $arrive_latest_time=isset($_POST['arrive_latest_time'])?$_POST['arrive_latest_time']:'';
  17. $maxcount=isset($_POST['maxcount']) && !empty($_POST['maxcount'])?$_POST['maxcount']:0;
  18. $customer_name=isset($_POST['customer_name'])?$_POST['customer_name']:'';
  19. $customer_mobile=isset($_POST['customer_mobile'])?$_POST['customer_mobile']:0;
  20. $order_comment=isset($_POST['order_comment'])?$_POST['order_comment']:'';
  21. $order_id=isset($_POST['order_id']) && !empty($_POST['order_id']) ?$_POST['order_id']:0;
  22. if($order_from ==177 && ($distributors==0 || $out_order_id=='')){
  23. echo json_encode(array("errcode"=>2,"errinfo"=>"分销商或外部订单号参数不能为空"));
  24. exit;
  25. }
  26. if($maxcount>0){
  27. $prod_list='';
  28. $total_base_price=$total_mid_price=$total_order_price=$total_num= 0;
  29. $prod_description='';
  30. $check_in_date_array=array();
  31. for($i=0;$i<$maxcount;$i++){
  32. $check_in_date=isset($_POST['check_in_date_'.$i])?$_POST['check_in_date_'.$i]:'';
  33. if ($check_in_date !=''){
  34. $check_in_date_array[]=$check_in_date;
  35. }
  36. $run_id=isset($_POST['run_id_'.$i])?$_POST['run_id_'.$i]:0;
  37. $room_count=isset($_POST['room_count_'.$i])?$_POST['room_count_'.$i]:0;
  38. $base_price=isset($_POST['base_price_'.$i])?$_POST['base_price_'.$i]:0;
  39. $mid_price=isset($_POST['mid_price_'.$i])?$_POST['mid_price_'.$i]:0;
  40. $order_price=isset($_POST['order_price_'.$i])?$_POST['order_price_'.$i]:0;
  41. $t_base_price=$base_price*$room_count;
  42. $t_mid_price=$mid_price*$room_count;
  43. $t_order_price=$order_price*$room_count;
  44. $total_base_price+=$t_base_price;
  45. $total_mid_price+=$t_mid_price;
  46. $total_order_price+=$t_order_price;
  47. $total_num+=$room_count;
  48. $prod_description.=$prod_name.",".$check_in_date.",".$room_count."|";
  49. $prod_list.=$check_in_date."^".$run_id."^".$room_count."^".$base_price."^".$mid_price."^".$order_price."*";
  50. }
  51. $prod_list=rtrim($prod_list,"*");
  52. $prod_description=rtrim($prod_description,"|");
  53. }else{
  54. echo json_encode(array("errcode"=>3,"errinfo"=>"没有预定入住日期"));
  55. exit;
  56. }
  57. if ($method =='' || $customer_name=='' || $customer_mobile==0){
  58. echo json_encode(array("errcode"=>3,"errinfo"=>"客人信息或者method参数不能为空"));
  59. exit;
  60. }
  61. $para_org_list=$prod_id."^".$distributors."^".$out_order_id."^".($total_num+1)."^".$total_base_price."^".$total_mid_price."^".$total_order_price."^".$prod_description."^".$arrive_latest_time."^".min($check_in_date_array);
  62. $customer_list=$customer_name."^".$customer_mobile."^".$order_comment;
  63. $userid=getUserId();
  64. if ($userid ===false){
  65. echo json_encode(array("errcode"=>1,"errinfo"=>"用户未登录"));
  66. exit;
  67. }
  68. $pdo=conn();
  69. if(is_object($pdo)){
  70. if($method=='add'){
  71. $sql="CALL HT_SUBMIT_ORDER(".$userid.",'".$method."','".$para_org_list."','".$prod_list."','".$customer_list."',".$order_id.")";
  72. writeLog("hotel_submit_order.php HT_SUBMIT_ORDER()::sql".$sql);
  73. $result=$pdo->query($sql);
  74. $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
  75. $result->closeCursor();
  76. writeLog("hotel_submit_order.php HT_SUBMIT_ORDER()::rowset".json_encode($rowset));
  77. if (is_array($rowset[0]) && $rowset[0]['code']==0){
  78. if (SEND_MESSAGE == true) {
  79. $order_id=$rowset[0]['global_order_id'];
  80. $rowset_order_status=145;
  81. $res_content=get_msg_info($order_id);
  82. $name=$res_content[0];
  83. $tel=$res_content[1];
  84. $content=$res_content[2];
  85. // $content = "单号:" . $order_id . ',订单状态变更为' . $order_status . "随机数" . rand(1, 10000);
  86. writeLog("短信模板内容:【" . $content . "】");
  87. $response = sendTelMessage($tel, $name, $content, $order_id);
  88. writeLog(json_encode($response));
  89. $send_success = (int)$response;
  90. $sql1 = "CALL HT_ADD_MSG_COMMENT(" . $userid . ",'addmsg'," . $order_id . ",0,'','" . $tel . "','" . $content . "','" . date("Y-m-d H:i:s") . "',{$send_success})";
  91. $result1 = $pdo -> query($sql1);
  92. $rowset1 = $result1 -> fetchAll(PDO::FETCH_ASSOC);
  93. $result1 -> closeCursor();
  94. writeLog("hotel_order_status.php HT_ADD_MSG_COMMENT()::" . $sql1);
  95. }
  96. $url= "http://".$_SERVER['HTTP_HOST']."/hotelOrderList.html";
  97. echo "<script>alert('下单成功');document.location.href='".$url."'</script>";
  98. //header("Location: $url");
  99. exit;
  100. }else{
  101. $url= "http://".$_SERVER['HTTP_HOST']."/hotelPlaceOrder.html?prod_id=".$prod_id;
  102. echo "<script>alert('下单失败');document.location.href='".$url."'</script>";
  103. exit;
  104. }
  105. }else if($method=='modify'){
  106. $sql="CALL HT_SUBMIT_ORDER(".$userid.",'".$method."','".$para_org_list."','".$prod_list."','".$customer_list."',".$order_id.")";
  107. writeLog("hotel_submit_order.php HT_SUBMIT_ORDER():: modify ::sql".$sql);
  108. $result=$pdo->query($sql);
  109. $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
  110. $result->closeCursor();
  111. writeLog("hotel_submit_order.php HT_SUBMIT_ORDER():: modify :: rowset".json_encode($rowset));
  112. if (is_array($rowset[0]) && $rowset[0]['code']==0){
  113. if (SEND_MESSAGE == true) {
  114. $rowset_order_status=145;
  115. $res_content=get_msg_info($order_id);
  116. $name=$res_content[0];
  117. $tel=$res_content[1];
  118. $content=$res_content[2];
  119. // $content = "单号:" . $order_id . ',订单状态变更为' . $order_status . "随机数" . rand(1, 10000);
  120. writeLog("短信模板内容:【" . $content . "】");
  121. $response = sendTelMessage($tel, $name, $content, $order_id);
  122. writeLog(json_encode($response));
  123. }
  124. $url= "http://".$_SERVER['HTTP_HOST']."/hotelWaitConfirm.html?order_id=".$order_id;
  125. echo "<script>alert('修改成功');document.location.href='".$url."'</script>";
  126. //header("Location: $url");
  127. exit;
  128. }else{
  129. $url= "http://".$_SERVER['HTTP_HOST']."/hotelOrderList.html";
  130. echo "<script>alert('修改失败');alert('".$rowset[0]['info']."');document.location.href='".$url."'</script>";
  131. exit;
  132. }
  133. }
  134. }
  135. function get_msg_info($order_id) {
  136. $msg_sql = "CALL HT_GET_MESSAGE_TEMPLATE(" . $order_id . ");";
  137. writeLog($msg_sql);
  138. $msg_pdo = conn();
  139. $msg_result = $msg_pdo -> query($msg_sql);
  140. $msg_re_da = array();
  141. do {
  142. $msg_rowset = $msg_result -> fetchAll(PDO::FETCH_ASSOC);
  143. if ($msg_rowset) {
  144. $msg_re_da[] = $msg_rowset;
  145. }
  146. } while($msg_result->nextRowset());
  147. $data['code'] = "0";
  148. $data['info'] = "";
  149. if (!$msg_re_da) {
  150. $data['code'] = "-1";
  151. $data['info'] = "没有查询到结果";
  152. if (is_array($data)) {
  153. echo json_encode($data);
  154. exit();
  155. }
  156. }
  157. $data['message_info'] = isset($msg_re_da[1]) ? $msg_re_da[1] : array();
  158. if (!isset($msg_re_da[1])) {
  159. $data['code'] = "-1";
  160. $data['info'] = "失败";
  161. if (is_array($data)) {
  162. echo json_encode($data);
  163. exit();
  164. }
  165. }
  166. $data['days'] = $msg_re_da[0][0]['days'];
  167. $data['all_price'] = $msg_re_da[0][0]['all_price'];
  168. $data['message_info'] = $msg_re_da[1];
  169. writeLog("get_msg_info:::".json_encode($data));
  170. $json_obj = json_decode(json_encode($data), TRUE);
  171. $message_info = $json_obj['message_info'];
  172. //$msg_customer_name=$message_info[0]['customer_name'];//用户姓名
  173. $name = $message_info[0]['customer_name'];
  174. $tel = $message_info[0]['customer_mobile'];
  175. $order_status = $message_info[0]['order_status'];
  176. //入住日期-主订单的入住日期=子订单第一个的日期
  177. $check_in_date = $message_info[0]['check_in_date'];
  178. //产品名称-所有日期的产品名称相同
  179. $prod_name = $message_info[0]['prod_name'];
  180. $ht_rooms = $message_info[0]['ht_rooms'];
  181. //酒店间数 -1表示没有
  182. for ($i = 0, $m = count($message_info); $i < $m; $i++) {
  183. $tm_day = $message_info[$i]['ht_rooms'];
  184. if ($ht_rooms == $tm_day) {
  185. continue;
  186. } else {
  187. $ht_rooms = "-1";
  188. break;
  189. }
  190. }
  191. $days = $json_obj['days'];
  192. //预订天数
  193. $all_price = $json_obj['all_price'];
  194. //总价格
  195. $breakfast = $message_info[0]['breakfast'];
  196. //早餐
  197. for ($i = 0, $m = count($message_info); $i < $m; $i++) {
  198. $tm_breakfast = $message_info[$i]['breakfast'];
  199. if ($breakfast == $tm_breakfast) {
  200. continue;
  201. } else {
  202. $breakfast = "-1";
  203. break;
  204. }
  205. }
  206. $content = "";
  207. //判断order_status的值
  208. if ($order_status == "145") {//待支付
  209. $content = "{customer_name}预订的{check_in_date}{prod_name},{ht_rooms}间{days}晚,总价{order_price}({breakfast}),订单已生成,请尽快支付以免影响您的出行。";
  210. } else if ($order_status == "198") {//待确定
  211. $content = "已支付,待确认:{customer_name}预订的{check_in_date}{prod_name},{ht_rooms}间{days}晚,总价{order_price}({breakfast}),房间将在2小时内确认,请耐心等待确认信息。";
  212. } else if ($order_status == "199") {//待通知
  213. $content = "已确认:{customer_name}预订的{check_in_date}{prod_name},{ht_rooms}间{days}晚,总价{order_price}({breakfast}),已安排房间。";
  214. } else if ($order_status == "201") {//退改中
  215. $content = "{customer_name}预订的{check_in_date}{prod_name},{ht_rooms}间{days}晚,总价{order_price}({breakfast}),酒店方确认当日无房,正在安排退款,请耐心等待。联系客服:021-33280578。";
  216. } else if ($order_status == "238") {//已退单
  217. $content = "退款成功:{customer_name}预订的{check_in_date}{prod_name},{ht_rooms}间{days}晚,总价{order_price}({breakfast}),酒店方确认当日无房,已成功退款,请留意银行相关退款信息。联系客服:021-33280578。";
  218. } else if ($order_status == "148") {
  219. $content = "已取消:{customer_name}预订的{check_in_date}{prod_name},{ht_rooms}间{days}晚,总价{order_price}({breakfast}),已取消。联系客服:021-33280578。";
  220. } else {
  221. $content = "短信模板错误---严重错误:500当前状态".$order_status;
  222. writeLog($content);
  223. exit();
  224. }
  225. $content = str_replace("{customer_name}", $name, $content);
  226. $content = str_replace("{check_in_date}", $check_in_date, $content);
  227. $content = str_replace("{prod_name}", $prod_name, $content);
  228. //判断房间数是否该显示
  229. if ($ht_rooms != "-1") {
  230. $content = str_replace("{ht_rooms}", $ht_rooms, $content);
  231. } else {
  232. $content = str_replace("{ht_rooms}间", "", $content);
  233. }
  234. $content = str_replace("{days}", $days, $content);
  235. $content = str_replace("{order_price}", $all_price, $content);
  236. //判断早餐是否该显示
  237. if ($breakfast != "-1") {
  238. $content = str_replace("{breakfast}", $breakfast, $content);
  239. } else {
  240. $content = str_replace("({breakfast})", "", $content);
  241. }
  242. return array($name,$tel,$content);
  243. }
  244. exit;