新增租赁合同签订接口
This commit is contained in:
parent
28a7008376
commit
cd7bf5c06c
@ -11,7 +11,39 @@ use think\response\Json;
|
|||||||
*/
|
*/
|
||||||
class VehicleController extends BaseApiController
|
class VehicleController extends BaseApiController
|
||||||
{
|
{
|
||||||
public array $notNeedLogin = ['tricycle','multipleRent','singleRent'];
|
public array $notNeedLogin = ['getCompany','setContract','tricycle','multipleRent','singleRent'];
|
||||||
|
|
||||||
|
/*
|
||||||
|
*获取平台公司接口
|
||||||
|
*/
|
||||||
|
public function getCompany():Json {
|
||||||
|
$result = VehicleLogic::company();
|
||||||
|
if($result['code'] == 1){
|
||||||
|
return $this->success($result['msg'],$result['data']);
|
||||||
|
}else{
|
||||||
|
return $this->fail($result['msg']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setContract() {
|
||||||
|
$params = $this->request->post(['party_a','party_b','num','start_time','end_time']);
|
||||||
|
//验证参数
|
||||||
|
if(empty($params['party_a']) || empty($params['party_b']) || empty($params['num']) || empty($params['start_time']) || empty($params['end_time'])){
|
||||||
|
return $this->fail('缺少必要的参数');
|
||||||
|
}
|
||||||
|
//验证时间格式
|
||||||
|
if(!checkDateIsValid($params['start_time']) || !checkDateIsValid($params['end_time'])){
|
||||||
|
return $this->fail('时间格式错误');
|
||||||
|
}
|
||||||
|
//生成数据
|
||||||
|
$result = VehicleLogic::rentRecord($params);
|
||||||
|
//返回数据
|
||||||
|
if($result['code'] == 1){
|
||||||
|
return $this->success($result['msg']);
|
||||||
|
}else{
|
||||||
|
return $this->fail($result['msg']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 获取去未出租的三轮车列表
|
* 获取去未出租的三轮车列表
|
||||||
|
@ -19,6 +19,7 @@ use app\common\logic\BaseLogic;
|
|||||||
use app\common\model\vehicle\Company;
|
use app\common\model\vehicle\Company;
|
||||||
use app\common\model\vehicle\Vehicle;
|
use app\common\model\vehicle\Vehicle;
|
||||||
use app\common\model\vehicle\VehicleRent;
|
use app\common\model\vehicle\VehicleRent;
|
||||||
|
use app\common\model\vehicle\VehicleRentRecord;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,4 +127,60 @@ class VehicleLogic extends BaseLogic
|
|||||||
return ['code'=>0,'msg'=>$e->getMessage()];
|
return ['code'=>0,'msg'=>$e->getMessage()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function company() {
|
||||||
|
$data = Company::field('id,company_name')->where('company_name',30)->select();
|
||||||
|
if($data){
|
||||||
|
return ['code'=>1,'msg'=>'请求成功','data'=>$data->toArray()];
|
||||||
|
}else{
|
||||||
|
return ['code'=>0,'msg'=>'请求失败'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function rentRecord($params):array {
|
||||||
|
//获取数据
|
||||||
|
$cars = Vehicle::field('id')->where('status',0)->where('type',0)->limit($params['num'])->select();
|
||||||
|
if(!$cars || $cars->count() < $params['num']){
|
||||||
|
return ['code'=>0,'msg'=>'车辆数量不足'];
|
||||||
|
}
|
||||||
|
$ids = array_column($cars->toArray(),'id');
|
||||||
|
$ids = implode(',',$ids);
|
||||||
|
//发起合同
|
||||||
|
VehicleRentRecord::startTrans();
|
||||||
|
try {
|
||||||
|
//获取token https://worker-task.lihaink.cn
|
||||||
|
$getToken = curl_post('https://worker-task.lihaink.cn/adminapi/login/account',[],['account'=>'admin','password'=>'123456','terminal'=>1]);
|
||||||
|
if($getToken['code'] == 0){
|
||||||
|
return ['code'=>0,'msg'=>'获取token失败'];
|
||||||
|
}
|
||||||
|
//发起合同
|
||||||
|
$setContract = curl_post('https://worker-task.lihaink.cn/adminapi/company/initiate_contract',[
|
||||||
|
'token:'.$getToken['data']['token']
|
||||||
|
],[
|
||||||
|
'id' => $params['party_b'],
|
||||||
|
'party_a' => $params['party_a'],
|
||||||
|
'contract_type' => 29
|
||||||
|
]);
|
||||||
|
if($setContract['code'] == 0){
|
||||||
|
return ['code'=>0,'msg'=>$setContract['msg']];
|
||||||
|
}
|
||||||
|
//写入数据
|
||||||
|
$res = VehicleRentRecord::create([
|
||||||
|
'car_ids' => $ids,
|
||||||
|
'contract_id' => $setContract['data']['id'],
|
||||||
|
'party_a' => $params['party_a'],
|
||||||
|
'party_b' => $params['party_b'],
|
||||||
|
'start_time' => $params['start_time'],
|
||||||
|
'end_time' => $params['end_time'],
|
||||||
|
'status' => 1,
|
||||||
|
'create_time' => time(),
|
||||||
|
'update_time' => time(),
|
||||||
|
]);
|
||||||
|
VehicleRentRecord::commit();
|
||||||
|
return ['code'=>1,'msg'=>'发起成功,等待平台风控部上传合同'];
|
||||||
|
}catch(\Exception $e) {
|
||||||
|
VehicleRentRecord::rollback();
|
||||||
|
return ['code'=>0,'msg'=>$e->getMessage()];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ Route::rule('getCarHistory','Gps/getCarHistory','get');
|
|||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------------------*/
|
||||||
Route::rule('tricycle','Vehicle/tricycle','get');
|
Route::rule('getCompany','Vehicle/getCompany','get');
|
||||||
|
Route::rule('setContract','Vehicle/setContract','post');
|
||||||
Route::rule('multipleRent','Vehicle/multipleRent','post');
|
Route::rule('multipleRent','Vehicle/multipleRent','post');
|
||||||
Route::rule('singleRent','Vehicle/singleRent','post');
|
Route::rule('singleRent','Vehicle/singleRent','post');
|
@ -307,7 +307,6 @@ function curl_post($url,$headers,$data) {
|
|||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
//设置头文件的信息作为数据流输出
|
//设置头文件的信息作为数据流输出
|
||||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
||||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
|
||||||
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
|
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||||
@ -315,6 +314,8 @@ function curl_post($url,$headers,$data) {
|
|||||||
curl_setopt($ch, CURLOPT_POST, 1);
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
//添加参数
|
//添加参数
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||||
|
//设置header
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
//关闭请求资源
|
//关闭请求资源
|
||||||
$output = curl_exec($ch);
|
$output = curl_exec($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
32
app/common/model/vehicle/VehicleRentRecord.php
Normal file
32
app/common/model/vehicle/VehicleRentRecord.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model\vehicle;
|
||||||
|
|
||||||
|
use app\common\model\BaseModel;
|
||||||
|
|
||||||
|
class VehicleRentRecord extends BaseModel
|
||||||
|
{
|
||||||
|
public function getStartTimeAttr($value): string
|
||||||
|
{
|
||||||
|
if(empty($value)){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return date('Y-m-d',$value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEndTimeAttr($value): string
|
||||||
|
{
|
||||||
|
if(empty($value)){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return date('Y-m-d',$value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCreateTimeAttr($value): string
|
||||||
|
{
|
||||||
|
if(empty($value)){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return date('Y-m-d',$value);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user