gpt4 book ai didi

php - 如何根据日期时间搜索计算特殊日期和正常日期的总金额

转载 作者:可可西里 更新时间:2023-11-01 08:58:06 24 4
gpt4 key购买 nike

我有一个预订系统,其中 2019-02-15 8:30:00 至 2019-02-16 8:30:00 的特价为 400 美元。房间的正常价格是 360 美元。加类费为 30 美元。那么如果有人在2019-02-14 08:30:00到2019-02-17 11:30:00之间预订,我该如何计算金额。请帮助mysql php。

table #room

+----+--------+------+-----------+
| ID | room | rate | hrly_rate |
+----+--------+------+-----------+
| 1 | room 1 | 360 | 30 |
+----+--------+------+-----------+

表#special_calendar

+----+--------+------+--------------------+--------------------+
| ID | room | rate | start_date | end_date |
+----+--------+------+--------------------+--------------------+
| 1 | room 1 | 400 | 2019-02-15 8:30:00 | 2019-02-16 8:30:00 |
+----+--------+------+--------------------+--------------------+

预期输出:-

Iteration 1: 2019-02-14 08:30:00 - 2019-02-15 08:30:00  Amount $360
Iteration 2: 2019-02-15 08:30:00 - 2019-02-16 08:30:00 Amount $400
Iteration 3: 2019-02-16 08:30:00 - 2019-02-17 08:30:00 Amount $360
Iteration 4: 2019-02-17 08:30:00 - 2019-02-17 11:30:00 Amount $90 (3 X hourly rate)
Total Amount: 1210

对于预订,我从文本框中获取输入。

Check in: 2019-02-14 08:30:00
Checkout: 2019-02-17 11:30:00

低于我的代码,但出现 500 错误

    $amt=0;
$chekin_date=date("Y-m-d H:i:s", strtotime($_GET['chekin_date']));
$checkout_date=date("Y-m-d H:i:s", strtotime($_GET['checkout_date']));
$query_result=$this->general->execute_query2("SELECT * from special_calendar where category_id='$row->id' and '$chekin_date'<=start_date && end_date<='$checkout_date'");
if(!empty($query_result)){
while($chekin_date<$checkout_date)
{
foreach($query_result as $result)
{
if($result->start_date<=$chekin_date && $checkout_date<$result->end_date)
{
$amt = $amt+$result->rate;
}
else
{
//normal rate
$amt = $amt+$row->rate_day;
}
}
// increase check in date by 1
$datetime = new DateTime($chekin_date);
$datetime->modify('+1 day');
$chekin_date = $datetime->format('Y-m-d H:i:s');
}
}
else
{
$hrdif= $this->general->dateDifference($chekin_date , $checkout_date , $differenceFormat = '%h' );
$daydif= $this->general->dateDifference($chekin_date , $checkout_date , $differenceFormat = '%a' );
$amt=$amt+($daydif*$row->rate_day);
if($hrdif!=0){
$amt=$amt+($hrdif*$row->hrly_rate);
}
}
echo $amt;

最佳答案

首先,如果有条目,您必须在特殊日历表上搜索,然后获取费率。如果不是则在查询中取和

    //below code Logically presented. proceed with your content
$amt=0;
$query = check_in<=special_check_in && special_check_out<=check_out
$query_result = store result;
if($query_count>0)
{
while($check_in<$check_out)
{
foreach($query_result as $result)
{
if($result[special_check_in]<=$check_in && $check_in<$result[special_check_out])
{
$amt = $amt+$result['special_rate'];
}
else
{
//add room table rate fetch by using query
$amt = $amt+$room_table_rate
}
}
check_in = check_in+1 // increase check in date by 1
}
}
else
{
$query = "select SUM(rate) FROM room_table where room_id=your_room_id";
$amt = $query_result_sum;
}

echo $amt; //this is your final booking rate

关于php - 如何根据日期时间搜索计算特殊日期和正常日期的总金额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54687439/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com