diff --git a/app/api/controller/VehicleController.php b/app/api/controller/VehicleController.php index df7f43db4..35d829740 100644 --- a/app/api/controller/VehicleController.php +++ b/app/api/controller/VehicleController.php @@ -22,8 +22,8 @@ class VehicleController extends BaseApiController } //获取该公司已签约的小组服务公司数量 $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('status','<>',3)->where('type',0)->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'); //自有车辆数量 @@ -361,8 +361,8 @@ class VehicleController extends BaseApiController })->toArray(); //获取该公司已签约的小组服务公司数量 $villageCompany = Contract::field('id')->where('party_a',$company['id'])->where('signing_timer',2)->count(); - //系统车辆数量 - $rentCar = VehicleRent::field('id')->where('company_id',$company['id'])->where('status','<>', 3)->where('type',0)->count(); + //已经租赁车辆 + $rentCar = VehicleRent::field('id')->where('company_id',$company['id'])->where('type','<>', 1)->count(); //申请中的车辆 $applyCar = VehicleContract::field('num')->where('company_b_id',$company['id'])->where('status','in','-1,0,1,2')->sum('num'); //自有车辆数量 @@ -393,13 +393,7 @@ class VehicleController extends BaseApiController return $this->fail('非小组公司不能访问'); } //获取申请信息 - $vehicleContract = VehicleContract::where('company_b_id',$company['id'])->order('id desc')->find(); - if(empty($vehicleContract)){ - return $this->success('没有数据,请申请',['status'=>-2]); - } - if($vehicleContract['type'] == 2){ - return $this->success('合同已解除',['status'=>-3]); - } + $vehicleContract = VehicleContract::where('company_b_id',$company['id'])->order('id desc')->findOrEmpty(); if($vehicleContract['status'] == 3){ if(!empty($vehicleContract['cars_info'])){ $vehicleContract['cars_info'] = json_decode($vehicleContract['cars_info'],true); @@ -528,12 +522,22 @@ class VehicleController extends BaseApiController 'update_time' => time(), 'old_file' => $contract['contract_url'], ]; - //写入数据 - $result = VehicleContract::create($data); - if($result){ - return $this->success('申请成功,待镇街公司审核'); - }else{ - return $this->fail('申请失败,请稍后重试'); + Db::startTrans(); + try{ + //写入数据 + $new_result = VehicleContract::create($data); + //修改原合同状态 + $old_result = VehicleContract::where('id',$contract['id'])->update(['status',5]); + if($new_result && $old_result){ + Db::commit(); + return $this->success('申请成功,待镇街公司审核'); + }else{ + Db::rollback(); + return $this->fail('申请失败,请稍后重试'); + } + }catch (\Exception $e) { + Db::rollback(); + return $this->fail($e->getMessage()); } }