作者 sgj

fix a bug of fee

... ... @@ -410,7 +410,7 @@ class OrderController extends HomeBaseController{
* @title 计算价格
* @description 微信统一下单
* @author 董瑞恩
* @url /portal/order/getPrice
* @url /portal/order/getPriceTest
* @method GET
*
* @param name:start_time type:String require:1 default:无 other: desc:起始时间
... ... @@ -418,7 +418,45 @@ class OrderController extends HomeBaseController{
*
* @return data:返回用于调用支付的参数
*/
public function getPrice($users_id,$start_time,$end_time){
public function getPriceTest(){
/*先获取跨越天数*/
$users_id=1;
$start_time=strtotime(input('start_time'));
$end_time=strtotime(input('end_time'));
// $end_time=$data['end_time']??time();
$spend=$this->timediff($start_time,$end_time);
if ($spend['min']!=0||$spend['sec']!=0){
$spend['hour']++;
}
$interval = Db::name('interval')->where('id',1)->find();
$cost=Db::name('cost')->where('id',1)->find();
$is_free=Db::name('users')->where('id',$users_id)->find()['is_free'];
$price=0;
$time=$start_time;
for ($i=0;$i<$spend['hour'];$i++){
$price+=$this->getPriceByTime($time,$interval['end_time'],$interval['start_time'],$interval['price'],$cost['cost']);
$time=$time+3600;
}
if ($price>$cost['ceiling']){
$price=$cost['ceiling'];
$free=0;
}else{
if ($cost['free']==1 && $is_free==0){
$free=$this->getPriceByTime($start_time,$interval['end_time'],$interval['start_time'],$interval['price'],$cost['cost']);
// Db::name('users')->where('id',$users_id)->update(['is_free'=>1]);
}else{
$free=0;
}
}
$allPirce=$cost['ceiling']*$spend['day']+$price-$free;
return $allPirce;
}
public function getPrice($users_id,$start_time,$end_time){
/*先获取跨越天数*/
... ... @@ -435,7 +473,7 @@ class OrderController extends HomeBaseController{
$time=$start_time;
for ($i=0;$i<$spend['hour'];$i++){
$price+=$this->getPriceByTime($time,$interval['end_time'],$interval['start_time'],$interval['price'],$cost['cost']);
$time=$time+3600;
$time=$time+3600;
}
... ... @@ -500,11 +538,20 @@ class OrderController extends HomeBaseController{
}
/**
* 获取当前时间点价格
* @param $time 开始时间点
* @param $first_time 一阶段价格
* @param $second_time 二阶段价格
* @param $cost1 一阶段金额单价
* @param $cost2 二阶段金额单价
* @return mixed
*/
public function getPriceBytime($time,$first_time,$second_time,$cost1,$cost2){
$first_time=strtotime($first_time);
$second_time=strtotime($second_time);
$date=date('Y-m-d',$time);
$first_time=strtotime($date.' '.$first_time);
$second_time=strtotime($date.' '.$second_time);
if ($time<$first_time){
return $cost1;
}
... ...