酒店预订和客房供应情况

时间:2016-05-21 21:52:51

标签: php mysql codeigniter

Hotel Reservation System ER Diagram

我正在使用CodeIgniter Framework。我希望在特定日期获得所有可用的房间。算法如下:

1)我将给出一个日期来检查房间的可用性。

2)系统应查看表" hotelbrancheshasreservations" ,并根据分支ID和status = 'active'选择预订 ID

3)然后选择所有有效的预订并与预订表结合使用。

4)仅从" 预订"中提取预订。连接后的表,这些表在提供的日期未保留且处于活动状态。该表中将有数以千计的预订,但应该跳过。

5)然后将有效预订与" 保留室"桌子,这将提供房间数量。虽然目前已经预订,但可以保留用于与当前预订日期没有冲突的其他日期。

6)最后,目前预订的房间也加入了" 酒店房间"桌子和所有可用的房间返回新的预订。

7)所以房间可以预订多次,但日期不同。

如果我提供$startdate = 2016-05-16$enddate = 2016-05-27之类的日期,我无法在CodeIgniter中开发适当的查询来获取所有可用空间。

MySQL Db中的数据类型是日期。

function joinReserv($branchid, $startdate, $enddate, $db)
{
$status = "active";
$this->$db->trans_start();
$this->$db->select('reservationid, startdate, enddate, hotelbrancheshasreservations.status');
$this->$db->from('reservation');
$this->$db->join('hotelbrancheshasreservations', 'hotelbrancheshasreservations.reservations_reservationsid = reservation.reservationid');
$this->$db->where('(hotelbrancheshasreservations.status = '."'".$status."')");
$this->$db->where('(hotelbrancheshasreservations.hotelbranches_hotelbranchesid ='."'".$branchid."')");
$this->$db->where('(startdate BETWEEN "' . $startdate . '" AND "' . $enddate . '") OR (enddate BETWEEN "' . $startdate . '" AND "' . $enddate . '")');
$this->$db->where('( "'. $startdate . '" BETWEEN startdate AND enddate  ) OR ( "'. $enddate . '" BETWEEN startdate AND enddate)');
$result = $this->$db->get()->result_array();
$this->$db->trans_complete();       
return $result;
}

如果我提供startdate 2016-05-24enddate 2016-05-26,则会选择如下预订:

[{"reservationid":"KHAN2016Q224","startdate":"2016-05-23","enddate":"2016-05-27","status":"pending"}]

此预订应跳过,因为它在表格中没有激活" hotelbrancheshasreservations "

选择提供日期但未激活的预订。我想选择那些在提供日期有效且可用的预订。

0 个答案:

没有答案
相关问题