|
@@ -107,36 +107,55 @@ class OrderController extends HomeBaseController{ |
|
@@ -107,36 +107,55 @@ class OrderController extends HomeBaseController{ |
107
|
$interval = Db::name('interval')->where('id',1)->find();
|
107
|
$interval = Db::name('interval')->where('id',1)->find();
|
108
|
|
108
|
|
109
|
//用了多少天
|
109
|
//用了多少天
|
110
|
- $date=floor(($end_time-$start_time)/86400);
|
|
|
111
|
- //去余数
|
|
|
112
|
- $yu=($end_time-$start_time)%86400;
|
|
|
113
|
-
|
|
|
114
|
- $new_start_time=$end_time-$yu;//时间戳
|
110
|
+ $day=floor(($end_time-$start_time)/86400);
|
|
|
111
|
+ $price=$day*1;
|
|
|
112
|
+ //去掉整天的金额
|
|
|
113
|
+ $new_start_time=$start_time+$day*86400;//时间戳
|
115
|
$new_end_time= $end_time;//时间戳
|
114
|
$new_end_time= $end_time;//时间戳
|
116
|
$hours_start_time=date('His',$new_start_time);
|
115
|
$hours_start_time=date('His',$new_start_time);
|
117
|
$hours_end_time=date('His',$new_end_time);
|
116
|
$hours_end_time=date('His',$new_end_time);
|
118
|
|
117
|
|
119
|
$stateTime=strtotime($interval['start_time']);
|
118
|
$stateTime=strtotime($interval['start_time']);
|
120
|
$endTime=strtotime($interval['end_time']);
|
119
|
$endTime=strtotime($interval['end_time']);
|
121
|
- $price=1;
|
|
|
122
|
- //判断是否跨天
|
120
|
+ //判断预设时间段是否跨天
|
123
|
if ($endTime < $stateTime){
|
121
|
if ($endTime < $stateTime){
|
|
|
122
|
+ //设备使用时间段是否跨天(不跨天)
|
124
|
if ($hours_end_time > $hours_start_time){
|
123
|
if ($hours_end_time > $hours_start_time){
|
125
|
- if ($new_start_time> strtotime('00:00:00') && $new_start_time < $endTime && $new_end_time > $endTime && $new_end_time < $stateTime){
|
|
|
126
|
- $price=ceil(($endTime-$new_start_time)/3600) * $interval['price'] + ceil(($new_end_time-$endTime)/3600) * $cost['cost'];
|
124
|
+ //在预设时间段左边并不与之重合
|
|
|
125
|
+ if (($new_start_time > strtotime('00:00:00') && $new_start_time < $endTime) && ($new_end_time > $new_start_time && $new_end_time < $endTime)){
|
|
|
126
|
+ $price +=(ceil(($new_end_time-$new_start_time)/3600) * $interval['price']);
|
127
|
}
|
127
|
}
|
128
|
- if ($new_start_time> strtotime('00:00:00') && $new_start_time < $endTime && $new_end_time > $stateTime){
|
|
|
129
|
- $price=ceil(($endTime-$new_start_time)/3600) * $interval['price'] + ceil(($new_end_time-$stateTime)/3600) * $interval['price'] + ceil(($stateTime-$endTime)/3600) * $cost['cost'];
|
128
|
+ //与预设时间段的尾部重合
|
|
|
129
|
+ if (($new_start_time > strtotime('00:00:00') && $new_start_time < $endTime) && ($new_end_time > $endTime && $new_end_time < $stateTime)){
|
|
|
130
|
+ $price +=(ceil(($endTime-$new_start_time)/3600) * $interval['price'] + ceil(($new_end_time-$endTime)/3600) * $cost['cost']);
|
130
|
}
|
131
|
}
|
131
|
-
|
|
|
132
|
- if ($new_start_time > $endTime && $new_end_time < $stateTime){
|
|
|
133
|
- $price=ceil(($new_end_time-$new_start_time)/3600) * $cost['cost'];
|
132
|
+ //与预设时间段的头尾都重合
|
|
|
133
|
+ if (($new_start_time > strtotime('00:00:00') && $new_start_time < $endTime) && $new_end_time > $stateTime){
|
|
|
134
|
+ $price +=(ceil(($endTime-$new_start_time)/3600) * $interval['price'] + ceil(($new_end_time-$stateTime)/3600) * $interval['price'] + ceil(($stateTime-$endTime)/3600) * $cost['cost']);
|
|
|
135
|
+ }
|
|
|
136
|
+ //不与预设时间段重合
|
|
|
137
|
+ if (($new_start_time > $endTime && $new_start_time < $stateTime) && ($new_end_time < $new_start_time && $new_end_time < $stateTime)){
|
|
|
138
|
+ //存在首小时免费
|
|
|
139
|
+ $price +=(ceil(($new_end_time-$new_start_time)/3600) * $cost['cost']);
|
134
|
}
|
140
|
}
|
135
|
- if ($new_start_time > $endTime && $new_end_time > $stateTime && $new_end_time < strtotime('24:00:00')){
|
|
|
136
|
- $price= ceil(($stateTime-$new_start_time)/3600) * $cost['cost'] + ceil(($new_end_time-$stateTime)/3600) * $interval['price'];
|
141
|
+ //与预设时间段的头部重合
|
|
|
142
|
+ if (($new_start_time > $endTime && $new_start_time < $stateTime) && ($new_end_time > $stateTime && $new_end_time < strtotime('24:00:00'))){
|
|
|
143
|
+ //存在首小时免费
|
|
|
144
|
+ $price += (ceil(($stateTime-$new_start_time)/3600) * $cost['cost'] + ceil(($new_end_time-$stateTime)/3600) * $interval['price']);
|
|
|
145
|
+ }
|
|
|
146
|
+ //在预设时间段右边并不与之重合
|
|
|
147
|
+ 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'))){
|
|
|
148
|
+ $price +=(ceil(($new_end_time-$new_start_time)/3600) * $interval['price']);
|
137
|
}
|
149
|
}
|
138
|
|
150
|
|
|
|
151
|
+ //设备使用时间段是否跨天(跨天:开始时间在昨天,结束时间在今天)
|
139
|
}else{
|
152
|
}else{
|
|
|
153
|
+ $YesterdayStateTime=$stateTime-86400;
|
|
|
154
|
+ $YesterdayEndTime=$endTime-86400;
|
|
|
155
|
+ //开始时间在预设开始时间的前面OR结束时间在预设结束时间的前面
|
|
|
156
|
+ if(($new_start_time > (strtotime('00:00:00')-86400) && $new_start_time < $YesterdayEndTime) && ($new_end_time > strtotime('00:00:00') && $new_end_time < $endTime)){
|
|
|
157
|
+ $price+= ceil(($YesterdayEndTime-$new_start_time)/3600) * $interval['price'];
|
|
|
158
|
+ }
|
140
|
|
159
|
|
141
|
}
|
160
|
}
|
142
|
}else{
|
161
|
}else{
|