...
|
...
|
@@ -403,9 +403,109 @@ class OrderController extends HomeBaseController{ |
|
|
}
|
|
|
return $price;
|
|
|
}
|
|
|
/**
|
|
|
* @title 计算价格
|
|
|
* @description 微信统一下单
|
|
|
* @author 董瑞恩
|
|
|
* @url /portal/order/getPriceSGJ
|
|
|
* @method GET
|
|
|
*
|
|
|
* @param name:start_time type:String require:1 default:无 other: desc:起始时间
|
|
|
* @param name:end_time type:String require:1 default:无 other: desc:结束时间
|
|
|
*
|
|
|
* @return data:返回用于调用支付的参数
|
|
|
*/
|
|
|
public function getPriceSGJ(){
|
|
|
/*先获取跨越天数*/
|
|
|
$users_id='11';
|
|
|
$data=input();
|
|
|
$start_time=$data['start_time']??'1545084020';
|
|
|
$end_time=$data['end_time']??time();
|
|
|
$spend=$this->timediff($start_time,$end_time);
|
|
|
if ($spend['min']!=0||$spend['sex']!=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 getOnlyPriceSGJ(){
|
|
|
/*先获取跨越天数*/
|
|
|
$users_id='11';
|
|
|
$data=input();
|
|
|
$start_time=$data['start_time']??'1545084020';
|
|
|
$end_time=$data['end_time']??time();
|
|
|
$spend=$this->timediff($start_time,$end_time);
|
|
|
if ($spend['min']!=0||$spend['sex']!=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 getPriceBytime($time,$first_time,$second_time,$cost1,$cost2){
|
|
|
$first_time=strtotime($first_time);
|
|
|
$second_time=strtotime($second_time);
|
|
|
if ($time<$first_time){
|
|
|
return $cost1;
|
|
|
}
|
|
|
|
|
|
if ($time>$first_time && $time<$second_time){
|
|
|
return $cost2;
|
|
|
}
|
|
|
|
|
|
if ($time>$second_time){
|
|
|
return $cost1;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @title 统一下单
|
|
|
* @description 微信统一下单
|
|
|
* @author 董瑞恩
|
...
|
...
|
@@ -442,6 +542,7 @@ class OrderController extends HomeBaseController{ |
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
//支付回调接口
|
|
|
public function notify(){
|
|
|
$param = $this->request->param();
|
...
|
...
|
@@ -471,6 +572,8 @@ class OrderController extends HomeBaseController{ |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function create_noncestr($length = 4){
|
|
|
$chars = "0123456789";
|
|
|
$str = "";
|
...
|
...
|
@@ -480,4 +583,93 @@ class OrderController extends HomeBaseController{ |
|
|
return $str;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 计算两个时间戳戳相差时间
|
|
|
* @param $begin_time
|
|
|
* @param $end_time
|
|
|
* @return array
|
|
|
*/
|
|
|
public function timediff($begin_time,$end_time)
|
|
|
{
|
|
|
if ($begin_time < $end_time) {
|
|
|
$starttime = $begin_time;
|
|
|
$endtime = $end_time;
|
|
|
} else {
|
|
|
$starttime = $end_time;
|
|
|
$endtime = $begin_time;
|
|
|
}
|
|
|
//计算天数
|
|
|
$timediff = $endtime - $starttime;
|
|
|
$days = intval($timediff / 86400);
|
|
|
//计算小时数
|
|
|
$remain = $timediff % 86400;
|
|
|
$hours = intval($remain / 3600);
|
|
|
//计算分钟数
|
|
|
$remain = $remain % 3600;
|
|
|
$mins = intval($remain / 60);
|
|
|
//计算秒数
|
|
|
$secs = $remain % 60;
|
|
|
$res = array("day" => $days, "hour" => $hours, "min" => $mins, "sec" => $secs);
|
|
|
return $res;
|
|
|
}
|
|
|
/**
|
|
|
* 计算出不同收费时间段的使用时间
|
|
|
* @param $start 开始时间
|
|
|
* @param $end 结束时间
|
|
|
* @param $first 早上计时点
|
|
|
* @param $second 晚上计时点
|
|
|
* @return mixed
|
|
|
*/
|
|
|
public function getTimeOneDay($start,$end,$first,$second){
|
|
|
$start_date=date('Y-m-d',$start);
|
|
|
$first=$start_date.' '.$first;
|
|
|
$first=strtotime($first);
|
|
|
$second=$start_date.' '.$second;
|
|
|
$second=strtotime($second);
|
|
|
// dump($start);
|
|
|
// dump($end);
|
|
|
// dump($first);
|
|
|
// dump($second);
|
|
|
/*分为六种情况分别处理*/
|
|
|
|
|
|
if ($end<=$first){
|
|
|
$time['first']=$start-$end;
|
|
|
$time['second']=0;
|
|
|
return $time;
|
|
|
}
|
|
|
|
|
|
if ($start<=$first && $end<=$second && $end>$first){
|
|
|
$time['first']=$first-$start;
|
|
|
$time['second']=$end-$first;
|
|
|
return $time;
|
|
|
}
|
|
|
|
|
|
if ($start<=$first && $end>$second){
|
|
|
$time['first']=($first-$start)+($end-$second);
|
|
|
$time['second']=$second-$first;
|
|
|
return $time;
|
|
|
}
|
|
|
|
|
|
if ($start>$first && $start<=$second && $end<=$second){
|
|
|
$time['first']='0';
|
|
|
$time['second']=$end-$start;
|
|
|
return $time;
|
|
|
}
|
|
|
|
|
|
if ($start>$first && $start<=$second && $end>$second ){
|
|
|
$time['first']=$second-$start;
|
|
|
$time['second']=$end-$second;
|
|
|
return $time;
|
|
|
}
|
|
|
|
|
|
if ($start>$second && $end>$second){
|
|
|
$time['first']=$end-$start;
|
|
|
$time['second']=0;
|
|
|
return $time;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|