...
|
...
|
@@ -245,6 +245,145 @@ class OrderController extends HomeBaseController{ |
|
|
return $numPrice;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 只是获取价格信息不会进行操作
|
|
|
* @param $users_id
|
|
|
* @param $start_time
|
|
|
* @param $end_time
|
|
|
* @return float|int|mixed
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
* @throws \think\exception\DbException
|
|
|
*/
|
|
|
|
|
|
public function onlyGetPrice($users_id,$start_time,$end_time){
|
|
|
$cost=Db::name('cost')->where('id',1)->find();
|
|
|
$interval = Db::name('interval')->where('id',1)->find();
|
|
|
$is_free=Db::name('users')->where('id',$users_id)->find()['is_free'];
|
|
|
//一小时免费状态
|
|
|
$free=$cost['free'];
|
|
|
|
|
|
//获取整天的价格
|
|
|
$dayPrice=$this->getDayPrice();
|
|
|
|
|
|
//用了多少天
|
|
|
$day=floor(($end_time-$start_time)/86400);
|
|
|
$dayPrice=$day*$dayPrice;
|
|
|
//去掉整天的金额
|
|
|
$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=0;
|
|
|
if ($endTime < $stateTime){
|
|
|
//设备使用时间段是否跨天(不跨天)
|
|
|
if ($hours_end_time > $hours_start_time){
|
|
|
// dump(date('Y-m-d H:i:s',$new_start_time));
|
|
|
// dump(date('Y-m-d H:i:s',$new_end_time));
|
|
|
// dump(date('Y-m-d H:i:s',$stateTime));
|
|
|
// dump(date('Y-m-d H:i:s',$endTime));
|
|
|
//在预设时间段左边并不与之重合
|
|
|
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 > $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 > $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 ($free==1 && $is_free==0){
|
|
|
$price-=$cost['cost'];
|
|
|
Log::init([
|
|
|
'type' => 'File',
|
|
|
'path' => APP_PATH.'logs/'
|
|
|
]);
|
|
|
Log::write($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 ($free==1 && $is_free==0){
|
|
|
$price-=$cost['cost'];
|
|
|
|
|
|
}
|
|
|
}
|
|
|
//在预设时间段右边并不与之重合
|
|
|
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;
|
|
|
//昨天预设结束前使用,今天预设结束前停止
|
|
|
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']
|
|
|
+ceil(($YesterdayStateTime-$YesterdayEndTime)/3600) * $cost['cost']
|
|
|
+ceil(($new_end_time-$YesterdayStateTime)/3600) * $interval['price'];
|
|
|
}
|
|
|
//昨天预设开始前使用,今天预设结束前停止
|
|
|
if(($new_start_time > $YesterdayEndTime && $new_start_time < $YesterdayStateTime) && ($new_end_time > strtotime('00:00:00') && $new_end_time < $endTime)){
|
|
|
//存在首小时免费
|
|
|
|
|
|
$price+= ceil(($YesterdayStateTime-$new_start_time)/3600) * $cost['cost']
|
|
|
+ceil(($new_end_time-$YesterdayStateTime)/3600) * $interval['price'];
|
|
|
if ($free==1 && $is_free==0){
|
|
|
$price-=$cost['cost'];
|
|
|
}
|
|
|
}
|
|
|
//昨天预设开始前使用,今天预设结束后停止
|
|
|
if(($new_start_time > $YesterdayEndTime && $new_start_time < $YesterdayStateTime) && ($new_end_time > $endTime && $new_end_time < $stateTime)){
|
|
|
//存在首小时免费
|
|
|
|
|
|
$price+= ceil(($YesterdayStateTime-$new_start_time)/3600) * $cost['cost']
|
|
|
+ceil(($endTime-$YesterdayStateTime)/3600) * $interval['price']
|
|
|
+ceil(($new_end_time-$endTime)/3600) * $cost['cost'];
|
|
|
if ($free==1 && $is_free==0){
|
|
|
$price-=$cost['cost'];
|
|
|
}
|
|
|
}
|
|
|
//昨天预设开始后使用,今天预设结束前停止
|
|
|
if(($new_start_time > $YesterdayStateTime && $new_start_time < strtotime('00:00:00')) && ($new_end_time > strtotime('00:00:00') && $new_end_time < $endTime)){
|
|
|
|
|
|
$price+= ceil(($new_end_time-$new_start_time)/3600) * $interval['price'];
|
|
|
}
|
|
|
//昨天预设开始后使用,今天预设结束后停止
|
|
|
if(($new_start_time > $YesterdayStateTime && $new_start_time < strtotime('00:00:00')) && ($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 > $YesterdayStateTime && $new_start_time < strtotime('00:00:00')) && ($new_end_time > $stateTime && $new_end_time < ($new_start_time+86400))){
|
|
|
|
|
|
$price+= ceil(($endTime-$new_start_time)/3600) * $interval['price']
|
|
|
+ceil(($stateTime-$endTime)/3600) * $cost['cost']
|
|
|
+ceil(($new_end_time-$stateTime)/3600) * $interval['price'];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if ($price > $cost['ceiling']){
|
|
|
$price = $cost['ceiling'];
|
|
|
}
|
|
|
$numPrice = $dayPrice+$price;
|
|
|
log::write($numPrice);
|
|
|
return $numPrice;
|
|
|
}
|
|
|
|
|
|
//获取整天的价格
|
|
|
public function getDayPrice(){
|
|
|
$cost=Db::name('cost')->where('id',1)->find();
|
...
|
...
|
|