每当客户取消预订时,我都会尝试向客户退款。由于我根据取消时间有不同的退款百分比,考虑到有人取消预订的时间。
目前主要有两种数据数组:
1) TimeMeta :这是一个保留时隙的数组。
$time_meta = array([
[
'id' => '9',
'start_date' => '2019-06-19',
'end_date' => '2019-06-19',
'start_time' => '08:00:00',
'end_time' => '09:00:00'
],
[
'id' => '10',
'start_date' => '2019-06-20',
'end_date' => '2019-06-20',
'start_time' => '08:00:00',
'end_time' => '09:00:00'
],
[
'id' => '11',
'start_date' => '2019-06-21',
'end_date' => '2019-06-20',
'start_time' => '08:00:00',
'end_time' => '09:00:00'
],
[
'id' => '12',
'start_date' => '2019-06-22',
'end_date' => '2019-06-20',
'start_time' => '08:00:00',
'end_time' => '09:00:00'
],
[
'id' => '13',
'start_date' => '2019-06-23',
'end_date' => '2019-06-23',
'start_time' => '08:00:00',
'end_time' => '09:00:00'
]
])
2) 按小时返还价值
$refunds = array([
[
'before_hours' => '12',
'refund_percent' => '50'
],
[
'before_hours' => '24',
'refund_percent' => '70'
],
[
'before_hours' => '48',
'refund_percent' => '90'
]
])
到目前为止,我可以计算当前日期时间和保留日期时间之间的差异,如下所示
foreach($time_meta as $ik => $iv){
$start_datetime = $iv->start_date->format('Y-m-d').' '.$iv->start_time;
$start_datetime = \Carbon\Carbon::parse($start_datetime);
$diff = $now->diffInHours($start_datetime,false);
// NEED CODE HERE TO DETERMINE THE EXACT REFUND PERCENT
// ACCORDING TO TIME DIFFERENCE BETWEEN NOW AND THE BOOKED DATE
}
现在,我想找到最匹配的退款百分比。因此,例如,如果用户尝试在 23 小时之前取消预订活动,退款百分比应该仅为 50%,因为 12 小时刚好小于refund数组的23 小时。
此外,如果活动日期已经过去,在这种情况下,$diff价值将为负数,这意味着过去的日期不应退款。
繁星点点滴滴