Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
chenbo 2023-09-08 17:32:05 +08:00
commit 05cda2b2d6

View File

@ -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');
//自有车辆数量
@ -299,15 +299,41 @@ class VehicleController extends BaseApiController
if($vehicleContract['company_a_id'] != $this->userInfo['company_id']){
return $this->fail('数据不匹配');
}
//更新
$result = VehicleContract::where('id',$params['id'])->update([
'status' => 4,
'reject_message' => $params['content']
]);
if($result){
return $this->success('驳回成功');
//判断合同类型
if($vehicleContract['type'] == 2){
Db::startTrans();
try{
//查找原合同
$car = json_decode($vehicleContract['cars_info'],true);
$carRentInfo = VehicleRent::where('car_id',$car['id'])->findOrEmpty();
$oldVehicleContractUpdate = VehicleContract::where('id',$carRentInfo['contract_id'])->update(['status'=>3]);
//更新
$result = VehicleContract::where('id',$params['id'])->update([
'status' => 4,
'reject_message' => $params['content']
]);
if($oldVehicleContractUpdate && $result){
Db::commit();
return $this->success('驳回成功');
}else{
Db::rollback();
return $this->fail('驳回失败');
}
}catch (\Exception $e) {
Db::rollback();
return $this->fail($e->getMessage());
}
}else{
return $this->fail('驳回失败');
//更新
$result = VehicleContract::where('id',$params['id'])->update([
'status' => 4,
'reject_message' => $params['content']
]);
if($result){
return $this->success('驳回成功');
}else{
return $this->fail('驳回失败');
}
}
}
@ -361,8 +387,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 +419,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'])->where('type','<>',2)->order('id desc')->findOrEmpty();
if($vehicleContract['status'] == 3){
if(!empty($vehicleContract['cars_info'])){
$vehicleContract['cars_info'] = json_decode($vehicleContract['cars_info'],true);
@ -528,12 +548,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());
}
}