简体   繁体   English

预约系统查询逻辑错误

[英]Logical error in the query of the booking system

I got a glitch in my logic from the reservation system.我的预订系统的逻辑出现了故障。 I have a room I can rent.我有一个房间可以租。

My database has the following test entries for the reservation:我的数据库有以下预订测试条目: 在此处输入图像描述

Now someone wants to book the room from 15.06 - 17.06 but the 17.06 is already booked.现在有人想从 15.06 到 17.06 预订房间,但 17.06 已经预订了。

I thought of something like我想到了类似的东西

SELECT * FROM reservation WHERE resDate >= "2020-06-15" AND depDate <= "2020-06-17"

and my query with Doctrine looks like我对 Doctrine 的查询看起来像

        return $this->createQueryBuilder('s')
            ->where('s.resDate >= :startdate')
            ->andWhere('s.depDate <= :enddate')
            ->setParameter('startdate', $startdate)
            ->setParameter('enddate', $enddate)
            ->getQuery()
            ->getOneOrNullResult()
            ;

Somehow I can't find a corresponding logic where the query tells me that it hasn't found an entry and that the entered period is free.不知何故,我找不到相应的逻辑,查询告诉我它没有找到条目并且输入的时间段是免费的。 What am I doing wrong?我究竟做错了什么?

Your booking starts from 17th so it is still free to book from 15th to 17th.您的预订从 17 日开始,因此从 15 日到 17 日仍然可以免费预订。

Therefore your logic should be to just query the database with 1 day less that is 16th as checkout will be done on 17th.因此,您的逻辑应该是在 16 日的 1 天以内查询数据库,因为结帐将在 17 日完成。

Usually when booking happens for 15th to 17th it means the guest has paid for 15th, 16th and 17th and will be checking out on 18th morning.通常当预订发生在 15 日至 17 日时,这意味着客人已支付 15 日、16 日和 17 日的费用,并将在 18 日早上退房。 That is why you see 3 nights and 5 nights stay in hotel reservations.这就是为什么您会在酒店预订中看到 3 晚和 5 晚住宿。 But in your case as you are explaining it.但在你解释的情况下。 It seems like you are counting same day in 2 places.好像您在 2 个地方计算同一天。

Either way you have to change the way the customer is trying to book the room in first place otherwise the crude fix won't work well and it will create other confusions later on.无论哪种方式,您都必须首先改变客户尝试预订房间的方式,否则粗略的修复将无法正常工作,并且稍后会造成其他混乱。

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

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