123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- use think\cache\driver\Redis;
- use app\common\library\Area;
- /**
- * 汽车接口
- */
- class Car extends Api
- {
- protected $noNeedLogin = ['index','showall','car_info','car_comment','get_car_price'];
- protected $noNeedRight = ['*'];
- public function index(){
- $where = [];
- $where['car.status'] = 1;
- $where['car.audit_status'] = 1;
- //车型
- $type_id = input('type_id',0);
- if($type_id){
- $where['p.type_id'] = $type_id;
- }
- //品牌
- $brand_id = input('brand_id',0);
- if($brand_id){
- $where['p.brand_id'] = ['IN',$brand_id];
- }
- //变速箱
- $gear_id = input('gear_id',0);
- if($gear_id){
- $where['p.gear_id'] = $gear_id;
- }
- //座位数
- $seat_id = input('seat_id',0);
- if($seat_id){
- $where['p.seat_id'] = ['IN',$seat_id];
- }
- //车辆配置
- $config_ids = input('config_ids','');
- if($config_ids){
- $config_ids = explode(',',$config_ids);
- foreach($config_ids as $ck => $cv){
- //$where[]=['exp','FIND_IN_SET('.$cv.',car.config_ids)'];
- $where[]=['exp',Db::raw("FIND_IN_SET('".$cv."',car.config_ids)")];
- }
- }
- //便捷取还
- $back_ids = input('back_ids','');
- if($back_ids){
- $back_ids = explode(',',$back_ids);
- foreach($back_ids as $sk => $sv){
- //$where[] = ['exp','FIND_IN_SET('.$back_ids.',company.back_ids)'];
- $where[] = ['exp',Db::raw("FIND_IN_SET('".$sv."',company.back_ids)")];
- }
- }
- //门店服务
- $service_ids = input('service_ids','');
- if($service_ids){
- $service_ids = explode(',',$service_ids);
- foreach($service_ids as $sk => $sv){
- //$where[]=['exp','FIND_IN_SET('.$sv.',company.service_ids)'];
- $where[]=['exp',Db::raw("FIND_IN_SET('".$sv."',company.service_ids)")];
- }
- }
- //双坐标都符合的公司ids
- $get_longitude = input('get_longitude',0);
- $get_latitude = input('get_latitude',0);
- $back_longitude = input('back_longitude',0);
- $back_latitude = input('back_latitude',0);
- //符合公司ids
- $company_can = $this->area_check($get_longitude,$get_latitude,$back_longitude,$back_latitude);
- $where['car.company_id'] = ['IN',$company_can];
- //双坐标都符合的公司ids
- //排序
- $ordertype = input('ordertype',0);
- if($ordertype == 1){
- $orderby = 'price_min asc';
- }elseif($ordertype == 2){
- $orderby = 'price_min desc';
- }else{
- $orderby = 'car.id desc';
- }
- //列表
- $list = Db::name('car')
- ->field('
- car.*,
- min(car.pricetoday) price_min,count(car.id) as baojianum,group_concat(car.id) as concat_car_id,
- p.type_id,p.brand_id,p.model_id,p.image,p.images,p.gear_id,p.pailiang,p.seat_id,p.banben,
- company.back_ids,company.service_ids,
- brand.name as brand_name,model.name as model_name,gear.name as gear_name,seat.name as seat_name
- ')
- ->join('car_public p','car.carpublic_id = p.id','LEFT')
- ->join('company','car.company_id = company.id','LEFT')
- ->join('store','car.store_id = store.id','LEFT')
- ->join('car_enum_brand brand','p.brand_id = brand.id','LEFT')
- ->join('car_enum_model model','p.model_id = model.id','LEFT')
- ->join('car_enum_gear gear','p.gear_id = gear.id','LEFT')
- ->join('car_enum_seat seat','p.seat_id = seat.id','LEFT')
- ->where($where)->order($orderby)->group('carpublic_id')->autopage()->select();
- $list = list_domain_image($list,['image','images']);
- $this->success('success',$list);
- }
- //双坐标都符合的公司ids
- private function area_check($get_longitude,$get_latitude,$back_longitude,$back_latitude){
- $company_can = [];//符合公司ids
- $companys = Db::name('company')->column('id');
- foreach($companys as $key => $val){
- $store_zuobiao = Db::name('store_zuobiao')->where('company_id',$val)->column('zuobiao');//某公司下所有门店的坐标
- if(empty($store_zuobiao)){
- continue;
- }
- //dump($store_zuobiao);
- $newArr = []; //坐标集合
- foreach($store_zuobiao as $k => $v){
- if(empty($v)){ continue;}
- $v = json_decode($v, true);
- if(!is_array($v)){ continue;}
- /*if(isset($v[0]) && is_array($v[0])){
- $newArr[] = $v[0];
- }*/
- $newArr[] = $v;
- }
- //dump($newArr);
- if(empty($newArr)){
- continue;
- }
- $area = new Area($newArr);
- $get_bol = $area->checkPoint($get_longitude, $get_latitude);
- $back_bol = $area->checkPoint($back_longitude, $back_latitude);
- //dump($get_bol);
- //dump($back_bol);
- //借车点和还车点都满足
- if($get_bol !== false && $back_bol !== false && $get_bol >= 0 && $back_bol >= 0){
- //echo $val;
- $company_can[] = $val;
- }
- //echo '<hr>';
- }
- return $company_can;
- //dump($company_can);
- //取车坐标
- }
- public function test(){
- //大兴取116.339878,39.730733
- //昌平还116.197299,40.234052
- //北京中心还116.372074,39.898331
- $get_back_fee = $this->store_fanwei_check(56,'116.339878','39.730733','116.372074','39.898331');
- dump($get_back_fee);
- }
- //车辆取还费
- private function store_fanwei_check($car_id,$get_longitude,$get_latitude,$back_longitude,$back_latitude){
- $return_fee = ['get_price'=>0,'back_price'=>0,'get_zuobiao_id'=>0,'back_zuobiao_id'=>0];
- $company_id = Db::name('car')->where('id',$car_id)->value('company_id');
- $store_zuobiao = Db::name('store_zuobiao')->where('company_id',$company_id)->column('id,zuobiao');//某公司下所有门店的坐标
- $store_fee = Db::name('store_zuobiao')->where('company_id',$company_id)->column('id,get_price,back_price');//某公司下所有门店的坐标
- if(empty($store_zuobiao)){
- return $return_fee;
- }
- //dump($store_zuobiao);
- $newArr = []; //坐标集合
- foreach($store_zuobiao as $k => $v){
- if(empty($v)){ continue;}
- $v = json_decode($v, true);
- if(!is_array($v)){ continue;}
- $newArr[$k] = $v;
- }
- //dump($newArr);
- if(empty($newArr)){
- return $return_fee;
- }
- $area = new Area($newArr);
- $get_bol = $area->checkPoint($get_longitude, $get_latitude);
- $back_bol = $area->checkPoint($back_longitude, $back_latitude);
- //dump($get_bol);//取
- //dump($back_bol);//还
- //借车点和还车点都满足
- if($get_bol !== false && $get_bol >= 0){
- $return_fee['get_price'] = $store_fee[$get_bol]['get_price'];
- $return_fee['get_zuobiao_id'] = $get_bol;
- }
- if($back_bol !== false && $back_bol >= 0){
- $return_fee['back_price'] = $store_fee[$back_bol]['back_price'];
- $return_fee['back_zuobiao_id'] = $back_bol;
- }
- //dump($return_fee);
- return $return_fee;
- }
- //展开车
- public function showall(){
- $id = input('concat_car_id',0);
- $address = input('address','');
- $starttime = input('starttime');
- $endtime = input('endtime');
- $days = bcdiv(($endtime - $starttime),86400,2);
- $longitude = input('longitude','');
- $latitude = input('latitude','');
- $where = [];
- $where['car.status'] = 1;
- $where['car.audit_status'] = 1;
- $where['car.id'] = ['IN',$id];
- $list = Db::name('car')
- ->field('
- car.*,
- p.type_id,p.brand_id,p.model_id,p.image,p.images,p.gear_id,p.seat_id,p.pailiang,p.banben,
- company.name as company_name,company.back_ids,company.service_ids,
- store.longitude as store_longitude,store.latitude as store_latitude,
- brand.name as brand_name,model.name as model_name,gear.name as gear_name,seat.name as seat_name
- ')
- ->join('car_public p','car.carpublic_id = p.id','LEFT')
- ->join('company','car.company_id = company.id','LEFT')
- ->join('store','car.store_id = store.id','LEFT')
- ->join('car_enum_brand brand','p.brand_id = brand.id','LEFT')
- ->join('car_enum_model model','p.model_id = model.id','LEFT')
- ->join('car_enum_gear gear','p.gear_id = gear.id','LEFT')
- ->join('car_enum_seat seat','p.seat_id = seat.id','LEFT')
- ->where($where)->order('car.pricetoday asc')->select();
- $list = list_domain_image($list,['image','images']);
- $redis = new Redis ();
- $redis->handler()->geoAdd("cs", $longitude, $latitude, 'kaishi_address');
- foreach($list as $key => &$val){
- //退还标签
- $val['backs'] = Db::name('store_enum_back')->where('id','IN',$val['back_ids'])->column('name');
- //服务标签
- $val['service'] = Db::name('store_enum_service')->where('id','IN',$val['service_ids'])->column('name');
- //配置标签
- $val['config'] = Db::name('car_enum_config')->where('id','IN',$val['config_ids'])->column('name');
- //取车点
- $val['get_address'] = $address;
- $val['days'] = $days;
- $val['price'] = $val['pricetoday']; //今日价格
- $val['price_total'] = bcmul($val['pricetoday'],$days,2);
- //门店直线距离
- $rediskey = 'juli' . $val['store_id'];
- $redis->handler()->geoAdd("cs", $val['store_longitude'], $val['store_latitude'], $rediskey);
- $distance = $redis->handler()->geoDist("cs", 'kaishi_address', $rediskey, 'km');
- $val['distance'] = $distance !== false ? $distance : 0;
- //合并image到images
- $val['images'] .= ','.$val['image'];
- //追加客服图片与客服电话
- $val['kefu_mobile'] = config('site.kefu_mobile');
- $val['kefu_weixin'] = localpath_to_netpath(config('site.kefu_weixin'));
- }
- $this->success('success',$list);
- }
- //单车信息
- public function car_info(){
- $id = input('id');
- $where = [];
- $where['car.id'] = $id;
- $info = Db::name('car')
- ->field('
- car.*,
- p.type_id,p.brand_id,p.model_id,p.image,p.images,p.gear_id,p.seat_id,p.pailiang,p.banben,
- company.name as company_name,company.back_ids,company.service_ids,
- store.longitude as store_longitude,store.latitude as store_latitude,
- brand.name as brand_name,model.name as model_name,gear.name as gear_name,seat.name as seat_name
- ')
- ->join('car_public p','car.carpublic_id = p.id','LEFT')
- ->join('company','car.company_id = company.id','LEFT')
- ->join('store','car.store_id = store.id','LEFT')
- ->join('car_enum_brand brand','p.brand_id = brand.id','LEFT')
- ->join('car_enum_model model','p.model_id = model.id','LEFT')
- ->join('car_enum_gear gear','p.gear_id = gear.id','LEFT')
- ->join('car_enum_seat seat','p.seat_id = seat.id','LEFT')
- ->where($where)->find();
- $info = info_domain_image($info,['image','images']);
- $info['price'] = $info['pricetoday'];//今日价格
- //退还标签
- $info['backs'] = Db::name('store_enum_back')->where('id','IN',$info['back_ids'])->column('name');
- //服务标签
- $info['service'] = Db::name('store_enum_service')->where('id','IN',$info['service_ids'])->column('name');
- //配置标签
- $info['config'] = Db::name('car_enum_config')->where('id','IN',$info['config_ids'])->column('name');
- $this->success('success',$info);
- }
- //汽车评价
- public function car_comment(){
- $id = input('car_id',0);
- //评价
- $comment = Db::name('order_comment')->alias('c')
- ->field('c.*,user.avatar,user.mobile')
- ->join('user','c.user_id = user.id','LEFT')
- ->where('c.car_id',$id)->order('id desc')->autopage()->select();
- foreach($comment as $key => &$val){
- $val['avatar'] = localpath_to_netpath($val['avatar']);
- $val['mobile'] = str_replace(substr($val['mobile'],3,5),'****',$val['mobile']);
- }
- $this->success('success',$comment);
- }
- //确认订单
- public function confirmorder(){
- $id = input('id');
- $starttime = input('starttime');
- $endtime = input('endtime');
- $days = bcdiv(($endtime - $starttime),86400,2);
- $coupon_id = input('coupon_id',0);
- $yajin_type = input('yajin_type','zhima');
- //双坐标都符合的公司ids
- $get_longitude = input('get_longitude',0);
- $get_latitude = input('get_latitude',0);
- $back_longitude = input('back_longitude',0);
- $back_latitude = input('back_latitude',0);
- $get_back_fee = $this->store_fanwei_check($id,$get_longitude,$get_latitude,$back_longitude,$back_latitude);
- //
- $where = [];
- $where['car.id'] = $id;
- $info = Db::name('car')
- ->field('
- car.*,
- p.type_id,p.brand_id,p.model_id,p.image,p.images,p.gear_id,p.seat_id,p.pailiang,
- com.name as company_name,com.back_ids,com.service_ids,com.service_price,
- store.longitude as store_longitude,store.latitude as store_latitude,
- brand.name as brand_name,model.name as model_name,gear.name as gear_name,seat.name as seat_name
- ')
- ->join('car_public p','car.carpublic_id = p.id','LEFT')
- ->join('company com','car.company_id = company.id','LEFT')
- ->join('store','car.store_id = store.id','LEFT')
- ->join('car_enum_brand brand','p.brand_id = brand.id','LEFT')
- ->join('car_enum_model model','p.model_id = model.id','LEFT')
- ->join('car_enum_gear gear','p.gear_id = gear.id','LEFT')
- ->join('car_enum_seat seat','p.seat_id = seat.id','LEFT')
- ->where($where)->find();
- $info['weizhang_price'] = config('site.public_weizhang_price');
- $info = info_domain_image($info,['image','images']);
- // $info['lease_price'] = bcmul($info['price'],$days,2);
- $price_data = $this->get_car_price_do($starttime,$endtime,$info);
- $info['lease_price'] = $price_data['lease_price'];
- $info['price_data'] = $price_data['price_data'];
- $info['base_price'] = bcmul($info['base_price'],$days,2);
- $info['get_price'] = $get_back_fee['get_price']; //取车费
- $info['back_price'] = $get_back_fee['back_price']; //还车费
- $info['total_fee'] = $info['lease_price'] + $info['base_price'] + $info['service_price'] + $info['get_price'] + $info['back_price'];
- //芝麻免押才计算押金,否则走线下
- if($yajin_type == 'zhima'){
- //$info['total_fee'] += $info['yajin_price'] + $info['weizhang_price'];
- }
- $info['total_fee'] = bcadd($info['total_fee'],0,2);
- $coupon_price = Db::name('user_coupons')->where('id',$coupon_id)->value('amount');
- $info['coupon_price'] = $coupon_price > 0 ? $coupon_price : 0;
- $info['pay_fee'] = $info['total_fee'] - $info['coupon_price'];
- //可用优惠券
- $coupon_list = Db::name('user_coupons')->where(
- [
- 'user_id' => $this->auth->id,
- 'enough' => ['elt',$info['total_fee']],
- 'status' => 0,
- 'usetimeend' => ['gt',time()],
- 'company_id' => ['IN',[0,$info['company_id']]],
- ]
- )->select();
- $info['coupons'] = $coupon_list;
-
- $this->success('success',$info);
- }
- //下订单
- public function createorder(){
- $car_id = input('car_id',0);
- $starttime = input('starttime');
- $endtime = input('endtime');
- $days = bcdiv(($endtime - $starttime),86400,2);
- $get_province_name = input('get_province_name','');
- $get_city_name = input('get_city_name','');
- $get_area_name = input('get_area_name','');
- $get_address = input('get_address','');
- $get_longitude = input('get_longitude','');
- $get_latitude = input('get_latitude','');
- $back_province_name = input('back_province_name','');
- $back_city_name = input('back_city_name','');
- $back_area_name = input('back_area_name','');
- $back_address = input('back_address','');
- $back_longitude = input('back_longitude','');
- $back_latitude = input('back_latitude','');
- $user_truename = input('user_truename','');
- $user_mobile = input('user_mobile','');
- $user_idcard = input('user_idcard','');
- $coupon_id = input('coupon_id',0);
- $yajin_type = input('yajin_type','offline');
- //车辆信息
- $car_info = Db::name('car')
- ->field('
- car.*,
- p.shortname,p.image as public_image,p.pailiang,p.banben,
- store.longitude as store_longitude,store.latitude as store_latitude,
- brand.name as brand_name,model.name as model_name,gear.name as gear_name,seat.name as seat_name,
- company.service_price
- ')
- ->join('car_public p','car.carpublic_id = p.id','LEFT')
- ->join('store','car.store_id = store.id','LEFT')
- ->join('car_enum_brand brand','p.brand_id = brand.id','LEFT')
- ->join('car_enum_model model','p.model_id = model.id','LEFT')
- ->join('car_enum_gear gear','p.gear_id = gear.id','LEFT')
- ->join('car_enum_seat seat','p.seat_id = seat.id','LEFT')
- ->join('company','car.company_id = company.id','LEFT')
- ->where('car.id',$car_id)->find();
- if($car_info['audit_status'] != 1){
- $this->error('不存在的车辆,请重新选择');
- }
- if($car_info['status'] != 1){
- $this->error('该车辆已经被占用');
- }
- $car_info['weizhang_price'] = config('site.public_weizhang_price') ?: 0;
- //数据
- $data = [
- 'orderno'=> createUniqueNo('N',$this->auth->id),
- 'starttime' => $starttime,
- 'endtime' => $endtime,
- 'company_id' => $car_info['company_id'],
- 'get_store_id' => $car_info['store_id'],
- 'back_store_id' => $car_info['store_id'], //先默认同上
- 'car_id' => $car_id,
- 'car_image' => $car_info['public_image'],
- 'car_shortname' => $car_info['brand_name'].' '.$car_info['model_name'],
- 'car_infoname' => $car_info['gear_name'].'|'.$car_info['seat_name'].'|'.$car_info['pailiang'].'|'.$car_info['banben'],
- 'car_chepai' => $car_info['chepai'],
- 'price' => $car_info['price'],
- 'days' => $days,
- //'lease_price' => bcmul($car_info['price'], $days,2), //借出费
- 'base_price' => bcmul($car_info['base_price'],$days,2), //基础保障费
- 'service_price' => $car_info['service_price'], //手续费
- 'yajin_price' => $car_info['yajin_price'], //车辆押金
- 'weizhang_price' => $car_info['weizhang_price'], //违章押金
- 'coupon_id' => 0,
- 'coupon_price' => 0,
- 'pay_fee' => 0,
- 'get_province_name' => $get_province_name,
- 'get_city_name' => $get_city_name,
- 'get_area_name' => $get_area_name,
- 'get_address' => $get_address,
- 'get_longitude' => $get_longitude,
- 'get_latitude' => $get_latitude,
- 'back_province_name' => $back_province_name,
- 'back_city_name' => $back_city_name,
- 'back_area_name' => $back_area_name,
- 'back_address' => $back_address,
- 'back_longitude' => $back_longitude,
- 'back_latitude' => $back_latitude,
- 'user_id' => $this->auth->id,
- 'user_truename' => $user_truename,
- 'user_mobile' => $user_mobile,
- 'user_idcard' => $user_idcard,
- 'status' => 0,
- 'createtime' => time(),
- ];
- //另写价格
- $price_data = $this->get_car_price_do($starttime,$endtime,$car_info);
- $data['lease_price'] = $price_data['lease_price'];
- $data['price_data'] = $price_data['price_data'];
- //双坐标都符合的公司ids
- $get_back_fee = $this->store_fanwei_check($car_id,$get_longitude,$get_latitude,$back_longitude,$back_latitude);
- $data['get_price'] = $get_back_fee['get_price']; //取车费
- $data['get_zuobiao_id'] = $get_back_fee['get_zuobiao_id']; //取车范围
- $data['back_price'] = $get_back_fee['back_price']; //还车费
- $data['back_zuobiao_id'] = $get_back_fee['back_zuobiao_id']; //还车范围
- //总计
- $data['total_fee'] = $data['lease_price'] + $data['base_price'] + $data['service_price'] + $data['get_price'] + $data['back_price'];
- //芝麻免押才计算押金,否则走线下
- if($yajin_type == 'zhima'){
- //$data['total_fee'] += $data['yajin_price'] + $data['weizhang_price'];
- $data['yajin_type'] = 1;
- }else{
- $data['yajin_type'] = 2;
- }
- $data['total_fee'] = bcadd($data['total_fee'],0,2);
- $data['coupon_id'] = $coupon_id;
- $data['coupon_price'] = Db::name('user_coupons')->where('id',$coupon_id)->value('amount') ?: 0; //优惠券减免费
- $data['pay_fee'] = $data['total_fee'] - $data['coupon_price']; //实际最终需要支付费
- //临时测试使用
- //$data['pay_fee'] = 0.09; //测试强制修改
- $order_id = Db::name('order')->insertGetId($data);
- //优惠券改为已使用
- $coupon_rs = Db::name('user_coupons')->where('id',$coupon_id)->update(['status'=>1,'usetime'=>time(),'use_order_id'=>$order_id]);
- if($coupon_rs === false){
- $this->error('优惠券使用失败');
- }
- //修改此车辆状态
- $car_rs = Db::name('car')->where('id',$car_id)->update(['status'=>0]);
- //
- $rs = [
- 'orderid' => $order_id,
- 'pay_fee' => $data['pay_fee'],
- ];
- $this->success('下单成功',$rs);
- }
- //测试
- public function get_car_price(){
- $car_id = 1;
- $info = Db::name('car')->where('id',$car_id)->find();
- $starttime = '1682825400';
- $endtime = '1683171000';//2023-04-05 11:30
- $rs = $this->get_car_price_do($starttime,$endtime,$info);
- dump($rs);
- }
- //获得价格
- private function get_car_price_do($starttime,$endtime,$info){
- if(empty($info['price_json'])){
- $price_json = [];
- }else{
- $price_json = json_decode($info['price_json'],true);
- }
- $price_default = $info['price'] ? $info['price'] : 0;
- $startdate = date('Y-m-d',$starttime);
- $startdatetime = strtotime($startdate); //第一天凌晨
- $enddate = date('Y-m-d',$endtime);
- //开始日期和结束日期是同一天
- if($startdate == $enddate){
- $start_price = isset($price_json[$startdate]) ? $price_json[$startdate] : $price_default;
- $lease_price = bcmul(bcdiv(($endtime - $starttime),86400,4),$start_price,2);
- return [
- 'lease_price'=> $lease_price,
- 'price_data' => json_encode([['date' => $startdate,'price' => $start_price,'fee' => $lease_price]]),
- ];
- }
- //开始日期和结束日期不是同一天
- $lease_price = 0;
- $price_data = [];
- $firstdate = ($startdatetime + 86400 - $starttime) / 3600; //(晚上0点 - 开始) / 3600,第一天小时数
- $lastdate = ($endtime - strtotime(date('Y-m-d',$endtime))) / 3600; //(结束 - 凌晨0点) / 3600,最后一天小时数
- $days = (strtotime(date('Y-m-d',$endtime)) - ($startdatetime + 86400)) / 86400;//中间天数
- // dump($firstdate);
- // dump($lastdate);
- // dump($days);
- //追加第一天
- $start_price = isset($price_json[$startdate]) ? $price_json[$startdate] : $price_default; //第一天价格
- $start_fee = bcmul(bcdiv($firstdate,24,4),$start_price,2);
- $lease_price = bcadd($lease_price,$start_fee,4); //第一天小时数 / 24 *第一天价格
- $price_data[] = ['date' => $startdate,'price' => $start_price,'fee'=> $start_fee];
- //追加中间天数
- for($i=1;$i<=$days;$i++){
- $i_time = $startdatetime + (86400 * $i);
- $i_date = date('Y-m-d',$i_time);
- $i_price = isset($price_json[$i_date]) ? $price_json[$i_date] : $price_default;
- $lease_price = bcadd($lease_price,$i_price,4);
- $price_data[] = ['date' => $i_date,'price' => $i_price, 'fee' => $i_price];
- }
- //追加最后一天
- $end_price = isset($price_json[$enddate]) ? $price_json[$enddate] : $price_default; //
- $end_fee = bcmul(bcdiv($lastdate,24,4),$end_price,2); //最后一天小时数 / 24 * 最后一天价格
- $lease_price = bcadd($lease_price,$end_fee,2);
- $price_data[] = ['date' => $enddate,'price' => $end_price, 'fee' => $end_fee];
- //结束
- return [
- 'lease_price'=> $lease_price,
- 'price_data' => json_encode($price_data),
- ];
- }
- }
|