简体   繁体   English

酒店预订系统的价格规则数据库设计

[英]Price rules database design for hotel reservation system

Right now I am developing Hotel reservation system. 现在我正在开发酒店预订系统。

so I need to store prices on certain date/date range for future days, so the price varies on different days/dates. 所以我需要在未来几天的某个日期/日期范围内存储价格,因此价格会因不同的日期/日期而异。 so I need to store those price & date details in to db. 所以我需要将这些价格和日期详细信息存储到db中。 i thought of 2 structures . 我想到了2个结构。

1st model : 第一款:

room_prices : room_id : from_date : to_date : price: is_available: 2nd design: room_prices : room_id : date: price: is_available room_prices : room_id : from_date : to_date : price: is_available: 2nd design: room_prices : room_id : date: price: is_available

so i found the 2nd method is easy. 所以我发现第二种方法很简单。 but data stored grows exponentially as my hotel list grows. 但随着酒店名单的增长,存储的数据呈指数级增长。

say suppose if i want to store next(future) 2 months price data for one hotel i need to create 60 records for every hotel. 假设如果我想存储一个酒店的下一个(未来)2个月价格数据,我需要为每个酒店创建60条记录。

in case of 1st design, i don't require that many records. 在第一次设计的情况下,我不需要那么多记录。

ex: 例如:

``` price values for X hotel : ```X酒店的价格值:

1-Dec-15 - 10-Dec-15 -- $200, 1月12日 - 15日 - 12月15日 - 200美元,

1st design requires : only 1 row 第一个设计要求:只有一排

2nd design requires : 10 rows ``` 第二个设计要求:10行```

i am using mysql, 我正在使用mysql,

does it have any performance degradation while searching room_prices table. 搜索room_prices表时是否有任何性能下降。

would someone suggest me any better design ? 有人会建议我更好的设计吗?

I have actually worked on designing and implementing a Hotel Reservation system and can offer the following advice based on my experience. 我实际上已经设计和实施了酒店预订系统,可以根据我的经验提供以下建议。

I would recommend your second design option, storing one record for each individual Date / Hotel combination. 我会推荐你​​的第二个设计选项,为每个日期/酒店组合存储一条记录。 The reason being that although there will be periods where a Hotel's Rate is the same across multiple days it is more likely that, depending on availability, it will change over time and become different (hotels tend to increase the room rate as the availability drops). 原因在于,尽管酒店的费率在多天内会有相同的时间段,但更可能的是,根据可用性,它会随着时间的推移而变化并变得不同(酒店往往随着可用性下降而增加房价) 。

Also there are other important pieces of information that will need to be stored that are specific to a given day: 此外,还需要存储特定于特定日期的其他重要信息:

  1. You will need to manage the hotel availability, ie on Date x there are y rooms available. 您需要管理酒店的可用性,即在日期xy房间可用。 This will almost certain vary by day. 这几乎肯定会在一天之内变化。
  2. Some hotels have blackout periods where the hotel is unavailable for short periods of time (typically specific days). 一些酒店有停电期间酒店短时间(通常是特定日期)不可用。
  3. Lead Time - some Hotels only allow rooms to be booked a certain number of days in advance, this can differ between Week days and Weekends. 交货时间 - 一些酒店只允许客房提前一定天数预订,这可能在工作日和周末之间有所不同。
  4. Minimum nights, again data stored by individual date that says if you arrive on this day you must stay x number of nights (say over a weekend) 最少的夜晚,再次按个人日期存储的数据,如果您在这一天到达,则必须保留x个晚上(比如周末)

Also consider a person booking a week long stay, the database query to return the rates and availability for each day of that stay is a lot more concise if you have a pricing record for each Date. 还要考虑一个人预订一周的住宿,如果您有每个日期的定价记录,那么返回该住宿每天的费率和可用性的数据库查询会更简洁。 You can simply do a query where the Room Rate Date is BETWEEN the Arrival and Departure Date to return a dataset with one record per date of the stay. 您可以简单地进行查询,其中房价日期在抵达和离开日期之间,以返回每个住宿日期有一条记录的数据集。

I realise with this approach you will store more records but with well indexed tables the performance will be fine and the management of the data will be much simpler. 我意识到使用这种方法你将存储更多的记录,但是使用索引良好的表格,性能将会很好,数据的管理将更加简单。 Judging by your comment you are only talking in the region of 18000 records which is a pretty small volume (the system I worked on has several million and works fine). 从你的评论来看,你只是在18000个记录的区域内谈论,这是一个非常小的数量(我工作的系统有几百万,工作正常)。

To illustrate the extra data management if you DON'T store one record per day, imagine that a Hotel has a rate of 100 USD and 20 rooms available for the whole of December: 如果您每天存储一条记录,为了说明额外的数据管理,想象一下酒店在整个12月份的房价为100美元和20间客房:

You will start with one record: 您将从一条记录开始:

1-Dec to 31st Dec Rate 100 Availability 20

Then you sell one room on the 10th Dec. 然后你在12月10日出售一个房间。

Your business logic now has to create three records from the one above: 您的业​​务逻辑现在必须创建上述三个记录:

1-Dec to 9th Dec Rate 100 Availability 20 10-Dec to 10th Dec Rate 100 Availability 19 11-Dec to 31st Dec Rate 100 Availability 20

Then the rate changes on the 3rd and 25th Dec to 110 然后费率在12月3日和25日变为110

Your business logic now has to split the data again: 您的业​​务逻辑现在必须再次拆分数据:

1-Dec to 2-Dec Rate 100 Availability 20 3-Dec to 3-Dec Rate 110 Availability 20 4-Dec to 9-Dec Rate 100 Availability 20 10-Dec to 10-Dec Rate 100 Availability 19 11-Dec to 24-Dec Rate 100 Availability 20 25-Dec to 25-Dec Rate 110 Availability 20 26-Dec to 31-Dec Rate 100 Availability 20

That is more business logic and more overhead than storing one record per date. 与每个日期存储一条记录相比,这是更多的业务逻辑和更多的开销。

I can guarantee you that by the time you have finished your system will end up with one row per date anyway so you might as well design it that way from the beginning and get the benefits of easier data management and quicker database queries. 我可以向您保证,当您完成系统时,每个日期最终会有一行,所以您不妨从头开始设计它,并获得更简单的数据管理和更快的数据库查询的好处。

I think that the first solution is better and as you already noticed it reduce the number of storage you need to store prices. 我认为第一种解决方案更好,因为您已经注意到它减少了存储价格所需的存储空间。 Another possible approach could be : having a single date and assuming that the date specified is valid up until a new date is found, so basically the same structure you designed in the second approach but implementing an internal logic in which you override a date if you find a new date for a specified period. 另一种可能的方法可能是:拥有一个日期,并假设指定的日期有效,直到找到新的日期,所以基本上与您在第二种方法中设计的结构相同,但实现了一个内部逻辑,如果您在其中覆盖日期查找指定期间的新日期。

Let's say that you have ROOM 1 with price $200 from 1st December and with price $250 from 12 December, then you will have only two rows : 假设从12月1日开始,房间价格为200美元,12月12日价格为250美元,那么您只有两排:

1-Dec-15  -- $200
12-Dec-15  -- $250

And you will assume in your logic that a price is valid from the specified date up until a new price is found. 并且您将在您的逻辑中假设价格从指定日期起有效,直到找到新价格。

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

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