作者 董瑞恩
1 个管道 的构建 通过 耗费 1 秒

interface

@@ -73,7 +73,7 @@ class OrderController extends HomeBaseController{ @@ -73,7 +73,7 @@ class OrderController extends HomeBaseController{
73 public function order($users_id,$name){ 73 public function order($users_id,$name){
74 $order= Db::name('order')->where(['users_id'=>$users_id,'state'=>1])->find(); 74 $order= Db::name('order')->where(['users_id'=>$users_id,'state'=>1])->find();
75 $end_time=time(); 75 $end_time=time();
76 - $price=$this->getPrice($order['start_time'],$end_time); 76 + $price=$this->getPrice($users_id,$order['start_time'],$end_time);
77 $time=ceil(($end_time-$order['start_time'])/3600); 77 $time=ceil(($end_time-$order['start_time'])/3600);
78 $data=[ 78 $data=[
79 'end_time'=>$end_time, 79 'end_time'=>$end_time,
@@ -113,14 +113,14 @@ class OrderController extends HomeBaseController{ @@ -113,14 +113,14 @@ class OrderController extends HomeBaseController{
113 } 113 }
114 114
115 115
116 - public function getPrice($start_time=1543298302,$end_time=1543303733){ 116 + public function getPrice($users_id,$start_time=1543298302,$end_time=1543303733){
117 $cost=Db::name('cost')->where('id',1)->find(); 117 $cost=Db::name('cost')->where('id',1)->find();
118 $interval = Db::name('interval')->where('id',1)->find(); 118 $interval = Db::name('interval')->where('id',1)->find();
  119 + $is_free=Db::name('users')->where('id',$users_id)->find()['is_free'];
119 $free=$cost['free']; 120 $free=$cost['free'];
120 //获取整天的价格 121 //获取整天的价格
121 $dayPrice=$this->getDayPrice(); 122 $dayPrice=$this->getDayPrice();
122 123
123 -  
124 //用了多少天 124 //用了多少天
125 $day=floor(($end_time-$start_time)/86400); 125 $day=floor(($end_time-$start_time)/86400);
126 $price=$day*$dayPrice; 126 $price=$day*$dayPrice;
@@ -152,16 +152,18 @@ class OrderController extends HomeBaseController{ @@ -152,16 +152,18 @@ class OrderController extends HomeBaseController{
152 if (($new_start_time > $endTime && $new_start_time < $stateTime) && ($new_end_time < $new_start_time && $new_end_time < $stateTime)){ 152 if (($new_start_time > $endTime && $new_start_time < $stateTime) && ($new_end_time < $new_start_time && $new_end_time < $stateTime)){
153 //存在首小时免费 153 //存在首小时免费
154 $price +=(ceil(($new_end_time-$new_start_time)/3600) * $cost['cost']); 154 $price +=(ceil(($new_end_time-$new_start_time)/3600) * $cost['cost']);
155 - if ($free==1){ 155 + if ($free==1 && $is_free==0){
156 $price-=$cost['cost']; 156 $price-=$cost['cost'];
  157 + Db::name('users')->where('id',$users_id)->update(['is_free'=>1]);
157 } 158 }
158 } 159 }
159 //与预设时间段的头部重合 160 //与预设时间段的头部重合
160 if (($new_start_time > $endTime && $new_start_time < $stateTime) && ($new_end_time > $stateTime && $new_end_time < strtotime('24:00:00'))){ 161 if (($new_start_time > $endTime && $new_start_time < $stateTime) && ($new_end_time > $stateTime && $new_end_time < strtotime('24:00:00'))){
161 //存在首小时免费 162 //存在首小时免费
162 $price += (ceil(($stateTime-$new_start_time)/3600) * $cost['cost'] + ceil(($new_end_time-$stateTime)/3600) * $interval['price']); 163 $price += (ceil(($stateTime-$new_start_time)/3600) * $cost['cost'] + ceil(($new_end_time-$stateTime)/3600) * $interval['price']);
163 - if ($free==1){ 164 + if ($free==1 && $is_free==0){
164 $price-=$cost['cost']; 165 $price-=$cost['cost'];
  166 + Db::name('users')->where('id',$users_id)->update(['is_free'=>1]);
165 } 167 }
166 } 168 }
167 //在预设时间段右边并不与之重合 169 //在预设时间段右边并不与之重合
@@ -184,8 +186,9 @@ class OrderController extends HomeBaseController{ @@ -184,8 +186,9 @@ class OrderController extends HomeBaseController{
184 //存在首小时免费 186 //存在首小时免费
185 $price+= ceil(($YesterdayStateTime-$new_start_time)/3600) * $cost['cost'] 187 $price+= ceil(($YesterdayStateTime-$new_start_time)/3600) * $cost['cost']
186 +ceil(($new_end_time-$YesterdayStateTime)/3600) * $interval['price']; 188 +ceil(($new_end_time-$YesterdayStateTime)/3600) * $interval['price'];
187 - if ($free==1){ 189 + if ($free==1 && $is_free==0){
188 $price-=$cost['cost']; 190 $price-=$cost['cost'];
  191 + Db::name('users')->where('id',$users_id)->update(['is_free'=>1]);
189 } 192 }
190 } 193 }
191 //昨天预设开始前使用,今天预设结束后停止 194 //昨天预设开始前使用,今天预设结束后停止
@@ -194,8 +197,9 @@ class OrderController extends HomeBaseController{ @@ -194,8 +197,9 @@ class OrderController extends HomeBaseController{
194 $price+= ceil(($YesterdayStateTime-$new_start_time)/3600) * $cost['cost'] 197 $price+= ceil(($YesterdayStateTime-$new_start_time)/3600) * $cost['cost']
195 +ceil(($endTime-$YesterdayStateTime)/3600) * $interval['price'] 198 +ceil(($endTime-$YesterdayStateTime)/3600) * $interval['price']
196 +ceil(($new_end_time-$endTime)/3600) * $cost['cost']; 199 +ceil(($new_end_time-$endTime)/3600) * $cost['cost'];
197 - if ($free==1){ 200 + if ($free==1 && $is_free==0){
198 $price-=$cost['cost']; 201 $price-=$cost['cost'];
  202 + Db::name('users')->where('id',$users_id)->update(['is_free'=>1]);
199 } 203 }
200 } 204 }
201 //昨天预设开始后使用,今天预设结束前停止 205 //昨天预设开始后使用,今天预设结束前停止