...
|
...
|
@@ -73,7 +73,7 @@ class OrderController extends HomeBaseController{ |
|
|
public function order($users_id,$name){
|
|
|
$order= Db::name('order')->where(['users_id'=>$users_id,'state'=>1])->find();
|
|
|
$end_time=time();
|
|
|
$price=$this->getPrice($order['start_time'],$end_time);
|
|
|
$price=$this->getPrice($users_id,$order['start_time'],$end_time);
|
|
|
$time=ceil(($end_time-$order['start_time'])/3600);
|
|
|
$data=[
|
|
|
'end_time'=>$end_time,
|
...
|
...
|
@@ -113,14 +113,14 @@ class OrderController extends HomeBaseController{ |
|
|
}
|
|
|
|
|
|
|
|
|
public function getPrice($start_time=1543298302,$end_time=1543303733){
|
|
|
public function getPrice($users_id,$start_time=1543298302,$end_time=1543303733){
|
|
|
$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);
|
|
|
$price=$day*$dayPrice;
|
...
|
...
|
@@ -152,16 +152,18 @@ class OrderController extends HomeBaseController{ |
|
|
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){
|
|
|
if ($free==1 && $is_free==0){
|
|
|
$price-=$cost['cost'];
|
|
|
Db::name('users')->where('id',$users_id)->update(['is_free'=>1]);
|
|
|
}
|
|
|
}
|
|
|
//与预设时间段的头部重合
|
|
|
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){
|
|
|
if ($free==1 && $is_free==0){
|
|
|
$price-=$cost['cost'];
|
|
|
Db::name('users')->where('id',$users_id)->update(['is_free'=>1]);
|
|
|
}
|
|
|
}
|
|
|
//在预设时间段右边并不与之重合
|
...
|
...
|
@@ -184,8 +186,9 @@ class OrderController extends HomeBaseController{ |
|
|
//存在首小时免费
|
|
|
$price+= ceil(($YesterdayStateTime-$new_start_time)/3600) * $cost['cost']
|
|
|
+ceil(($new_end_time-$YesterdayStateTime)/3600) * $interval['price'];
|
|
|
if ($free==1){
|
|
|
if ($free==1 && $is_free==0){
|
|
|
$price-=$cost['cost'];
|
|
|
Db::name('users')->where('id',$users_id)->update(['is_free'=>1]);
|
|
|
}
|
|
|
}
|
|
|
//昨天预设开始前使用,今天预设结束后停止
|
...
|
...
|
@@ -194,8 +197,9 @@ class OrderController extends HomeBaseController{ |
|
|
$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){
|
|
|
if ($free==1 && $is_free==0){
|
|
|
$price-=$cost['cost'];
|
|
|
Db::name('users')->where('id',$users_id)->update(['is_free'=>1]);
|
|
|
}
|
|
|
}
|
|
|
//昨天预设开始后使用,今天预设结束前停止
|
...
|
...
|
|