Merge pull request '三轮车上传合同逻辑修改' (#70) from zhangwei into dev
Reviewed-on: #70
This commit is contained in:
commit
859b0c5532
@ -30,6 +30,9 @@ 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('合同状态错误');
|
||||
}
|
||||
|
@ -642,4 +642,79 @@ class VehicleController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
//获取空闲车辆列表
|
||||
public function getFreeCars(): \think\response\Json
|
||||
{
|
||||
//1、获取当前登录用户信息并判断其公司是否是小组服务公司
|
||||
$xzCompany = Company::field('id,company_type')->where('id',$this->userInfo['company_id'])->findOrEmpty();
|
||||
if($xzCompany->isEmpty() || $xzCompany['company_type'] != 18){
|
||||
return $this->fail('当前用户非小组服务公司');
|
||||
}
|
||||
//2、获取小组服务公司签约的镇街公司
|
||||
$zjCompany = Contract::field('party_a')->where('party_b',$this->userInfo['company_id'])->where('signing_timer',2)->findOrEmpty();
|
||||
//3、获取镇街公司向平台租赁的且未二次租赁给小组公司的车辆
|
||||
$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 = array_column($xzRentCars,'car_id');
|
||||
//5、获取平台未出租的车辆
|
||||
$result = curl_post(env('project.logistic_domain').'/api/Vehicle/getFreeCars',[],['ids'=>implode(',',array_merge($zjRentCars,$xzRentCars))]);
|
||||
//6、返回
|
||||
return $this->success('success',$result['data']);
|
||||
}
|
||||
|
||||
//申请购车
|
||||
public function buyCars() {
|
||||
//验证请求类型
|
||||
if(!$this->request->isPost()){
|
||||
return $this->fail('请求类型错误');
|
||||
}
|
||||
//1、获取购买车辆的id参数
|
||||
$cars = $this->request->post('cars');
|
||||
$cars = json_decode($cars,true);
|
||||
if(empty($cars)){
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
//获取小组服务公司信息
|
||||
$xzCompany = Company::field('id,company_name,master_name,master_phone,master_email,organization_code,company_type')->where('id',$this->userInfo['company_id'])->findOrEmpty();
|
||||
if($xzCompany->isEmpty() || $xzCompany['company_type'] != 18){
|
||||
return $this->fail('当前用户非小组服务公司');
|
||||
}
|
||||
//获取镇街公司信息
|
||||
$zjCompany = Contract::field('party_a')->where('party_b',$this->userInfo['company_id'])->where('signing_timer',2)->findOrEmpty();
|
||||
//判断购买车辆中是否包含镇街公司租赁的车辆
|
||||
$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();
|
||||
//判断小组服务公司是否租车或者有自有车辆
|
||||
$xzRentCars = VehicleRent::where('rent_company_id',$xzCompany['id'])->where('status','in','1,2')->findOrEmpty();
|
||||
//如果没有租赁车俩和上传自有车辆,也没有购买镇街公司租赁的车辆 则直接发起购买合同
|
||||
if($xzRentCars->isEmpty() && $zjRentCars->isEmpty()){
|
||||
//发送生成合同给物流系统
|
||||
$curl_result = curl_post(env('project.logistic_domain').'/api/signContract',[],[
|
||||
'num' => count($cars),
|
||||
'company_id' => $xzCompany['id'],
|
||||
'company_name' => $xzCompany['company_name'],
|
||||
'company_code' => $xzCompany['organization_code'],
|
||||
'company_user' => $xzCompany['master_name'],
|
||||
'company_phone' => $xzCompany['master_phone'],
|
||||
'company_email' => $xzCompany['master_email'],
|
||||
'cars_info' => json_encode($cars),
|
||||
'type' => 3
|
||||
]);
|
||||
if(empty($curl_result)){
|
||||
return $this->fail('null return from logistic');
|
||||
}
|
||||
if($curl_result['code'] == 0){
|
||||
return $this->fail($curl_result['msg'].' from logistic');
|
||||
}
|
||||
//生成本地合同
|
||||
VehicleContract::create($curl_result['data']);
|
||||
return $this->success('合同发起成功,等待审核 from task'
|
||||
);
|
||||
}
|
||||
//2、判断当前小组服务公司是否租赁车辆,如果已经租赁车辆,则发起与镇街公司解除租赁关系的合同申请 =》如果解除合同签约成功将当前车辆状态重置为未出租,然后进行第三步
|
||||
//3、如果当前小组服务公司没有租赁车辆,则判断购买的车辆中是否有镇街公司租赁的车辆,如果有,则发起镇街公司与平台公司的解除合同 =》 当解除合同签约成功,
|
||||
//4、如果当前小组服务公司没有租赁车辆且购买的车辆中不包含镇街公司租赁的车辆,则直接发起与平台公司的购车合同
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user