简体   繁体   English

在线酒店预订系统,同步预订?

[英]Online Hotel Booking System, Simultaneous Booking?

I'm asked to create an online booking system with online payment and I'm wondering what to do in the case when 2 customers booked for the same room(s) at the same time. 我被要求创建一个在线支付的在线预订系统,我想知道在2个客户同时预订同一房间的情况下该怎么办。

For Example: 例如:
At the same time: 与此同时:

Customer1 and Customer2 booked for a standard room which only has 1 room available. 客户1和客户2预订了标准间,只有1间客房。 (The Room availability will display that there is still 1 room available). (房间可用性将显示仍有1个房间可用)。 And then they hit the 'confirm' button at the same time. 然后他们同时点击“确认”按钮。

Use a locking construct (probably on the database level in this case) to ensure that only one confirmation will go through at once. 使用锁定构造(在这种情况下可能在数据库级别),以确保一次只能进行一次确认。 You should always do this if it's possible to have a race condition like this. 如果可能出现这样的竞争条件,你应该总是这样做。 That way you will always know who was first, and you can tell the other user that they were too slow to confirm. 通过这种方式,您将始终知道谁是第一个,并且您可以告诉其他用户他们太慢而无法确认。

Another thing you might want to add is a payment time limit. 您可能想要添加的另一件事是付款时间限制。 In many systems, when you confirm something, you will have a certain amount of time to make a payment to get the reservation. 在许多系统中,当您确认某些内容时,您将有一定的时间来支付预订费用。 If you don't pay within that time, the confirmation will expire and the room will once again be available. 如果您未在该时间内付款,确认将过期,房间将再次可用。

There's a couple of ways to combat this. 有几种方法可以解决这个问题。

  1. If I user selects a room, temporarily remove it as available from your web front-end. 如果我的用户选择了一个房间,请暂时将其从网络前端删除。 Then any subsequent visitors will not be able to select that room for booking. 然后任何后来的访客将无法选择该房间进行预订。 If the first user doesn't complete the transaction, then the room becomes available again. 如果第一个用户未完成交易,则房间再次可用。
  2. Put a lock on the database as mentioned above so only one record can be written at any time 如上所述锁定数据库,因此任何时候都只能写入一条记录

Use a "provisional" system that marks the booking as provisional for, say 10 minutes. 使用“临时”系统将预订标记为临时,例如10分钟。 These slots then become unavailable to subsequent requests. 然后,这些插槽将无法用于后续请求。 If the booking is not completed within the time frame the slot is released again. 如果预订未在时间范围内完成,则该插槽将再次释放。 If you grab all the customer detail before they book the slot then the drop-out rate should stay low. 如果您在预订插槽之前获取所有客户详细信息,则辍学率应保持较低。

You must communicate the time-frame and it's "provisional status" to the booker. 您必须将时间框架和“临时状态”告知预订者。 If you have subsequent stages where the visitor could stop then a simple JS timer counting down the time would help and also push the booker along the process. 如果你有后续阶段,访问者可以停止,那么一个简单的JS计时器倒计时将有所帮助,并推动预订者沿着这个过程。

Alternatively, allow double booking until such time as the final "pay" button is pressed when it becomes first comes first. 或者,允许双重预订,直到第一次出现时按下最后的“付费”按钮。 The second method would convert better, the first method is more "correct". 第二种方法转换得更好,第一种方法更“正确”。

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

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