我正在使用CodeIgniter框架。我想在特定的日期獲得所有可用的房間。算法如下:
1)我將給出一個日期來檢查房間的可用性。
2)系統應看到表「hotelbrancheshasreservations」和基於分支的ID和status = 'active'.
3應選擇預約IDS)然後,所有的活性保留被選擇和被接合與保留表。
4)只有那些保留是從提取的「保留」表中提取後的表,它們不在提供的日期保留並且是活動的。這張表中會有數千個保留,但應該跳過。
5)然後積極保留加入「保留房間」表,這將提供房間號。雖然目前保留,但可以爲與當前保留日期沒有衝突的其他日期保留。 6)最後,當前預訂的房間也加入了「酒店房間」表和所有可用的房間返回新的預訂。
7)所以一個房間可以預訂多次,但日期不同。
我無法在CodeIgniter中開發適當的查詢來獲取所有可用房間,如果我提供一些日期,如$startdate = 2016-05-16
和$enddate = 2016-05-27
。
的數據類型在MySQL的 Db的是date
。
我運行下面的查詢中笨
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->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 . '")');
$this->$db->join('hotelbrancheshasreservations', 'hotelbrancheshasreservations.reservations_reservationsid = reservation.reservationid');
$this->$db->where('(hotelbrancheshasreservations.status = '."'".$status."')");
$this->$db->where('(hotelbrancheshasreservations.hotelbranches_hotelbranchesid ='."'".$branchid."')");
$result = $this->$db->get()->result_array();
$this->$db->trans_complete();
return $result;
}
如果我提供startdate 2016-05-24
和enddate 2016-05-26
,然後它會選擇保留其如下:
[{"reservationid":"KHAN2016Q224","startdate":"2016-05-23","enddate":"2016-05-27","status":"pending"}]
此預訂應跳過因爲它在表「hotelbrancheshasreservations」
它選擇那些保留這是在提供的日期內,但不活躍。我想選擇那些在提供日期有效並可用的預訂。