简体   繁体   English

酒店预订日历预订逻辑问题

[英]Hotel Booking Calendar Reservation logic issue

I am trying to setup a hotel booking system and have run into an issue. 我正在尝试设置酒店预订系统,但遇到了问题。 We are trying to find where the room would be available across multiple days and months. 我们正在尝试寻找在几天和几个月内都可以使用房间的地方。 Below are the four queries we are currently using however the admin can't book in advance until one room has NO events. 以下是我们当前正在使用的四个查询,但是直到一个房间没有任何事件,管理员才能提前预订。 Any help would be great. 任何帮助都会很棒。

$sql_statementxf1 = "Select * FROM Hotels 
  WHERE EXISTS (
    Select * FROM cal_events 
    WHERE start_date >= $end_dated 
    AND cal_events.HotelID = Hotels.HotelID 
    ORDER BY start_date) 
  AND HotelID>0 
  AND Class != 'HO' 
  ORDER BY HotelBlock, HotelNumber";
$sql_statementxf = "Select * FROM Hotels 
  WHERE EXISTS (
    Select * FROM cal_events 
    WHERE end_date >= $start_dated  
    AND cal_events.HotelID = Hotels.HotelID)  
  AND NOT EXISTS ( 
    select * from cal_events  
    WHERE start_date=$start_dated  
    AND cal_events.HotelID = Hotels.HotelID)  
  AND HotelID>0 
  AND Class != 'HO'
  ORDER BY HotelBlock, HotelNumber"; 
$sql_statementxf2 = "Select * FROM Hotels 
  WHERE NOT EXISTS ( 
    Select * FROM cal_events  
    WHERE cal_events.HotelID = Hotels.HotelID)  
  AND HotelID>0 
  AND Class != 'HO' 
  ORDER BY HotelBlock, HotelNumber";
$sql_statementxf3 = "Select * FROM Hotels 
  WHERE EXISTS ( 
    Select * FROM cal_events  
    WHERE start_date=$start_dated  
    AND end_date = $end_dated  
    AND CustomerID = $custid  
    AND PersonID != $personid  
    AND cal_events.HotelID = Hotels.HotelID)  
  AND HotelID>0 
  AND Class!='HO' 
  ORDER BY HotelBlock, HotelNumber";

There are a lot of mysteries in this code (like why the variable names don't seem to match up with how they are used), but one thing does stand out, $sql_statementxf2 is not like the other sections. 这段代码中有很多奥秘(例如为什么变量名似乎与它们的用法不匹配),但确实有一点与众不同,$ sql_statementxf2与其他部分不同。 Xf, XF1, and XF3 are all very careful about the dates. Xf,XF1和XF3都非常注意日期。 XF2 completely ignores dates, and excludes all hotels with any calendar events. XF2完全忽略了日期,并排除所有酒店任何日历事件。 That sounds like the problem behavior you are describing, since that's the only thing it does I'd say comment it and see if that gets you the results you are looking for. 这听起来像是您正在描述的问题行为,因为这是我唯一要说的内容,就是看看是否能为您提供所需的结果。

To go slightly off question, It seems like what you are trying to do is find rooms without a calendar entry for the range your provide. 稍微说一下,似乎您要尝试的是找到没有日历条目的房间,您提供的范围。 I'm not sure how you are combining the first three statements, but they could all be replaced by using a simple or statement: 我不确定您如何组合前三个语句,但是可以使用简单或语句将它们全部替换:

  select Hotels.* from Hotels
  where not exists 
  (
    select * from cal_events 
    where cal_events.HotelID = Hotels.HotelID
      and (cal_events.start_date between $start_Date and $End_Date
        or cal_events.end_date between $start_Date and $End_Date
        or (cal_events.start_date < $start_Date and cal_events.end_date > $End_date))
    )
      AND HotelID>0 
      AND Class != 'HO' 
  ORDER BY HotelBlock, HotelNumber

What that does is it excludes the three types of overlapping date ranges, don't show rooms where an event starts during the period, don't show rooms where events end during the period, and don't show rooms with events that start before and end after the period (a full overlap). 它的作用是排除三种重叠的日期范围,不显示该时间段内事件开始的房间,不显示该时间段内事件结束的房间,也不显示事件之前的房间并在句点之后结束(完全重叠)。 The last one looks like you are trying to avoid a customer double booking, so that section might stay. 最后一个看起来像您在尝试避免重复预订客户,因此该部分可能会保留。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM