diff --git a/app/api/controller/VehicleController.php b/app/api/controller/VehicleController.php index 5f24547f1..a30a26e2f 100644 --- a/app/api/controller/VehicleController.php +++ b/app/api/controller/VehicleController.php @@ -30,7 +30,7 @@ class VehicleController extends BaseApiController //自有车辆数量 $selfCar = VehicleRent::field('id')->where('company_id',$this->userInfo['company_id'])->where('status','<>',3)->where('type',1)->count(); //可在租车辆 - $doubleRentCar = $villageCompany - $rentCar - $applyCar - $selfCar; + $doubleRentCar = max($villageCompany - $rentCar - $applyCar - $selfCar,0); if($params['num'] > $doubleRentCar ){ return $this->fail('数量超过可再租车辆数'); } @@ -395,7 +395,7 @@ class VehicleController extends BaseApiController //自有车辆数量 $selfCar = VehicleRent::field('id')->where('company_id',$company['id'])->where('status','<>',3)->where('type',1)->count(); //可在租车辆 - $doubleRentCar = $villageCompany - $rentCar - $applyCar - $selfCar; + $doubleRentCar = max($villageCompany - $rentCar - $applyCar - $selfCar,0); //设置数据 $data = [ 'apply' => $vehicleContract, @@ -419,9 +419,17 @@ class VehicleController extends BaseApiController if($company['company_type'] != 18 ){ return $this->fail('非小组公司不能访问'); } + //获取购买车辆记录 + $buyCarRent = VehicleBuyRecord::where('company_id',$company['id'])->where('status','<>',4)->findOrEmpty(); + if($buyCarRent->isEmpty()){ + $data = VehicleContract::where('company_b_id',$company['id'])->where('type','<>',2)->order('id desc')->findOrEmpty(); + }else{ + $data = $buyCarRent; + $data['status'] = 0; + $data['type'] = 0; + } //获取签约合同 - $vehicleContract = VehicleContract::where('company_b_id',$company['id'])->where('type','<>',2)->order('id desc')->findOrEmpty(); - return $this->success('请求成功',$vehicleContract->toArray()); + return $this->success('请求成功',$data->toArray()); } //车辆详情