增加车辆签约接口

This commit is contained in:
unknown 2023-08-29 17:23:36 +08:00
parent 14e88d5b9b
commit 5a69af3f00
5 changed files with 114 additions and 262 deletions

View File

@ -0,0 +1,63 @@
<?php
namespace app\adminapi\controller\contract;
use app\adminapi\controller\BaseAdminController;
use app\common\enum\notice\NoticeEnum;
use app\common\model\contract\VehicleContract;
class VehicleContractController extends BaseAdminController
{
public array $notNeedLogin = ['uploadContract'];
// private string $url = 'http://www.lst.local';
private string $url = 'http://logistics.lihaink.cn';
public function uploadContract() {
//获取参数
$params = $this->request->post(['id','file']);
if(empty($params['id']) || empty($params['file'])){
return $this->fail('参数错误');
}
//更新本地和物流系统
$la_result = VehicleContract::where('id', $params['id'])->update(['file' => $params['file'],'status'=>2]);
$lst_result = curl_post($this->url.'/api/updateContract',[],[
'id' => $params['id'],
'file' => $params['file'],
'status' => 2
]);
if($la_result && $lst_result && $lst_result['code'] == 1){
//获取合同数据
$contract = VehicleContract::field('')->where('id',$params['id'])->find();
//发送短信
$sms = [
'mobile' => $contract['company_a_phone'],
'name' => $contract['company_a_name'],
'scene' => 'WQTZ'
];
$this->rentNoticeSms($sms);
return $this->success('上传成功', [], 1, 1);
} else {
if($la_result==0 || !$lst_result){
return $this->success('没有更新', [], 1, 1);
}
return $this->fail('上传失败');
}
}
public function rentNoticeSms($params) {
try {
$scene = NoticeEnum::getSceneByTag($params['scene']);
if (empty($scene)) {
throw new \Exception('场景值异常');
}
$result = event('Notice', [
'scene_id' => $scene,
'params' => $params
]);
return $result[0];
} catch (\Exception $e) {
return false;
}
}
}

View File

@ -18,6 +18,7 @@ namespace app\api\controller;
use app\api\logic\IndexLogic;
use app\common\model\Company;
use app\common\model\company\CompanyProperty;
use app\common\model\contract\VehicleContract;
use think\facade\Db;
use think\facade\Log;
use think\response\Json;
@ -32,7 +33,7 @@ class IndexController extends BaseApiController
{
public array $notNeedLogin = ['index', 'config', 'policy', 'decorate', 'notifyUrl','notifyProperty','notifyAuthentication'];
public array $notNeedLogin = ['index', 'config', 'policy', 'decorate', 'notifyUrl','notifyProperty','notifyAuthentication','notifyVehicleContractUpdate'];
@ -116,45 +117,26 @@ class IndexController extends BaseApiController
Db::name('user')->where('id', $find['party_b'])->update(['is_contract' => 1]);
}
}
try {
//获取租赁信息
$vehicleRent = Db::name('vehicle_rent')->where('contract_id',$a['id'])->find();
//获取公司信息
$company = Db::name('company')->where('id',$vehicleRent['party_b'])->find();
//通知物流系统
if($vehicleRent && $company){
$result = curl_post('http://logistics.lihaink.cn/api/vehicleRent', [], [
'contract_id' => $a['id'],
'car_id' => $vehicleRent['car_ids'],
'company_id' => $company['id'],
'company_name' => $company['company_name'],
'company_user_id' => $company['user_id'],
'company_user_name' => $company['master_name'],
'company_user_phone' => $company['master_phone'],
'rent_type' => $vehicleRent['rent_type']
]);
if($result['code'] == 1){
$carids = explode(',',$vehicleRent['car_ids']);
$pro_data = [];
foreach($carids as $k => $v){
$pro_data[$k]['company_id']=$company['id'];
$pro_data[$k]['object_id']=$v;
$pro_data[$k]['type']=1;
$pro_data[$k]['create_time']=time();
}
Db::name('company_property')->insertAll($pro_data);
Db::name('vehicle_rent')->update(['status'=>2,'update_time'=>time(),'id'=>$vehicleRent['id']]);
}
}
}catch (\Exception $e){
return false;
}
}
}
return json(['success' => true, 'msg' => '成功']);
}
//车辆租赁签约合同状态更改
public function notifyVehicleContractUpdate(){
$param = $this->request->post();
if(empty($param['id'])){
return $this->fail('缺少参数');
}
$model = VehicleContract::where('id',$param['id'])->find();
if(!$model || $model->isEmpty()){
return $this->fail('数据不存在');
}
$result = $model->save($param);
//返回
return $result ? $this->success('更新成功') : $this->fail('更新失败');
}
/**
* 资产回调
*/

View File

