简体   繁体   English

PHP实时在线座位预订系统所需的逻辑流程?

[英]Logical flow required for a real time online seats booking system in PHP?

I am workinng on a development of online web application in PHP. 我正在用PHP开发在线Web应用程序。 The system is regarding seats booking system for a travel company. 该系统与旅游公司的座位预订系统有关。 I have a booking form containing a select box which have list of tour code. 我有一个包含选择框的预订表格,其中包含旅游代码列表。 Whenever a user selects the tour code an Ajax request fetches currently available number of seats for that tour code. 每当用户选择游览代码时,Ajax请求都会获取该游览代码的当前可用座位数。 After this the user selects the number of seats he requiers to book and fill details of that number of passengers in form and submits the form. 此后,用户选择需要预订的座位数,并在表格中填写该人数的详细信息,然后提交表格。

As this system is online a situation may arise as follow: 由于此系统在线,因此可能会出现以下情况:

User1 and user2 has logged in trying to book seats for tourA. 用户1和用户2已登录,试图为tourA预订座位。 For tourA only 10 Seats are available. 对于旅行团,仅提供1​​0个座位。 User1 want to book 7 seats and user2 wants to book 5 seats. 用户1要预订7个席位,用户2要预订5个席位。 Both hit the booking form link and both are getting the available seats number as 10. Both has started filling the form as form is little bit lengthy. 两者都点击了预订表格链接,并且都获得了10个可用的座位数。两者都开始填写表格,因为表格有点长。 Both takes some different time to fill the form and submit according to there typing speed.Both the users are thinking that they will get the required number of seats booked. 两者都需要花费一些不同的时间来填写表格并根据输入的速度进行提交。两个用户都认为他们将获得所需的预定座位数。 But both have submit the form with small time difference the one her consider userB submit first will get the booking and the other userA will get the an error message that the respective number of seats are not available. 但是,两者都以较小的时差提交了表格,她认为用户B首先提交的表格将获得预订,而另一个用户A将收到一条错误消息,指出相应的座位数不可用。 So here userA get confused that as the he got the message that the number seats are availebe now after submitting the form he gets the message require number of seats are not available. 因此,在这里,用户A感到困惑,因为在提交表单后,他得到了席位数量可用的消息,因此他得到消息,要求席位数量不可用。

How could I avoid the condition like above? 如何避免上述情况? I need the logical flow behind the real time booking system. 我需要实时预订系统背后的逻辑流程。 Anybody please explain me this and how to achive this in php. 任何人都请向我解释这个以及如何在php中实现。

I am thinking of as soon as the user selects the number of seats count; 我在想,一旦用户选择了席位数量; using ajax I will update the field in database table which maintains this available number of seats count and book that number of seats for that session. 使用ajax,我将更新数据库表中的字段,该表将维护此可用座位数并为该会话预订该座位数。 But here a codition may arise like if user selects the seats and start filling the form but due to any reason if he is not submits the booking form then the problem will arise because we have removed required number of seats from db but booking procedure is not completed by user. 但是在这里可能会出现这样的情况,例如,如果用户选择座位并开始填写表格,但是由于任何原因(如果他没有提交预订表格),则会出现问题,因为我们已经从数据库中删除了所需的座位数,但是预订程序却没有由用户完成。 So how to revert this back as well as we updated the table then the other users who want to book seats they my fond that the number of seats are not available and they will be gone and will not check it again. 因此,如何还原该位置以及我们更新了表格,然后其他想要预订座位的用户又对他们感到满意,因为他们感到座位数量不可用,他们将消失并且不会再次检查。 Due to this travel company's business may goes down. 由于这个旅行公司的业务可能会下降。

Please note that every user need to login to application for booking the seats. 请注意,每个用户都需要登录到预订座位的应用程序。

Friends you may found this question as home work but here I dont have any firm logical solution. 朋友,您可能会发现这个问题是家庭作业,但在这里我没有任何坚定的逻辑解决方案。 Please guide me in this and please explain me the logical flow of system to overcome above kind of situation. 请以此指导我,并请我解释克服上述情况的系统逻辑流程。 If anybody have a simple code example in PHP for this for reference the it will also helpful for me. 如果有人在PHP中有一个简单的代码示例作为参考,它对我也将有所帮助。

Expecting positive reply 期待正面答复

Thank You! 谢谢!

There really is not a perfect way to do this. 确实没有做到这一点的完美方法。 You basically have 3 options 您基本上有3个选择

  1. Reserve the resource as soon as the user indicates that they want to reserve it (this what nycballet.com does) 用户指示要保留资源后立即保留资源(这是nycballet.com的工作)
  2. Reserve the resource when the user commits to the purchase(this is what travelocity does). 当用户承诺购买时,保留资源(这就是travelocity所做的事情)。
  3. Let both users purchase the resource and have a facility for a human to rollback one of the transactions (aka overbooking) 让两个用户都购买资源并为人员提供回退其中一项交易(又称为超额预订)的便利

Which you pick ultimately is a business decision and one that depends on the shape of your funnel and how sensitive your users are to UX problems. 您最终选择的是一项业务决策,这取决于漏斗的形状以及用户对UX问题的敏感程度。

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

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