使用Django进行预订周期

huangapple go评论68阅读模式
英文:

Booking Cycle with Django

问题

我有一个应用程序,用户可以预订会话,然后使用支付服务提供商(如Fawry或Paymob,这些是中东地区的公司)进行付款。这是如何完成的:当用户预订一个会话或多个会话时,会生成一个代码,该代码在30分钟内可用。

我的问题是:

我应该将用户要支付的会话声明为已预订,这样当另一个用户获取会话时,它们将不可用于预订吗?如果是这样,如果用户决定不支付会话,我该如何知道?如果我能知道并将它们返回到未预订状态,那么如果其他想要这些会话的用户没有再次检查这些会话会发生什么?或者,我应该使它们在用户支付它们之前保持可用状态,然后从可用会话中移除它们,但如果两个用户预订了同一个会话——因为当一个用户预订它时它还没有被移除——那么他们要使用的生成的代码有一个要支付的金额,它不会检查用户要支付的会话是否不再可用。

我的建议是:

创建一个临时表,保存即将被预订的会话,并将它们从可用会话中移除。在生成的代码不再可用的特定时间后,会话状态可以更改回可用状态,但我不知道如何触发切换会话状态的操作。

英文:

I have an app where the user books a session and then pay it using payment service provider (like Fawry or Paymob which are middle-east based companies). the way this is done is when the user books a session or multiple sessions a code is generated and it will be available for say 30 mins.

My Question is :

should I declare the sessions that the user is going to pay for as booked so when another user fetches the sessions they will not be available to be booked? and if so what happens if the user decided not to pay for the sessions, how would I know? and if I can know and return them back to unbooked status what if the other user that wanted them didn't check for these sessions again? OR should I make them available until the user pay for them then remove them from the available sessions, but then what if two users booked the same session -as it's not yet been removed when one user booked it-, the generated code that they are going to use has an amount of money to be paid it will not check if the session that the user paying for not available anymore.

My Suggestion :

is to make a temp table that holds the about to be booked sessions and remove them from the available sessions and after a specific period of time when the generated code is no longer available the sessions status can change back to available, but I don't know how to trigger the action that toggles the session status.

答案1

得分: 1

预定与否的问题是您的业务逻辑的一部分,而不是编码决策 - 因此,您需要决定您希望为客户提供的用户体验。

可以以许多方式实现预订 - 其中一个简单的方式是将“reserved_until”日期时间字段以及相应对象中的“reserving_user”链接存储起来,然后与“datetime.now()”进行比较,以确定访问用户是否已更改。

英文:

The question to reserve or not is part of your business logic an not a coding decision - so you need to decide what you want for your customers user experience.

The implementation of a reservation could be done in many ways - one simple one could be to store a "reserved_until" datetime field as well as a link to the "reserving_user" in the respective object and compare it with "datetime.now()" if the accessing user has changed.

huangapple
  • 本文由 发表于 2023年7月13日 23:50:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76681271.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定