@ -3,7 +3,6 @@
namespace app\api\controller;
use app\common\logic\vehicle\VehicleLogic;
use app\common\model\Company;
use think\response\Json;
class VehicleController extends BaseApiController
@ -11,140 +10,23 @@ class VehicleController extends BaseApiController
public function setContractByTownCompany():Json
{
//获取参数
$params = $this->request->post(['party_a','num','car_ids']);
$params = $this->request->post(['num']);
//验证参数
if(empty($params['party_a']) || empty($params['num']) || empty($params['car_ids'])){
if(empty($params['num'])){
return $this->fail('缺少必要参数');
}
if(empty($this->userInfo['company_id'])){
return $this->fail('签约公司不存在');
}
$params['party_b'] = $this->userInfo['company_id'];
if($params['party_b'] == $params['party_a']){
return $this->fail('甲方和乙方不能是同一个公司');
}
$params['rent_type'] = 1;//镇街公司批量租赁
$result = VehicleLogic::initiate_contract($params);
//返回数据
if($result['code'] == 1){
return $this->success($result['msg'],$result['data']);
}else{
return $this->fail($result['msg']);
}
}
public function setContractByVillageCompany():Json
{
//获取参数
$params = $this->request->post(['party_b','car_ids']);
//验证参数
if(empty($params['party_b']) || empty($params['car_ids'])){
return $this->fail('缺少必要参数');
}
if(empty($this->userInfo['company_id'])){
return $this->fail('签约公司不存在');
}
$params['party_a'] = $this->userInfo['company_id'];
if($params['party_b'] == $params['party_a']){
return $this->fail('甲方和乙方不能是同一个公司');
}
$params['rent_type'] = 2;//小组服务公司单辆租赁
$params['num'] = 1;
$result = VehicleLogic::initiate_contract($params);
//返回数据
if($result['code'] == 1){
return $this->success($result['msg'],$result['data']);
}else{
return $this->fail($result['msg']);
}
}
public function townCompanyCarList():Json {
//获取参数
$params = $this->request->get(['is_rent','license','company_name','page_no','page_size']);
if(empty($params['is_rent'])){
return $this->fail('缺少必要参数');
}
if(!in_array($params['is_rent'],[1,2])){
return $this->fail('参数错误');
}
//获取公司id
$params['company_id'] = $this->userInfo['company_id'];
//获取车辆
$result = VehicleLogic::townCompanyCarList($params);
//返回数据
if($result['code'] == 1){
return $this->success($result['msg'],$result['data']);
}else{
return $this->fail($result['msg']);
}
}
public function villageCompanyCar():Json {
//获取公司id
$company_id = $this->userInfo['company_id'];
if(empty($company_id)){
return $this->fail('数据错误');
}
$result = VehicleLogic::villageCompanyCar($company_id);
//返回数据
if($result['code'] == 1){
return $this->success($result['msg'],$result['data']);
}else{
return $this->fail($result['msg']);
}
}
public function addCar():Json {
//获取参数
$params = $this->request->post(['license']);
//验证参数
if(empty($params['license'])){
return $this->fail('缺啥破必要参数');
}
//获取公司id
$params['company_id'] = $this->userInfo['company_id'];
$result = VehicleLogic::addCar($params);
//返回数据
if($result['code'] == 1){
if($result && $result['code'] == 1){
return $this->success($result['msg']);
}else{
return $this->fail($result['msg']);
}
}
public function getCarInfo():Json {
//获取参数
$params = $this->request->get(['car_id','car_type']);
if(empty($params['car_id']) || empty($params['car_type'])){
return $this->fail('缺少必要参数');
}
if(!in_array($params['car_type'],[1,2])){
return $this->fail('车辆类型错误');
}
//获取车辆详情
$result = curl_post('http://logistics.lihaink.cn/api/carInfo',[],$params);
//返回数据
if($result && $result['code'] == 1){
if($result['data']['type'] == 1 && $result['data']['lessee_two_flag'] == 1){
$lessee_two_company = Company::where('id','lessee_two_company_id')->find();
$result['data']['lessee_two_company_address'] = $lessee_two_company['address'];
}
return $this->success($result['msg'],$result['data']);
}else{
return $this->fail($result['msg']);
}
}
public function checkNum():Json {
//获取参数
$num = $this->request->get('num');
$result = curl_post('http://logistics.lihaink.cn/api/checkNum',[],['num'=>$num]);
//返回数据
if($result && $result['code'] == 1){
return $this->success($result['msg'],$result['data']);
}else{
return $this->fail($result['msg']);
}
}
}

View File

@ -5,119 +5,34 @@ namespace app\common\logic\vehicle;
use app\common\logic\BaseLogic;
use app\common\model\Company;
use app\common\model\contract\Contract;
use app\common\model\contract\VehicleContract;
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'=>'参数错误'];
// public static string $url = 'http://logistics.lihaink.cn';
public static string $url = 'http://www.lst.local';
public static function initiate_contract($data):array|bool {
//查找乙方公司信息
$party_b = Company::field('id,company_name,organization_code,master_name,master_phone,master_email,company_type')->where('id',$data['party_b'])->find();
//镇街公司
if(!$party_b || $party_b->isEmpty() || $party_b['company_type'] != 16){
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);
//生成合同
$result = curl_post(self::$url.'/api/signContract',[],[
'num' => $data['num'],
'company_id' => $party_b['id'],
'company_name' => $party_b['company_name'],
'company_code' => $party_b['organization_code'],
'company_user' => $party_b['master_name'],
'company_phone' => $party_b['master_phone'],
'company_email' => $party_b['master_email'],
]);
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 villageCompanyCar($company_id):array {
$result = curl_post(self::$url.'/api/companyCar',[],['company_id'=>$company_id]);
//返回数据
if($result && $result['code'] == 1){
if($result['data']['type'] == 1 && $result['data']['lessee_two_flag'] == 1){
$lessee_two_company = Company::where('id','lessee_two_company_id')->find();
$result['data']['lessee_two_company_address'] = $lessee_two_company['address'];
}
if($result['data']['type'] == 2){
$lessee_two_company = Company::where('id',$result['data']['company_id'])->find();
$result['data']['lessee_two_company_address'] = $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']];
VehicleContract::create($result['data']);
}
return $result ?? false;
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace app\common\model\contract;
use app\common\model\BaseModel;
class VehicleContract extends BaseModel
{
}