This commit is contained in:
yaooo 2023-10-12 15:21:32 +08:00
commit e670138ea7
3 changed files with 71 additions and 28 deletions

View File

@ -30,38 +30,30 @@ class VehicleContractController extends BaseAdminController
return $this->fail('参数cars无效');
}
}
if($vehicle_contract['type'] == 3){
$params['cars'] = $vehicle_contract['cars_info'];
}
if($vehicle_contract['status'] != 0){
return $this->fail('合同状态错误');
}
//更新本地
try {
$data = [
'id' => $vehicle_contract['contract_logistic_id'],
'file' => $params['file'],
'status' => 1,
];
//判断合同类型
if($vehicle_contract['type'] == 0){
$data['cars_info'] = $params['cars'];
}
if(!empty($vehicle_contract['contract_logistic_id'])){
//更新物流系统
curl_post(env('project.logistic_domain').'/api/contractUpdate',[],[
'id' => $vehicle_contract['contract_logistic_id'],
'file' => $params['file'],
'status' => 1,
'cars_info' => $params['cars']
]);
VehicleContract::where('id', $params['id'])->update(['file' => $params['file'],'cars_info' => $params['cars'],'status'=>1]);
}else{
VehicleContract::where('id', $params['id'])->update(['file' => $params['file'],'status'=>1]);
curl_post(env('project.logistic_domain').'/api/contractUpdate',[],$data);
}
unset($data['id']);
VehicleContract::where('id', $params['id'])->update($data);
}catch (\Exception $e){
return $this->fail($e->getMessage());
}
//发送短信
$sms = [
'mobile' => $vehicle_contract['company_a_phone'],
'name' => $vehicle_contract['company_user'],
'scene' => 'WQTZ'
];
$this->rentNoticeSms($sms);
return $this->success('上传成功', [], 1, 1);
}

View File

