105 lines
4.1 KiB
PHP
105 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace app\common\logic\vehicle;
|
|
|
|
use app\common\logic\BaseLogic;
|
|
use app\common\model\Company;
|
|
use app\common\model\contract\Contract;
|
|
use Exception;
|
|
use think\facade\Db;
|
|
|
|
class VehicleLogic extends BaseLogic
|
|
{
|
|
public static string $url = 'http://logistics.lihaink.cn';
|
|
// public static string $url = 'http://www.lst.local';
|
|
public static function initiate_contract($data):array {
|
|
$party_b = Company::field('company_type')->where('id',$data['party_b'])->find();
|
|
if($data['rent_type'] == 1){
|
|
//镇街公司
|
|
if($party_b['company_type'] != 16){
|
|
return ['code'=>0,'msg'=>'非镇街公司不能签约'];
|
|
}
|
|
}elseif($data['rent_type'] == 2){
|
|
//小组服务公司
|
|
if($party_b['company_type'] != 18){
|
|
return ['code'=>0,'msg'=>'非小组服务公司不能签约'];
|
|
}
|
|
//判断小组服务公司是否添加了自有车辆
|
|
$selfCar = curl_post(self::$url.'/api/getSelfCar',[],['company_id'=>$data['party_b']]);
|
|
if($selfCar && $selfCar['data']['has_car']){
|
|
return ['code'=>0,'msg'=>'已上传自有车辆不能签约'];
|
|
}
|
|
}else{
|
|
return ['code'=>0,'msg'=>'参数错误'];
|
|
}
|
|
Db::startTrans();
|
|
try {
|
|
$contract = Contract::create([
|
|
'admin_id' => 0,
|
|
'company_id' =>0,
|
|
'contract_type' => 29,
|
|
'file' => '',
|
|
'contract_no' => time(),
|
|
'create_time' => time(),
|
|
'update_time' => time(),
|
|
'check_status' => 1,
|
|
'party_a' => $data['party_a'],
|
|
'party_b' => $data['party_b'],
|
|
'area_manager' => 0,
|
|
'type' => 1,
|
|
]);
|
|
$vehicleRent = Db::name('vehicle_rent')->insert([
|
|
'car_ids' => $data['car_ids'],
|
|
'contract_id' => $contract->id,
|
|
'party_a' => $data['party_a'],
|
|
'party_b' => $data['party_b'],
|
|
'num' => $data['num'],
|
|
'rent_type' => $data['rent_type'],
|
|
'status' => 1,
|
|
'create_time' => time(),
|
|
'update_time' => time(),
|
|
]);
|
|
if($contract->id && $vehicleRent) {
|
|
Db::commit();
|
|
return ['code'=>1,'msg'=>'发起成功,等待平台风控部上传合同','data'=>['id'=>$contract->id]];
|
|
}else{
|
|
Db::rollback();
|
|
return ['code'=>0,'msg'=>'发起失败,请稍后重试'];
|
|
}
|
|
}catch (Exception $e) {
|
|
Db::rollback();
|
|
return ['code'=>0,'msg'=>$e->getMessage()];
|
|
}
|
|
}
|
|
|
|
public static function townCompanyCarList($params):array {
|
|
//请求物流系统获取车辆详情
|
|
$result = curl_post(self::$url.'/api/companyCarList',[],$params);
|
|
if($result && $result['code'] == 1){
|
|
foreach ($result['data'] as $k=>$v){
|
|
if($v['lessee_two_flag'] == 1){
|
|
$lessee_two_company = Company::where('id','lessee_two_company_id')->find();
|
|
$result['data'][$k]['lessee_two_company_address'] = $lessee_two_company['address'];
|
|
}else{
|
|
$result['data'][$k]['lessee_two_company_address'] = '';
|
|
}
|
|
}
|
|
return ['code'=>1,'msg'=>'请求成功','data'=>$result['data']];
|
|
}else{
|
|
return ['code'=>0,'msg'=>'请求失败'];
|
|
}
|
|
}
|
|
|
|
public static function addCar($params):array {
|
|
$company = Company::field('company_type')->where('id',$params['company_id'])->find();
|
|
if($company['company_type'] != 18){
|
|
return ['code'=>0,'msg'=>'非小组服务公司不能添加车辆'];
|
|
}
|
|
$result = curl_post(self::$url.'/api/addVehicle',[],$params);
|
|
if($result && $result['code'] == 1){
|
|
return ['code'=>1,'msg'=>$result['msg']];
|
|
}else{
|
|
return ['code'=>0,'msg'=>$result['msg']];
|
|
}
|
|
}
|
|
} |