diff --git a/app/api/controller/VehicleController.php b/app/api/controller/VehicleController.php index de0e4ca90..5cedf913f 100644 --- a/app/api/controller/VehicleController.php +++ b/app/api/controller/VehicleController.php @@ -21,16 +21,21 @@ 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','<>', 1)->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('status','<>',3)->where('type',1)->count(); - //可在租车辆 - $doubleRentCar = max($villageCompany - $rentCar - $applyCar - $selfCar,0); + //获取该公司已签约的小组服务公司数量 + $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'])->whereNotIn('type','1,2')->count(); + //申请中的车辆 + $applyCar = VehicleContract::field('num')->where('company_b_id',$this->userInfo['company_id'])->where('status','in','-1,0,1,2')->sum('num'); + //自有车辆数量 + $selfCar = VehicleContract::field('id')->where('company_a_id',$this->userInfo['company_id'])->where('type',1)->where('status','in','-1,0,1,2,3')->sum('num'); + //购买车辆数量 + //获取下面的小组服务公司 + $villageCompanys = Contract::field('party_b')->where('party_a',$this->userInfo['company_id'])->where('signing_timer',2)->select()->toArray(); + $villageCompanys_ids = array_column($villageCompanys,'party_b'); + $buyCar = VehicleContract::field('id')->where('company_b_id','in',$villageCompanys_ids)->where('type',3)->where('status','in','-1,0,1,2,3')->count(); + //可在租车辆 + $doubleRentCar = max($villageCompany - $rentCar - $applyCar - $selfCar - $buyCar,0); if($params['num'] > $doubleRentCar ){ return $this->fail('数量超过可再租车辆数'); } @@ -397,13 +402,18 @@ class VehicleController extends BaseApiController //获取该公司已签约的小组服务公司数量 $villageCompany = Contract::field('id')->where('party_a',$company['id'])->where('signing_timer',2)->count(); //已经租赁车辆 - $rentCar = VehicleRent::field('id')->where('company_id',$company['id'])->where('type','<>', 1)->count(); + $rentCar = VehicleRent::field('id')->where('company_id',$company['id'])->whereNotIn('type','1,2')->count(); //申请中的车辆 $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('status','<>',3)->where('type',1)->count(); + $selfCar = VehicleContract::field('id')->where('company_a_id',$company['id'])->where('type',1)->where('status','in','-1,0,1,2,3')->sum('num'); + //购买车辆数量 + //获取下面的小组服务公司 + $villageCompanys = Contract::field('party_b')->where('party_a',$company['id'])->where('signing_timer',2)->select()->toArray(); + $villageCompanys_ids = array_column($villageCompanys,'party_b'); + $buyCar = VehicleContract::field('id')->where('company_b_id','in',$villageCompanys_ids)->where('type',3)->where('status','in','-1,0,1,2,3')->count(); //可在租车辆 - $doubleRentCar = max($villageCompany - $rentCar - $applyCar - $selfCar,0); + $doubleRentCar = max($villageCompany - $rentCar - $applyCar - $selfCar - $buyCar,0); //设置数据 $data = [ 'apply' => $vehicleContract, @@ -412,6 +422,7 @@ class VehicleController extends BaseApiController 'rent_num' => $rentCar, 'can_rent_num' => intval($doubleRentCar), 'self_num' => $selfCar, + 'buy_num' => $buyCar, 'apply_num' => $applyCar ]; //返回