@ -6,6 +6,7 @@ use app\common\enum\notice\NoticeEnum;
use app\common\model\Company;
use app\common\model\contract\Contract;
use app\common\model\contract\VehicleContract;
use app\common\model\vehicle\VehicleBuyRecord;
use app\common\model\vehicle\VehicleRent;
use think\facade\Db;
@ -656,7 +657,7 @@ class VehicleController extends BaseApiController
$zjRentCars = VehicleRent::field('car_id')->where('company_id',$zjCompany['party_a'])->where('status',0)->select()->toArray();
$zjRentCars = array_column($zjRentCars,'car_id');
//4、获取小组公司自己租赁的车辆
$xzRentCars = VehicleRent::field('car_id')->where('company_id',$zjCompany['party_a'])->where('rent_company_id',$xzCompany['id'])->where('status',2)->select()->toArray();
$xzRentCars = VehicleRent::field('car_id')->where('company_id',$zjCompany['party_a'])->where('rent_company_id',$xzCompany['id'])->where('status',2)->where('type','<>',2)->select()->toArray();
$xzRentCars = array_column($xzRentCars,'car_id');
//5、获取平台未出租的车辆
$result = curl_post(env('project.logistic_domain').'/api/Vehicle/getFreeCars',[],['ids'=>implode(',',array_merge($zjRentCars,$xzRentCars))]);
@ -683,14 +684,17 @@ class VehicleController extends BaseApiController
}
//获取镇街公司信息
$zjCompany = Contract::field('party_a')->where('party_b',$this->userInfo['company_id'])->where('signing_timer',2)->findOrEmpty();
if($zjCompany->isEmpty()){
return $this->fail('签约镇街公司不存在');
}
//判断购买车辆中是否包含镇街公司租赁的车辆
$car_ids = array_column($cars,'id');
$zjRentCars = VehicleRent::field('car_id,car_license')->where('company_id',$zjCompany['party_a'])->where('car_id','in',$car_ids)->select();
$zjRentCars = VehicleRent::field('car_id as id,car_license as license')->where('company_id',$zjCompany['party_a'])->where('car_id','in',$car_ids)->where('status',0)->where('type',0)->select();
//判断小组服务公司是否租车或者有自有车辆
$xzRentCars = VehicleRent::where('rent_company_id',$xzCompany['id'])->where('status','in','1,2')->findOrEmpty();
$xzRentCars = VehicleRent::where('rent_company_id',$xzCompany['id'])->where('status','in','1,2')->where('type','<>',2)->findOrEmpty();
//如果没有租赁车俩和上传自有车辆,也没有购买镇街公司租赁的车辆 则直接发起购买合同
if($xzRentCars->isEmpty() && $zjRentCars->isEmpty()){
//发送生成合同给物流系统
//发送购买合同给物流系统
$curl_result = curl_post(env('project.logistic_domain').'/api/signContract',[],[
'num' => count($cars),
'company_id' => $xzCompany['id'],
@ -710,11 +714,48 @@ class VehicleController extends BaseApiController
}
//生成本地合同
VehicleContract::create($curl_result['data']);
return $this->success('合同发起成功,等待审核 from task'
);
return $this->success('合同发起成功,等待审核 from task');
}
//如果没有租赁车俩和上传自有车辆,但有购买镇街公司租赁的车辆 则发起镇街公司与平台公司的解约合同
if($xzRentCars->isEmpty() && !$zjRentCars->isEmpty()){
$zjCompanyInfo = Company::field('id,company_name,master_name,master_phone,master_email,organization_code')->where('id',$zjCompany['party_a'])->findOrEmpty();
//发送解约合同给物流系统
$curl_result = curl_post(env('project.logistic_domain').'/api/signContract',[],[
'num' => count($zjRentCars),
'company_id' => $zjCompanyInfo['id'],
'company_name' => $zjCompanyInfo['company_name'],
'company_code' => $zjCompanyInfo['organization_code'],
'company_user' => $zjCompanyInfo['master_name'],
'company_phone' => $zjCompanyInfo['master_phone'],
'company_email' => $zjCompanyInfo['master_email'],
'cars_info' => json_encode($zjRentCars),
'type' => 2
]);
if(empty($curl_result)){
return $this->fail('null return from logistic');
}
if($curl_result['code'] == 0){
return $this->fail($curl_result['msg'].' from logistic');
}
//生成本地合同
$res = VehicleContract::create($curl_result['data']);
//生成关联记录
VehicleBuyRecord::create([
'company_id' => $zjCompanyInfo['id'],
'company_name' => $zjCompanyInfo['company_name'],
'company_code' => $zjCompanyInfo['organization_code'],
'company_user' => $zjCompanyInfo['master_name'],
'company_phone' => $zjCompanyInfo['master_phone'],
'company_email' => $zjCompanyInfo['master_email'],
'cars_info' => json_encode($cars),
'num' => count($cars),
'status' => 2,
'contract_id' => $res->id,
'create_time' => time()
]);
//更改本地车辆状态
VehicleRent::where('car_id','in',$car_ids)->update(['status'=>1]);
return $this->success('合同发起成功,等待审核 from task');
}
//2、判断当前小组服务公司是否租赁车辆如果已经租赁车辆则发起与镇街公司解除租赁关系的合同申请 =》如果解除合同签约成功将当前车辆状态重置为未出租,然后进行第三步
//3、如果当前小组服务公司没有租赁车辆则判断购买的车辆中是否有镇街公司租赁的车辆如果有则发起镇街公司与平台公司的解除合同 =》 当解除合同签约成功,
//4、如果当前小组服务公司没有租赁车辆且购买的车辆中不包含镇街公司租赁的车辆则直接发起与平台公司的购车合同
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace app\common\model\vehicle;
use app\common\model\BaseModel;
class VehicleBuyRecord extends BaseModel
{
protected $name = 'vehicle_buy_record';
}