This commit is contained in:
unknown 2023-09-01 13:29:44 +08:00
parent 841d315113
commit e94bdcc7f7
2 changed files with 80 additions and 78 deletions

View File

@ -30,7 +30,7 @@ use think\response\Json;
*/
class IndexController extends BaseApiController
{
public array $notNeedLogin = ['index', 'config', 'policy', 'decorate', 'notifyUrl','notifyProperty','notifyAuthentication','notifyVehicleContractUpdate','systemCarRent','cancelContract'];
public array $notNeedLogin = ['index', 'config', 'policy', 'decorate', 'notifyUrl','notifyProperty','notifyAuthentication','notifyVehicleContractUpdate','systemCarRent','selfCarRent','cancelContract'];
private $domain = 'https://logistics.lihaink.cn';
// private $domain = 'http://www.lst.local';
@ -125,25 +125,25 @@ class IndexController extends BaseApiController
//获取参数
$id = $this->request->get('id');
if(empty($id)){
return json(['success' => false, 'msg' => '缺少参数']);
return json(['success' => false, 'msg' => '失败1.1']);
}
//获取合同数据
$contract = VehicleContract::where('id',$id)->find();
if(empty($contract)){
return json(['success' => false, 'msg' => '参数错误']);
return json(['success' => false, 'msg' => '失败1.2']);
}
if($contract['type'] != 0){
return json(['success' => false, 'msg' => '合同类型错误']);
return json(['success' => false, 'msg' => '失败1.3']);
}
if($contract['status'] != 2){
return json(['success' => false, 'msg' => '合同状态错误']);
return json(['success' => false, 'msg' => '失败1.4']);
}
//判断签约方
if ($contract['signing_timer'] == 0) {
//更新合同的签约次数
$res = VehicleContract::where('id',$id)->update(['signing_timer'=>1]);
if(!$res){
return json(['success' => false, 'msg' => '更新失败']);
return json(['success' => false, 'msg' => '失败1.5']);
}
return json(['success' => true, 'msg' => '成功']);
}else if($contract['signing_timer'] == 1) {
@ -156,7 +156,69 @@ class IndexController extends BaseApiController
'rent_time' => time(),
'rent_company_id' => $contract['company_b_id'],
]);
$car_id = $vehicle['id'];
//通知物流系统跟新
curl_post($this->domain.'/api/cancelRent',[],[
'car_id' => $vehicle['id'],
'status' => 1
]);
return json(['success' => true, 'msg' => '成功']);
}else{
return json(['success' => true, 'msg' => '成功']);
}
}
//自有车辆租赁回答
public function selfCarRent() {
//获取参数
$id = $this->request->get('id');
if(empty($id)){
return json(['success' => false, 'msg' => '失败2.1']);
}
//获取合同数据
$contract = VehicleContract::where('id',$id)->find();
if(empty($contract)){
return json(['success' => false, 'msg' => '失败2.2']);
}
if($contract['type'] != 1){
return json(['success' => false, 'msg' => '失败2.3']);
}
if($contract['status'] != 2){
return json(['success' => false, 'msg' => '失败2.4']);
}
//判断签约方
if ($contract['signing_timer'] == 0) {
$res = VehicleContract::where('id',$id)->update(['signing_timer'=>1]);
if(!$res){
return json(['success' => false, 'msg' => '失败2.5']);
}
return json(['success' => true, 'msg' => '成功']);
}else if($contract['signing_timer'] == 1) {
//添加车辆到物流系统
$vehicle = json_decode($contract['cars_info'],true);
$curl_res = curl_post($this->domain.'/api/addSelfCar',[],[
'license'=>$vehicle['license'],
'company_id' => $contract['company_a_id'],
'company_name' => $contract['company_a_name'],
'company_user' => $contract['company_a_user'],
'company_phone' => $contract['company_a_phone'],
]);
if(!$curl_res || $curl_res['code'] == 0){
return json(['success' => false, 'msg' => '失败2.6']);
}
$cars_info = json_encode(['id'=>$curl_res['data']['car_id'],'license'=>$vehicle['license']]);
VehicleContract::where('id',$id)->update(['cars_info'=>$cars_info,'update_time'=>time(),'signing_timer'=>2,'status'=>3]);
VehicleRent::create([
'car_id' => $curl_res['data']['car_id'],
'contract_id' => $contract['id'],
'company_id' => $contract['company_a_id'],
'car_license' => $vehicle['license'],
'status' => 2,
'rent_time' => time(),
'rent_company_id' => $contract['company_b_id'],
'create_time' => time(),
'type' => 1
]);
$car_id = $curl_res['data']['car_id'];
$party_b = Company::where('id',$contract['company_b_id'])->find();
//通知物流系统跟新
curl_post($this->domain.'/api/updateVehicleRent',[],[
@ -176,100 +238,38 @@ class IndexController extends BaseApiController
}
}
//解除合同回调
public function cancelContract() {
//获取参数
$id = $this->request->get('id');
if(empty($id)){
return json(['success' => false, 'msg' => '缺少参数']);
return json(['success' => false, 'msg' => '失败3.1']);
}
//获取合同数据
$contract = VehicleContract::where('id',$id)->find();
if(empty($contract)){
return json(['success' => false, 'msg' => '参数错误']);
return json(['success' => false, 'msg' => '失败3.2']);
}
if($contract['type'] != 2){
return json(['success' => false, 'msg' => '合同状态错误']);
return json(['success' => false, 'msg' => '失败3.3']);
}
if($contract['status'] != 2){
return json(['success' => false, 'msg' => '合同状态错误']);
return json(['success' => false, 'msg' => '失败3.4']);
}
}
public function notifyVillageCarRent(){
//获取参数
$id = $this->request->get('id');
if(empty($id)){
return json(['success' => false, 'msg' => '缺少参数']);
}
//获取合同数据
$contract = VehicleContract::where('id',$id)->find();
if(empty($contract)){
return json(['success' => false, 'msg' => '参数错误']);
}
if($contract['status'] != 2){
return json(['success' => false, 'msg' => '合同状态错误']);
}
if ($contract['signing_timer'] == 0) {
if($contract['signing_timer'] == 0){
$res = VehicleContract::where('id',$id)->update(['signing_timer'=>1]);
if(!$res){
return json(['success' => false, 'msg' => '更新失败']);
return json(['success' => false, 'msg' => '失败3.5']);
}
return json(['success' => true, 'msg' => '成功']);
}else if($contract['signing_timer'] == 1) {
//更改合同状态
VehicleContract::where('id',$id)->update(['signing_timer'=>2,'status'=>3]);
//添加车辆到物流系统
//更改租赁列表车辆状态
$vehicle = json_decode($contract['cars_info'],true);
//判断是否是自有车辆
if($contract['type'] == 1){
$curl_res = curl_post($this->domain.'/api/addSelfCar',[],[
'license'=>$vehicle['license'],
'company_id' => $contract['company_a_id'],
'company_name' => $contract['company_a_name'],
'company_user' => $contract['company_a_user'],
'company_phone' => $contract['company_a_phone'],
]);
$cars_info = json_encode(['id'=>$curl_res['data']['car_id'],'license'=>$vehicle['license']]);
VehicleContract::where('id',$id)->update(['cars_info'=>$cars_info,'update_time'=>time()]);
VehicleRent::create([
'car_id' => $curl_res['data']['car_id'],
'contract_id' => $contract['id'],
'company_id' => $contract['company_a_id'],
'car_license' => $vehicle['license'],
'status' => 2,
'rent_time' => time(),
'rent_company_id' => $contract['company_b_id'],
'create_time' => time(),
'type' => 1
]);
$car_id = $curl_res['data']['car_id'];
}else if($contract['type'] == 0){
//添加车辆到租赁列表
VehicleRent::where('car_id',$vehicle['id'])->update([
'status' => 2,
'rent_time' => time(),
'rent_company_id' => $contract['company_b_id'],
'status' => 3,
]);
$car_id = $vehicle['id'];
}
$party_b = Company::where('id',$contract['company_b_id'])->find();
//通知物流系统跟新
curl_post($this->domain.'/api/updateVehicleRent',[],[
'car_id' => $car_id,
'use_user_id' => $party_b['user_id'],
'use_user_name' => $party_b['master_name'],
'use_user_phone' => $party_b['master_phone']
]);
CompanyProperty::create([
'company_id' => $contract['company_b_id'],
'object_id' => $car_id,
'type' => 1
]);
return json(['success' => true, 'msg' => '成功']);
}else{
return json(['success' => true, 'msg' => '成功']);
}

View File

@ -426,6 +426,8 @@ class VehicleController extends BaseApiController
$position = curl_post($this->url.'/api/getCarLocal',[],['car_id'=>$carId]);
if($position && $position['code'] == 1){
$data['position'] = $position['data'];
}else{
$data['position'] = [];
}
return $this->success('请求成功',$data->toArray());
}