作者 sgj

fix a bug of fee

@@ -410,7 +410,7 @@ class OrderController extends HomeBaseController{ @@ -410,7 +410,7 @@ class OrderController extends HomeBaseController{
410 * @title 计算价格 410 * @title 计算价格
411 * @description 微信统一下单 411 * @description 微信统一下单
412 * @author 董瑞恩 412 * @author 董瑞恩
413 - * @url /portal/order/getPrice 413 + * @url /portal/order/getPriceTest
414 * @method GET 414 * @method GET
415 * 415 *
416 * @param name:start_time type:String require:1 default:无 other: desc:起始时间 416 * @param name:start_time type:String require:1 default:无 other: desc:起始时间
@@ -418,7 +418,45 @@ class OrderController extends HomeBaseController{ @@ -418,7 +418,45 @@ class OrderController extends HomeBaseController{
418 * 418 *
419 * @return data:返回用于调用支付的参数 419 * @return data:返回用于调用支付的参数
420 */ 420 */
421 - public function getPrice($users_id,$start_time,$end_time){ 421 + public function getPriceTest(){
  422 + /*先获取跨越天数*/
  423 +
  424 + $users_id=1;
  425 + $start_time=strtotime(input('start_time'));
  426 + $end_time=strtotime(input('end_time'));
  427 +// $end_time=$data['end_time']??time();
  428 + $spend=$this->timediff($start_time,$end_time);
  429 + if ($spend['min']!=0||$spend['sec']!=0){
  430 + $spend['hour']++;
  431 + }
  432 + $interval = Db::name('interval')->where('id',1)->find();
  433 + $cost=Db::name('cost')->where('id',1)->find();
  434 + $is_free=Db::name('users')->where('id',$users_id)->find()['is_free'];
  435 + $price=0;
  436 + $time=$start_time;
  437 + for ($i=0;$i<$spend['hour'];$i++){
  438 + $price+=$this->getPriceByTime($time,$interval['end_time'],$interval['start_time'],$interval['price'],$cost['cost']);
  439 + $time=$time+3600;
  440 + }
  441 +
  442 + if ($price>$cost['ceiling']){
  443 + $price=$cost['ceiling'];
  444 + $free=0;
  445 + }else{
  446 + if ($cost['free']==1 && $is_free==0){
  447 + $free=$this->getPriceByTime($start_time,$interval['end_time'],$interval['start_time'],$interval['price'],$cost['cost']);
  448 +// Db::name('users')->where('id',$users_id)->update(['is_free'=>1]);
  449 + }else{
  450 + $free=0;
  451 + }
  452 + }
  453 + $allPirce=$cost['ceiling']*$spend['day']+$price-$free;
  454 + return $allPirce;
  455 + }
  456 +
  457 +
  458 +
  459 + public function getPrice($users_id,$start_time,$end_time){
422 /*先获取跨越天数*/ 460 /*先获取跨越天数*/
423 461
424 462
@@ -435,7 +473,7 @@ class OrderController extends HomeBaseController{ @@ -435,7 +473,7 @@ class OrderController extends HomeBaseController{
435 $time=$start_time; 473 $time=$start_time;
436 for ($i=0;$i<$spend['hour'];$i++){ 474 for ($i=0;$i<$spend['hour'];$i++){
437 $price+=$this->getPriceByTime($time,$interval['end_time'],$interval['start_time'],$interval['price'],$cost['cost']); 475 $price+=$this->getPriceByTime($time,$interval['end_time'],$interval['start_time'],$interval['price'],$cost['cost']);
438 - $time=$time+3600; 476 + $time=$time+3600;
439 } 477 }
440 478
441 479
@@ -500,11 +538,20 @@ class OrderController extends HomeBaseController{ @@ -500,11 +538,20 @@ class OrderController extends HomeBaseController{
500 } 538 }
501 539
502 540
503 -  
504 - 541 + /**
  542 + * 获取当前时间点价格
  543 + * @param $time 开始时间点
  544 + * @param $first_time 一阶段价格
  545 + * @param $second_time 二阶段价格
  546 + * @param $cost1 一阶段金额单价
  547 + * @param $cost2 二阶段金额单价
  548 + * @return mixed
  549 + */
505 public function getPriceBytime($time,$first_time,$second_time,$cost1,$cost2){ 550 public function getPriceBytime($time,$first_time,$second_time,$cost1,$cost2){
506 - $first_time=strtotime($first_time);  
507 - $second_time=strtotime($second_time); 551 + $date=date('Y-m-d',$time);
  552 + $first_time=strtotime($date.' '.$first_time);
  553 + $second_time=strtotime($date.' '.$second_time);
  554 +
508 if ($time<$first_time){ 555 if ($time<$first_time){
509 return $cost1; 556 return $cost1;
510 } 557 }