简体   繁体   English

预订系统:根据访客数量查找房间组合 - PHP

[英]Booking system: Find room combinations based on guest count - PHP

I am preparing a booking system and solving a specific problem. 我正在准备预订系统并解决具体问题。 I have the following data structure (room number/occupancy/ price): 我有以下数据结构(房间号/占用/价格):

$room[222][1] = 80;

$room[223][1] = 100; //Room ID 222, occupancy 1 guest, price €100
$room[223][2] = 200; //Room ID 222, occupancy 2 guest, price €200
$room[223][3] = 300; //...

$room[224][1] = 110;
$room[224][2] = 220;
$room[224][3] = 330;
...

I need to find the best (lowest price) combination of rooms for a specified number of guests. 我需要为指定数量的客人找到最好的(最低价格)房间组合。

For example: For the 4 guests is the best combination of room $room[222][1] and room $room[223][3]. 例如: 4位客人是房间$ 222 [1]和房间$ room [223] [3]的最佳组合。 The total price of the rooms is €380. 房间的总价格是380欧元。

Can you help me? 你能帮助我吗?

First, I would make the rooms a more descriptive object so something like this: Second, I wouldn't store price per customer like that, rather focus on capacity and go from there 首先,我会把房间作为一个更具描述性的对象,所以这样:第二,我不会像这样存储每个客户的价格,而是关注容量并从那里开始

  $room = array();
  $room[222] = array(
    'capactiy' => '3',
    'price' => array(
      1 => '100', //Use a string, likely you'll have .99 or whatever
      2 => '200',
      3 => '300',
    ),
    'booked' => false,
  );

So you have 3 customers come in: Loop through available rooms, if the amount of people is less than capacity then cool, book it, else (say capacity is 2) then remove 2 from the amount of customers needing room, Then loop again and grab the next room 所以你有3个客户进来:循环通过可用房间,如果人数少于容量然后冷却,预订,否则(比如容量为2)然后从需要房间的客户数量中删除2,然后再循环抓住隔壁房间

If you want to get complex, say they want to be right next to each other, take room 222 + 1, is it available? 如果你想变得复杂,说他们想要彼此相邻,取222 + 1房间,它可用吗? if no then 223 + 1, is it available? 如果没有223 + 1,它可用吗? yes? 是? great! 大! book it. 预订吧。

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

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