diff --git a/app/api/controller/VehicleController.php b/app/api/controller/VehicleController.php index 3089f38c4..a18023b0c 100644 --- a/app/api/controller/VehicleController.php +++ b/app/api/controller/VehicleController.php @@ -22,6 +22,19 @@ class VehicleController extends BaseApiController if(empty($params['num'])){ return $this->fail('缺少必要参数'); } + //获取该公司已签约的小组服务公司数量 + $villageCompany = Contract::field('id')->where('party_a',$this->userInfo['company_id'])->where('signing_timer',2)->count(); + //系统车辆数量 + $rentCar = VehicleRent::field('id')->where('company_id',$this->userInfo['company_id'])->where('type',0)->count(); + //申请中的车辆 + $applyCar = VehicleContract::field('num')->where('company_b_id',$this->userInfo['company_id'])->where('status','in','-1,0,1,2')->sum('num'); + //自有车辆数量 + $selfCar = VehicleRent::field('id')->where('company_id',$this->userInfo['company_id'])->where('type',1)->count(); + //可在租车辆 + $doubleRentCar = $villageCompany - $rentCar - $applyCar - $selfCar; + if($params['num'] > $doubleRentCar ){ + return $this->fail('数量超过可再租车辆数'); + } //查找乙方公司信息 $party_b = Company::field('id,company_name,organization_code,master_name,master_phone,master_email,company_type')->where('id',$this->userInfo['company_id'])->find(); if(empty($party_b)) { @@ -302,7 +315,7 @@ class VehicleController extends BaseApiController //系统车辆数量 $rentCar = VehicleRent::field('id')->where('company_id',$company['id'])->where('type',0)->count(); //申请中的车辆 - $applyCar = VehicleContract::field('num')->where('company_b_id',$company['id'])->where('status','in','-1,0,1,2,')->sum('num'); + $applyCar = VehicleContract::field('num')->where('company_b_id',$company['id'])->where('status','in','-1,0,1,2')->sum('num'); //自有车辆数量 $selfCar = VehicleRent::field('id')->where('company_id',$company['id'])->where('type',1)->count(); //可在租车辆