...
|
...
|
@@ -107,36 +107,55 @@ class OrderController extends HomeBaseController{ |
|
|
$interval = Db::name('interval')->where('id',1)->find();
|
|
|
|
|
|
//用了多少天
|
|
|
$date=floor(($end_time-$start_time)/86400);
|
|
|
//去余数
|
|
|
$yu=($end_time-$start_time)%86400;
|
|
|
|
|
|
$new_start_time=$end_time-$yu;//时间戳
|
|
|
$day=floor(($end_time-$start_time)/86400);
|
|
|
$price=$day*1;
|
|
|
//去掉整天的金额
|
|
|
$new_start_time=$start_time+$day*86400;//时间戳
|
|
|
$new_end_time= $end_time;//时间戳
|
|
|
$hours_start_time=date('His',$new_start_time);
|
|
|
$hours_end_time=date('His',$new_end_time);
|
|
|
|
|
|
$stateTime=strtotime($interval['start_time']);
|
|
|
$endTime=strtotime($interval['end_time']);
|
|
|
$price=1;
|
|
|
//判断是否跨天
|
|
|
//判断预设时间段是否跨天
|
|
|
if ($endTime < $stateTime){
|
|
|
//设备使用时间段是否跨天(不跨天)
|
|
|
if ($hours_end_time > $hours_start_time){
|
|
|
if ($new_start_time> strtotime('00:00:00') && $new_start_time < $endTime && $new_end_time > $endTime && $new_end_time < $stateTime){
|
|
|
$price=ceil(($endTime-$new_start_time)/3600) * $interval['price'] + ceil(($new_end_time-$endTime)/3600) * $cost['cost'];
|
|
|
//在预设时间段左边并不与之重合
|
|
|
if (($new_start_time > strtotime('00:00:00') && $new_start_time < $endTime) && ($new_end_time > $new_start_time && $new_end_time < $endTime)){
|
|
|
$price +=(ceil(($new_end_time-$new_start_time)/3600) * $interval['price']);
|
|
|
}
|
|
|
if ($new_start_time> strtotime('00:00:00') && $new_start_time < $endTime && $new_end_time > $stateTime){
|
|
|
$price=ceil(($endTime-$new_start_time)/3600) * $interval['price'] + ceil(($new_end_time-$stateTime)/3600) * $interval['price'] + ceil(($stateTime-$endTime)/3600) * $cost['cost'];
|
|
|
//与预设时间段的尾部重合
|
|
|
if (($new_start_time > strtotime('00:00:00') && $new_start_time < $endTime) && ($new_end_time > $endTime && $new_end_time < $stateTime)){
|
|
|
$price +=(ceil(($endTime-$new_start_time)/3600) * $interval['price'] + ceil(($new_end_time-$endTime)/3600) * $cost['cost']);
|
|
|
}
|
|
|
|
|
|
if ($new_start_time > $endTime && $new_end_time < $stateTime){
|
|
|
$price=ceil(($new_end_time-$new_start_time)/3600) * $cost['cost'];
|
|
|
//与预设时间段的头尾都重合
|
|
|
if (($new_start_time > strtotime('00:00:00') && $new_start_time < $endTime) && $new_end_time > $stateTime){
|
|
|
$price +=(ceil(($endTime-$new_start_time)/3600) * $interval['price'] + ceil(($new_end_time-$stateTime)/3600) * $interval['price'] + ceil(($stateTime-$endTime)/3600) * $cost['cost']);
|
|
|
}
|
|
|
//不与预设时间段重合
|
|
|
if (($new_start_time > $endTime && $new_start_time < $stateTime) && ($new_end_time < $new_start_time && $new_end_time < $stateTime)){
|
|
|
//存在首小时免费
|
|
|
$price +=(ceil(($new_end_time-$new_start_time)/3600) * $cost['cost']);
|
|
|
}
|
|
|
if ($new_start_time > $endTime && $new_end_time > $stateTime && $new_end_time < strtotime('24:00:00')){
|
|
|
$price= ceil(($stateTime-$new_start_time)/3600) * $cost['cost'] + ceil(($new_end_time-$stateTime)/3600) * $interval['price'];
|
|
|
//与预设时间段的头部重合
|
|
|
if (($new_start_time > $endTime && $new_start_time < $stateTime) && ($new_end_time > $stateTime && $new_end_time < strtotime('24:00:00'))){
|
|
|
//存在首小时免费
|
|
|
$price += (ceil(($stateTime-$new_start_time)/3600) * $cost['cost'] + ceil(($new_end_time-$stateTime)/3600) * $interval['price']);
|
|
|
}
|
|
|
//在预设时间段右边并不与之重合
|
|
|
if (($new_start_time > $stateTime && $new_start_time < strtotime('24:00:00')) && ($new_end_time > $new_start_time && $new_end_time < strtotime('24:00:00'))){
|
|
|
$price +=(ceil(($new_end_time-$new_start_time)/3600) * $interval['price']);
|
|
|
}
|
|
|
|
|
|
//设备使用时间段是否跨天(跨天:开始时间在昨天,结束时间在今天)
|
|
|
}else{
|
|
|
$YesterdayStateTime=$stateTime-86400;
|
|
|
$YesterdayEndTime=$endTime-86400;
|
|
|
//开始时间在预设开始时间的前面OR结束时间在预设结束时间的前面
|
|
|
if(($new_start_time > (strtotime('00:00:00')-86400) && $new_start_time < $YesterdayEndTime) && ($new_end_time > strtotime('00:00:00') && $new_end_time < $endTime)){
|
|
|
$price+= ceil(($YesterdayEndTime-$new_start_time)/3600) * $interval['price'];
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}else{
|
...
|
...
|
|