2023-08-25 13:58:06 +08:00
< ? php
namespace app\api\controller ;
2023-08-30 15:49:41 +08:00
use app\common\enum\notice\NoticeEnum ;
2023-08-30 13:37:20 +08:00
use app\common\model\Company ;
2023-09-01 15:30:19 +08:00
use app\common\model\contract\Contract ;
2023-08-30 13:37:20 +08:00
use app\common\model\contract\VehicleContract ;
use app\common\model\vehicle\VehicleRent ;
use think\facade\Db ;
2023-08-25 13:58:06 +08:00
class VehicleController extends BaseApiController
{
2023-08-30 13:37:20 +08:00
//镇街公司想物流平台申请租赁车辆
2023-08-30 18:18:42 +08:00
public function setContractByTownCompany ()
2023-08-25 13:58:06 +08:00
{
//获取参数
2023-08-29 17:23:36 +08:00
$params = $this -> request -> post ([ 'num' ]);
2023-08-25 13:58:06 +08:00
//验证参数
2023-08-29 17:23:36 +08:00
if ( empty ( $params [ 'num' ])){
2023-08-25 13:58:06 +08:00
return $this -> fail ( '缺少必要参数' );
}
2023-08-31 19:20:20 +08:00
//获取该公司已签约的小组服务公司数量
2023-09-01 15:30:19 +08:00
$villageCompany = Contract :: field ( 'id' ) -> where ( 'party_a' , $this -> userInfo [ 'company_id' ]) -> where ( 'signing_timer' , 2 ) -> count ();
2023-09-08 16:47:30 +08:00
//已经租赁车辆
$rentCar = VehicleRent :: field ( 'id' ) -> where ( 'company_id' , $this -> userInfo [ 'company_id' ]) -> where ( 'type' , '<>' , 1 ) -> count ();
2023-08-31 19:20:20 +08:00
//申请中的车辆
$applyCar = VehicleContract :: field ( 'num' ) -> where ( 'company_b_id' , $this -> userInfo [ 'company_id' ]) -> where ( 'status' , 'in' , '-1,0,1,2' ) -> sum ( 'num' );
//自有车辆数量
2023-09-01 13:57:54 +08:00
$selfCar = VehicleRent :: field ( 'id' ) -> where ( 'company_id' , $this -> userInfo [ 'company_id' ]) -> where ( 'status' , '<>' , 3 ) -> where ( 'type' , 1 ) -> count ();
2023-08-31 19:20:20 +08:00
//可在租车辆
$doubleRentCar = $villageCompany - $rentCar - $applyCar - $selfCar ;
2023-09-05 11:12:32 +08:00
if ( $params [ 'num' ] > $doubleRentCar ){
return $this -> fail ( '数量超过可再租车辆数' );
}
2023-09-07 09:41:53 +08:00
//判断物流车辆
$checkNum = curl_post ( env ( 'project.logistic_domain' ) . '/api/checkCarNum' ,[],[ 'num' => $params [ 'num' ]]);
if ( $checkNum == null ){
return $this -> fail ( '检查车辆数量错误' );
}
if ( $checkNum [ 'code' ] == 0 ){
return $this -> fail ( $checkNum [ 'msg' ]);
}
2023-08-31 01:24:26 +08:00
//查找乙方公司信息
$party_b = Company :: field ( 'id,company_name,organization_code,master_name,master_phone,master_email,company_type' ) -> where ( 'id' , $this -> userInfo [ 'company_id' ]) -> find ();
if ( empty ( $party_b )) {
return $this -> fail ( '数据不存在' );
2023-08-25 13:58:06 +08:00
}
2023-08-31 01:24:26 +08:00
//判断是否是镇街公司
if ( $party_b [ 'company_type' ] != 16 ){
return [ 'code' => 0 , 'msg' => '非镇街公司不能签约' ];
}
//发送生成合同给物流信息
2023-09-04 16:15:27 +08:00
$curl_result = curl_post ( env ( 'project.logistic_domain' ) . '/api/signContract' ,[],[
2023-08-31 01:24:26 +08:00
'num' => $params [ '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 ( empty ( $curl_result )){
return $this -> fail ( 'null return from logistic' );
}
if ( $curl_result [ 'code' ] == 0 ){
return $this -> fail ( $curl_result [ 'msg' ] . ' from logistic' );
}
Db :: startTrans ();
try {
$create_result = VehicleContract :: create ( $curl_result [ 'data' ]);
if ( $create_result -> id ){
Db :: commit ();
return $this -> success ( '合同发起成功,等待审核 from task' );
} else {
Db :: rollback ();
return $this -> success ( '合同发起失败,请稍后重试 from task' );
}
} catch ( \Exception $e ) {
Db :: rollback ();
return $this -> fail ( $e -> getMessage () . ' from task' );
2023-08-26 14:04:16 +08:00
}
}
2023-08-26 16:15:14 +08:00
2023-08-30 15:49:41 +08:00
//镇街公司生成小组服务公司租赁合同
public function setContractByVillageCompany (){
//获取参数
2023-08-31 08:54:53 +08:00
$params = $this -> request -> post ([ 'id' , 'car_id' ]);
if ( empty ( $params [ 'id' ])){
2023-08-30 15:49:41 +08:00
return $this -> fail ( '缺少必要参数' );
}
2023-08-31 08:54:53 +08:00
//获取数据
$vehicleContract = VehicleContract :: where ( 'id' , $params [ 'id' ]) -> find ();
if ( empty ( $vehicleContract )){
return $this -> fail ( '未找到数据' );
}
if ( $this -> userInfo [ 'company_id' ] != $vehicleContract [ 'company_a_id' ]){
return $this -> fail ( '数据错误' );
}
if ( $vehicleContract [ 'status' ] != - 1 ) {
return $this -> fail ( '数据状态错误' );
}
if ( $vehicleContract [ 'type' ] == 0 ){
2023-08-30 18:57:41 +08:00
if ( empty ( $params [ 'car_id' ])){
2023-08-31 08:54:53 +08:00
return $this -> fail ( '缺少参数car_id' );
2023-08-30 18:57:41 +08:00
}
}
2023-08-31 08:54:53 +08:00
if ( $vehicleContract [ 'type' ] == 0 ){
$car = VehicleRent :: field ( 'car_id as id,car_license as license' ) -> where ( 'car_id' , $params [ 'car_id' ]) -> find ();
if ( empty ( $car )){
return $this -> fail ( '车辆数据有误' );
}
$json = json_encode ( $car -> toArray ());
//更改车辆状态
VehicleRent :: where ( 'car_id' , $params [ 'car_id' ]) -> update ([ 'status' => 1 ]);
//更改状态
$result = VehicleContract :: where ( 'id' , $params [ 'id' ]) -> update ([ 'status' => 0 , 'cars_info' => $json , 'update_time' => time ()]);
} else {
//更改状态
$result = VehicleContract :: where ( 'id' , $params [ 'id' ]) -> update ([ 'status' => 0 , 'update_time' => time ()]);
2023-08-30 15:49:41 +08:00
}
//返回数据
2023-08-31 08:54:53 +08:00
if ( $result ){
return $this -> success ( '合同生成成功,等待风控部审核' );
2023-08-30 15:49:41 +08:00
} else {
2023-08-31 08:54:53 +08:00
return $this -> fail ( '合同生成失败,请稍后重试' );
2023-08-30 15:49:41 +08:00
}
}
//镇街公司发起合同
public function initiatingRentCarContract () {
//获取参数
$params = $this -> request -> post ([ 'id' ]);
if ( empty ( $params [ 'id' ])){
return $this -> fail ( '缺少必要参数' );
}
//获取数据
$contract = VehicleContract :: where ( 'id' , $params [ 'id' ]) -> find ();
2023-08-31 08:54:53 +08:00
if ( empty ( $contract )){
2023-08-30 15:49:41 +08:00
return $this -> fail ( '数据不存在' );
}
if ( $contract [ 'status' ] != 1 ){
return $this -> fail ( '合同状态错误' );
}
$signData = [
'name' => $contract [ 'company_a_name' ] . '的合同' ,
'signatories' => [
[ 'fullName' => $contract [ 'company_a_name' ], 'identityType' => 12 , 'identityCard' => $contract [ 'company_a_code' ], 'email' => $contract [ 'company_a_email' ], 'noNeedVerify' => 1 , 'signLevel' => 1 ],
[ 'fullName' => $contract [ 'company_b_name' ], 'identityType' => 12 , 'identityCard' => $contract [ 'company_b_code' ], 'email' => $contract [ 'company_b_email' ], 'noNeedVerify' => 1 , 'signLevel' => 1 ]
],
'url' => $contract [ 'file' ]
];
2023-09-01 11:23:04 +08:00
$notify_url = '' ;
if ( $contract [ 'type' ] == 0 ){
2023-09-04 21:09:37 +08:00
$notify_url = env ( 'project.website_domain' ) . '/api/index/systemCarRent' ;
2023-09-01 11:23:04 +08:00
} elseif ( $contract [ 'type' ] == 1 ){
2023-09-04 21:09:37 +08:00
$notify_url = env ( 'project.website_domain' ) . '/api/index/selfCarRent' ;
2023-09-01 11:23:04 +08:00
} elseif ( $contract [ 'type' ] == 2 ){
2023-09-04 21:09:37 +08:00
$notify_url = env ( 'project.website_domain' ) . '/api/index/cancelRent' ;
2023-09-01 11:23:04 +08:00
}
2023-09-02 11:46:40 +08:00
$signRes = app ( JunziqianController :: class ) -> VehicleRentSigning ( $signData , $params [ 'id' ], $notify_url );
2023-08-30 15:49:41 +08:00
if ( $signRes -> success ) {
$contract -> save ([
'id' => $contract [ 'id' ],
'contract_no' => $signRes -> data ,
'status' => 2
]);
2023-09-01 11:23:04 +08:00
if ( $contract [ 'type' ] == 2 ){
$smsTitle = '《解约合同》' ;
} else {
$smsTitle = '《租赁合同》' ;
}
$this -> sendSms ( $params [ 'id' ], $smsTitle );
2023-08-30 15:49:41 +08:00
return $this -> success ( '合同发送成功' );
} else {
return $this -> fail ( $signRes -> msg );
}
}
2023-08-31 20:03:06 +08:00
public function sendSmsAgain () {
//获取参数
$id = $this -> request -> post ( 'id' );
if ( empty ( $id )){
return $this -> fail ( '参数错误' );
}
2023-09-01 11:23:04 +08:00
//获取数据
$contract = VehicleContract :: where ( 'id' , $id ) -> find ();
if ( empty ( $contract )){
return $this -> fail ( '数据错误' );
}
if ( $contract [ 'type' ] == 2 ){
$smsTitle = '《解约合同》' ;
} else {
$smsTitle = '《租赁合同》' ;
}
$this -> sendSms ( $id , $smsTitle );
2023-08-31 20:03:06 +08:00
return $this -> success ( '发送成功' );
}
2023-08-30 13:37:20 +08:00
//小组服务公司租赁申请
public function rentApply () {
2023-08-31 08:54:53 +08:00
//验证请求类型
2023-08-30 13:37:20 +08:00
if ( ! $this -> request -> isPost ()){
return $this -> fail ( '请求类型错误' );
}
//获取参数
2023-09-07 13:39:28 +08:00
$params = $this -> request -> post ([ 'type' , 'license' , 'pic' ]);
2023-09-07 14:06:42 +08:00
if ( ! isset ( $params [ 'type' ])){
return $this -> fail ( '缺少必要参数' );
}
2023-09-07 13:39:28 +08:00
if ( $params [ 'type' ] == 1 ){
if ( empty ( $params [ 'license' ]) || empty ( $params [ 'pic' ])){
return $this -> fail ( '缺少必要参数' );
}
}
2023-08-30 13:37:20 +08:00
//获取当前公司信息
2023-08-31 08:54:53 +08:00
$party_b = Company :: field ( 'id,company_name,master_name,master_phone,master_email,is_contract,organization_code,company_type' ) -> where ( 'id' , $this -> userInfo [ 'company_id' ]) -> find ();
if ( empty ( $party_b )){
return $this -> fail ( '账号异常' );
}
if ( $party_b [ 'company_type' ] != 18 ){
2023-08-30 13:37:20 +08:00
return $this -> fail ( '非小组服务公司不能申请' );
}
2023-08-31 08:54:53 +08:00
if ( $party_b [ 'is_contract' ] != 1 ){
2023-08-30 13:37:20 +08:00
return $this -> fail ( '当前小组服务公司未签约' );
}
//获取签约信息
2023-09-01 17:45:27 +08:00
$contract = Contract :: where ( 'party_b' , $this -> userInfo [ 'company_id' ]) -> where ( 'signing_timer' , 2 ) -> find ();
2023-08-31 08:54:53 +08:00
$party_a = Company :: field ( 'id,company_name,master_name,master_phone,master_email,is_contract,organization_code,company_type' ) -> where ( 'id' , $contract [ 'party_a' ]) -> find ();
if ( empty ( $contract ) || empty ( $party_a )){
2023-08-30 13:37:20 +08:00
return $this -> fail ( '未找到签约镇街公司' );
}
2023-08-31 08:54:53 +08:00
if ( $party_a [ 'company_type' ] != 16 ){
return $this -> fail ( '不能与非镇街公司签约' );
}
if ( $party_a [ 'is_contract' ] != 1 ){
return $this -> fail ( '当前镇街公司未签约' );
}
2023-08-30 13:37:20 +08:00
//判断是否申请过
2023-09-08 17:43:08 +08:00
$vehicleContract = VehicleContract :: where ( 'company_b_id' , $this -> userInfo [ 'company_id' ]) -> where ( 'type' , '<>' , 2 ) -> whereNotIn ( 'status' , '4,5,6' ) -> find ();
2023-08-31 08:54:53 +08:00
if ( ! empty ( $vehicleContract )){
return $this -> fail ( '请勿重复申请' );
2023-08-30 13:37:20 +08:00
}
2023-09-07 13:39:28 +08:00
if ( $params [ 'type' ] == 1 ){
$cars_info = json_encode ([ 'license' => $params [ 'license' ], 'pic' => $params [ 'pic' ]]);
$car_type = 1 ;
} else {
$cars_info = null ;
$car_type = 0 ;
}
2023-08-30 13:37:20 +08:00
//设置数据
2023-08-31 08:54:53 +08:00
$data = [
'contract_logistic_id' => 0 ,
'contract_no' => time (),
'company_a_id' => $party_a [ 'id' ],
'company_a_name' => $party_a [ 'company_name' ],
'company_a_code' => $party_a [ 'organization_code' ],
'company_a_user' => $party_a [ 'master_name' ],
'company_a_phone' => $party_a [ 'master_phone' ],
'company_a_email' => $party_a [ 'master_email' ],
'company_b_id' => $party_b [ 'id' ],
'company_b_name' => $party_b [ 'company_name' ],
'company_b_code' => $party_b [ 'organization_code' ],
'company_b_user' => $party_b [ 'master_name' ],
'company_b_phone' => $party_b [ 'master_phone' ],
'company_b_email' => $party_b [ 'master_email' ],
2023-09-07 13:39:28 +08:00
'cars_info' => $cars_info ,
2023-08-31 08:54:53 +08:00
'num' => 1 ,
2023-09-07 13:39:28 +08:00
'type' => $car_type ,
2023-08-31 08:54:53 +08:00
'status' => - 1 ,
2023-08-30 13:37:20 +08:00
'create_time' => time (),
2023-08-31 08:54:53 +08:00
'update_time' => time ()
];
//写入数据
$result = VehicleContract :: create ( $data );
if ( $result ){
return $this -> success ( '申请成功,待镇街公司审核' );
2023-08-30 13:37:20 +08:00
} else {
2023-08-31 08:54:53 +08:00
return $this -> fail ( '申请失败,请稍后重试' );
2023-08-30 13:37:20 +08:00
}
}
//镇街公司驳回小组服务公司的租赁申请
public function rejectRentApply () {
2023-08-31 08:54:53 +08:00
//验证请求类型
if ( ! $this -> request -> isPost ()){
return $this -> fail ( '请求类型错误' );
}
2023-08-30 13:37:20 +08:00
//获取参数
2023-08-31 08:54:53 +08:00
$params = $this -> request -> post ([ 'id' , 'content' ]);
if ( empty ( $params [ 'id' ]) || empty ( $params [ 'content' ])){
2023-08-30 13:37:20 +08:00
return $this -> fail ( '缺少必要参数' );
}
//获取数据
2023-08-31 08:54:53 +08:00
$vehicleContract = VehicleContract :: where ( 'id' , $params [ 'id' ]) -> find ();
if ( empty ( $vehicleContract )){
return $this -> fail ( '未查找到数据' );
2023-08-30 13:37:20 +08:00
}
2023-08-31 08:54:53 +08:00
if ( $vehicleContract [ 'company_a_id' ] != $this -> userInfo [ 'company_id' ]){
return $this -> fail ( '数据不匹配' );
2023-08-30 13:37:20 +08:00
}
2023-09-08 17:13:33 +08:00
//判断合同类型
if ( $vehicleContract [ 'type' ] == 2 ){
Db :: startTrans ();
try {
//查找原合同
$car = json_decode ( $vehicleContract [ 'cars_info' ], true );
$carRentInfo = VehicleRent :: where ( 'car_id' , $car [ 'id' ]) -> findOrEmpty ();
$oldVehicleContractUpdate = VehicleContract :: where ( 'id' , $carRentInfo [ 'contract_id' ]) -> update ([ 'status' => 3 ]);
//更新
$result = VehicleContract :: where ( 'id' , $params [ 'id' ]) -> update ([
'status' => 4 ,
'reject_message' => $params [ 'content' ]
]);
if ( $oldVehicleContractUpdate && $result ){
Db :: commit ();
return $this -> success ( '驳回成功' );
} else {
Db :: rollback ();
return $this -> fail ( '驳回失败' );
}
} catch ( \Exception $e ) {
Db :: rollback ();
return $this -> fail ( $e -> getMessage ());
}
2023-08-30 13:37:20 +08:00
} else {
2023-09-08 17:14:45 +08:00
//更新
$result = VehicleContract :: where ( 'id' , $params [ 'id' ]) -> update ([
'status' => 4 ,
'reject_message' => $params [ 'content' ]
]);
if ( $result ){
return $this -> success ( '驳回成功' );
} else {
return $this -> fail ( '驳回失败' );
2023-09-08 17:13:33 +08:00
}
2023-08-30 13:37:20 +08:00
}
}
//镇街公司收到的小组服务公司租赁申请列表
public function rentApplyList () {
2023-09-02 11:04:05 +08:00
$data = VehicleContract :: where ( 'company_a_id' , $this -> userInfo [ 'company_id' ]) -> where ( 'status' , '<>' , 4 ) -> select ();
2023-08-30 13:37:20 +08:00
return $this -> success ( '请求成功' , $data -> toArray ());
}
//小组服务公司租赁申请详情
public function rentApplyInfo () {
//获取参数
$id = $this -> request -> get ( 'id' );
if ( empty ( $id )){
return $this -> fail ( '缺少必要参数' );
}
//获取数据
2023-08-31 08:54:53 +08:00
$vehicleContract = VehicleContract :: where ( 'id' , $id ) -> find ();
if ( empty ( $vehicleContract )){
2023-08-30 13:37:20 +08:00
return $this -> fail ( '获取数据失败' );
}
2023-08-31 08:54:53 +08:00
if ( $vehicleContract [ 'company_a_id' ] != $this -> userInfo [ 'company_id' ]){
return $this -> fail ( '数据不匹配' );
}
2023-09-01 13:53:58 +08:00
$vehicleRentCars = VehicleRent :: where ( 'company_id' , $vehicleContract [ 'company_a_id' ]) -> where ( 'status' , 0 ) -> select () -> toArray ();
2023-08-31 08:54:53 +08:00
$data = [
'vehicleContract' => $vehicleContract -> toArray (),
2023-08-31 11:20:55 +08:00
'vehicleRentCars' => $vehicleRentCars
2023-08-31 08:54:53 +08:00
];
return $this -> success ( '请求成功' , $data );
2023-08-30 13:37:20 +08:00
}
2023-08-29 19:21:15 +08:00
2023-08-30 15:49:41 +08:00
//镇街公司车辆管理首页
2023-08-31 08:54:53 +08:00
public function townCompanyVehicleIndex () {
//获取公司信息
$company = Company :: where ( 'id' , $this -> userInfo [ 'company_id' ]) -> find ();
if ( empty ( $company )){
return $this -> fail ( '数据错误' );
}
2023-09-01 13:53:58 +08:00
if ( $company [ 'company_type' ] != 16 ){
2023-08-31 08:54:53 +08:00
return $this -> fail ( '非镇街公司不能访问' );
2023-08-30 13:37:20 +08:00
}
2023-08-30 15:49:41 +08:00
//获取小组服务公司申请信息
2023-09-01 13:53:58 +08:00
$vehicleContract = VehicleContract :: where ( 'company_a_id' , $company [ 'id' ]) -> where ( 'status' , 'in' , '-1,0,1,2' ) -> limit ( 4 ) -> order ( 'create_time desc' ) -> select () -> toArray ();
2023-08-30 13:37:20 +08:00
//获取车辆列表
2023-09-01 13:53:58 +08:00
$vehicleRentCars = VehicleRent :: where ( 'company_id' , $company [ 'id' ]) -> where ( 'status' , 'in' , '0,1,2' ) -> select () -> each ( function ( $item ){
2023-08-31 08:54:53 +08:00
if ( $item [ 'status' ] == 2 ){
$item [ 'rent_user' ] = Company :: field ( 'company_name,master_name as user_name,master_phone as user_phone,province,city,area,street,village,brigade' ) -> where ( 'id' , $item [ 'rent_company_id' ]) -> find () -> append ([ 'province_name' , 'city_name' , 'area_name' , 'street_name' , 'village_name' , 'brigade_name' ]);
2023-08-30 13:37:20 +08:00
}
2023-08-31 08:54:53 +08:00
}) -> toArray ();
2023-08-30 15:49:41 +08:00
//获取该公司已签约的小组服务公司数量
2023-09-01 15:30:19 +08:00
$villageCompany = Contract :: field ( 'id' ) -> where ( 'party_a' , $company [ 'id' ]) -> where ( 'signing_timer' , 2 ) -> count ();
2023-09-08 16:47:30 +08:00
//已经租赁车辆
$rentCar = VehicleRent :: field ( 'id' ) -> where ( 'company_id' , $company [ 'id' ]) -> where ( 'type' , '<>' , 1 ) -> count ();
2023-08-31 18:56:12 +08:00
//申请中的车辆
2023-08-31 19:20:20 +08:00
$applyCar = VehicleContract :: field ( 'num' ) -> where ( 'company_b_id' , $company [ 'id' ]) -> where ( 'status' , 'in' , '-1,0,1,2' ) -> sum ( 'num' );
2023-08-30 15:49:41 +08:00
//自有车辆数量
2023-09-01 13:53:58 +08:00
$selfCar = VehicleRent :: field ( 'id' ) -> where ( 'company_id' , $company [ 'id' ]) -> where ( 'status' , '<>' , 3 ) -> where ( 'type' , 1 ) -> count ();
2023-08-31 18:56:12 +08:00
//可在租车辆
$doubleRentCar = $villageCompany - $rentCar - $applyCar - $selfCar ;
2023-08-30 13:37:20 +08:00
//设置数据
$data = [
2023-08-31 08:54:53 +08:00
'apply' => $vehicleContract ,
'car_list' => $vehicleRentCars ,
2023-08-31 18:56:12 +08:00
'monitor_num' => $villageCompany ,
'rent_num' => $rentCar ,
'can_rent_num' => intval ( $doubleRentCar ),
'self_num' => $selfCar ,
2023-08-31 19:25:08 +08:00
'apply_num' => $applyCar
2023-08-30 13:37:20 +08:00
];
//返回
return $this -> success ( '请求成功' , $data );
}
2023-08-31 08:54:53 +08:00
public function villageCompanyIndex () {
//获取公司信息
$company = Company :: field ( 'id,company_type,province,city,area,street,village,brigade' ) -> where ( 'id' , $this -> userInfo [ 'company_id' ]) -> find () -> append ([ 'province_name' , 'city_name' , 'area_name' , 'street_name' , 'village_name' , 'brigade_name' ]);
if ( empty ( $company )){
return $this -> fail ( '数据错误' );
}
if ( $company [ 'company_type' ] != 18 ){
return $this -> fail ( '非小组公司不能访问' );
}
//获取申请信息
2023-09-08 17:20:36 +08:00
$vehicleContract = VehicleContract :: where ( 'company_b_id' , $company [ 'id' ]) -> where ( 'type' , '<>' , 2 ) -> order ( 'id desc' ) -> findOrEmpty ();
2023-09-01 21:02:59 +08:00
if ( $vehicleContract [ 'status' ] == 3 ){
2023-08-31 08:54:53 +08:00
if ( ! empty ( $vehicleContract [ 'cars_info' ])){
2023-08-31 19:05:12 +08:00
$vehicleContract [ 'cars_info' ] = json_decode ( $vehicleContract [ 'cars_info' ], true );
if ( ! empty ( $vehicleContract [ 'cars_info' ])){
$arr = $vehicleContract [ 'cars_info' ];
$arr [ 'mileage' ] = 0 ;
2023-09-04 16:15:27 +08:00
$position = curl_get ( env ( 'project.logistic_domain' ) . '/api/getCarLocal?car_id=' . $arr [ 'id' ]);
2023-08-31 19:05:12 +08:00
if ( $position && $position [ 'code' ] == 1 ){
$arr [ 'lon' ] = $position [ 'data' ][ 'lon' ];
$arr [ 'lat' ] = $position [ 'data' ][ 'lat' ];
}
$vehicleContract [ 'cars_info' ] = $arr ;
2023-08-31 08:54:53 +08:00
}
}
2023-08-31 19:05:12 +08:00
$vehicleContract [ 'province' ] = $company [ 'province_name' ];
$vehicleContract [ 'city' ] = $company [ 'city_name' ];
$vehicleContract [ 'area' ] = $company [ 'area_name' ];
$vehicleContract [ 'street' ] = $company [ 'street_name' ];
$vehicleContract [ 'village' ] = $company [ 'village_name' ];
$vehicleContract [ 'brigade' ] = $company [ 'brigade_name' ];
2023-08-31 08:54:53 +08:00
}
//返回数据
return $this -> success ( '请求成功' , $vehicleContract -> toArray ());
2023-08-30 21:58:24 +08:00
}
2023-08-30 15:49:41 +08:00
//车辆详情
2023-08-30 13:37:20 +08:00
public function vehicleInfo () {
//获取参数
$carId = $this -> request -> get ( 'car_id' );
if ( empty ( $carId )){
return $this -> fail ( '缺少必要参数' );
}
//获取数据
$data = VehicleRent :: where ( 'car_id' , $carId ) -> find ();
2023-08-31 08:54:53 +08:00
if ( empty ( $data )){
return $this -> fail ( '数据错误' );
}
2023-08-30 13:37:20 +08:00
$data [ 'mileage' ] = 0 ;
2023-08-31 10:56:21 +08:00
if ( $data [ 'status' ] == 2 ){
2023-08-31 08:54:53 +08:00
$data [ 'company' ] = Company :: field ( 'company_name,master_name as user_name,master_phone as user_phone,province,city,area,street,village,brigade' ) -> where ( 'id' , $data [ 'rent_company_id' ]) -> find () -> append ([ 'province_name' , 'city_name' , 'area_name' , 'street_name' , 'village_name' , 'brigade_name' ]);
2023-09-01 15:37:03 +08:00
//获取合同
2023-09-05 15:04:58 +08:00
$data [ 'contract' ] = VehicleContract :: field ( 'id,contract_no,contract_url,file,status,create_time,update_time' ) -> where ( 'id' , $data [ 'contract_id' ]) -> findOrEmpty ();
2023-08-30 13:37:20 +08:00
}
2023-08-30 15:49:41 +08:00
//当前坐标位置
2023-09-05 11:12:32 +08:00
$position = curl_get ( env ( 'project.logistic_domain' ) . '/api/getCarLocal?car_id=' . $carId );
2023-08-30 15:49:41 +08:00
if ( $position && $position [ 'code' ] == 1 ){
$data [ 'position' ] = $position [ 'data' ];
2023-09-01 13:29:44 +08:00
} else {
$data [ 'position' ] = [];
2023-08-30 15:49:41 +08:00
}
2023-08-30 13:37:20 +08:00
return $this -> success ( '请求成功' , $data -> toArray ());
}
2023-08-30 18:06:55 +08:00
public function vehicleTrack () {
//获取参数
2023-08-30 21:58:24 +08:00
$params = $this -> request -> post ([ 'car_id' , 'start_time' , 'end_time' ]);
2023-08-30 18:06:55 +08:00
if ( empty ( $params [ 'car_id' ]) || empty ( $params [ 'start_time' ]) || empty ( $params [ 'end_time' ])){
return $this -> fail ( '缺少必要参数' );
}
//获取轨迹
2023-09-04 16:15:27 +08:00
$url = env ( 'project.logistic_domain' ) . '/api/getCarHistory?car_id=' . $params [ 'car_id' ] . '&start_time=' . $params [ 'start_time' ] . '&end_time=' . $params [ 'end_time' ];
2023-08-30 18:06:55 +08:00
$result = curl_get ( $url );
2023-09-01 11:23:04 +08:00
$data = [];
foreach ( $result [ 'data' ] as $k => $v ){
$data [ $k ][ 'latitude' ] = $v [ 'lat' ];
$data [ $k ][ 'longitude' ] = $v [ 'lon' ];
}
2023-09-01 11:24:54 +08:00
return $this -> success ( 'success' , $data );
2023-08-30 18:06:55 +08:00
}
2023-09-01 11:23:04 +08:00
public function cancelContract () {
//获取参数
$params = $this -> request -> post ([ 'car_id' ]);
if ( empty ( $params [ 'car_id' ])){
return $this -> fail ( '参数错误' );
}
//获取车辆信息
$carInfo = VehicleRent :: where ( 'car_id' , $params [ 'car_id' ]) -> where ( 'type' , 1 ) -> find ();
if ( empty ( $carInfo )){
return $this -> fail ( '车辆信息错误' );
}
if ( $carInfo [ 'rent_company_id' ] != $this -> userInfo [ 'company_id' ]){
return $this -> fail ( '当前公司与车辆信息不匹配' );
}
2023-09-01 14:24:55 +08:00
//获取原签约信息
2023-09-01 15:24:59 +08:00
$contract = VehicleContract :: where ( 'id' , $carInfo [ 'contract_id' ]) -> where ( 'status' , 3 ) -> find ();
2023-09-01 14:24:55 +08:00
if ( empty ( $contract )){
return $this -> fail ( '原签约信息错误' );
}
2023-09-01 11:23:04 +08:00
//获取甲方公司信息
$party_a = Company :: where ( 'id' , $carInfo [ 'company_id' ]) -> find ();
if ( empty ( $party_a )){
return $this -> fail ( '甲方公司信息错误' );
}
//获取乙方公司信息
$party_b = Company :: where ( 'id' , $this -> userInfo [ 'company_id' ]) -> find ();
if ( empty ( $party_b )){
return $this -> fail ( '乙方公司信息错误' );
}
//判断是否申请过
$vehicleContract = VehicleContract :: where ( 'company_b_id' , $this -> userInfo [ 'company_id' ]) -> where ( 'type' , 3 ) -> where ( 'status' , '<>' , 4 ) -> find ();
if ( ! empty ( $vehicleContract )){
return $this -> fail ( '请勿重复申请' );
}
//设置数据
$data = [
'contract_logistic_id' => 0 ,
'contract_no' => time (),
'company_a_id' => $party_a [ 'id' ],
'company_a_name' => $party_a [ 'company_name' ],
'company_a_code' => $party_a [ 'organization_code' ],
'company_a_user' => $party_a [ 'master_name' ],
'company_a_phone' => $party_a [ 'master_phone' ],
'company_a_email' => $party_a [ 'master_email' ],
'company_b_id' => $party_b [ 'id' ],
'company_b_name' => $party_b [ 'company_name' ],
'company_b_code' => $party_b [ 'organization_code' ],
'company_b_user' => $party_b [ 'master_name' ],
'company_b_phone' => $party_b [ 'master_phone' ],
'company_b_email' => $party_b [ 'master_email' ],
'cars_info' => json_encode ([ 'id' => $carInfo [ 'car_id' ], 'license' => $carInfo [ 'car_license' ]]),
'num' => 1 ,
'type' => 2 ,
'status' => - 1 ,
'create_time' => time (),
2023-09-01 14:24:55 +08:00
'update_time' => time (),
2023-09-05 15:04:58 +08:00
'old_file' => $contract [ 'contract_url' ],
2023-09-01 11:23:04 +08:00
];
2023-09-08 16:47:30 +08:00
Db :: startTrans ();
try {
//写入数据
$new_result = VehicleContract :: create ( $data );
//修改原合同状态
2023-09-08 16:58:09 +08:00
$old_result = VehicleContract :: where ( 'id' , $contract [ 'id' ]) -> update ([ 'status' => 5 ]);
2023-09-08 16:47:30 +08:00
if ( $new_result && $old_result ){
Db :: commit ();
return $this -> success ( '申请成功,待镇街公司审核' );
} else {
Db :: rollback ();
return $this -> fail ( '申请失败,请稍后重试' );
}
} catch ( \Exception $e ) {
Db :: rollback ();
return $this -> fail ( $e -> getMessage ());
2023-09-01 11:23:04 +08:00
}
}
2023-09-01 15:16:42 +08:00
public function townCompanyContractList () {
2023-09-01 17:55:12 +08:00
//获取公司信息
2023-09-01 15:16:42 +08:00
$company = Company :: where ( 'id' , $this -> userInfo [ 'company_id' ]) -> find ();
if ( empty ( $company )){
return $this -> fail ( '请求错误' );
}
if ( $company [ 'company_type' ] != 16 ){
2023-09-01 17:55:12 +08:00
return $this -> fail ( '非镇街公司不能访问' );
2023-09-01 15:16:42 +08:00
}
2023-09-21 11:44:55 +08:00
$data = VehicleContract :: field ( 'id,contract_no,contract_url,status,create_time,update_time' ) -> where ( 'contract_logistic_id' , 0 ) -> where ( 'company_b_id' , $company [ 'id' ]) -> select ();
2023-09-01 15:26:22 +08:00
return $this -> success ( '请求成功' , $data -> toArray ());
2023-09-01 15:16:42 +08:00
}
2023-09-01 11:23:04 +08:00
public function sendSms ( $id , $title ) {
2023-08-30 15:49:41 +08:00
//获取合同数据
$contract = VehicleContract :: where ( 'id' , $id ) -> find ();
if ( $contract && ! $contract -> isEmpty () && $contract [ 'file' ] != '' ) {
//发送短信
$data = [
//甲方
[
" applyNo " => $contract [ 'contract_no' ],
" fullName " => $contract [ 'company_a_name' ],
" identityCard " => $contract [ 'company_a_code' ],
" identityType " => 12 ,
" master_phone " => $contract [ 'company_a_phone' ],
" type " => " party_a "
],
//乙方
[
" applyNo " => $contract [ 'contract_no' ],
" fullName " => $contract [ 'company_b_name' ],
" identityCard " => $contract [ 'company_b_code' ],
" identityType " => 12 ,
" master_phone " => $contract [ 'company_b_phone' ],
" type " => " party_b "
],
];
$url = [];
foreach ( $data as $v ) {
$res = app ( JunziqianController :: class ) -> SigningLink ( $v );
if ( ! $res -> success ) {
return false ;
}
if ( $v [ 'type' ] == 'party_a' ) {
$url [ 'party_a' ] = $res -> data ;
} else {
$url [ 'party_b' ] = $res -> data ;
}
//发送短信
$sms = [
'mobile' => $v [ 'master_phone' ],
'name' => $v [ 'fullName' ],
2023-09-01 11:23:04 +08:00
'type' => $title ,
2023-08-31 18:24:32 +08:00
'code' => 'api/Hetong/info?id=' . $id . '&type=' . $v [ 'type' ],
2023-08-31 08:54:53 +08:00
'scene' => 'WQ'
2023-08-30 15:49:41 +08:00
];
$scene = NoticeEnum :: getSceneByTag ( $sms [ 'scene' ]);
if ( empty ( $scene )) {
throw new \Exception ( '场景值异常' );
}
event ( 'Notice' , [
'scene_id' => $scene ,
'params' => $sms
]);
}
VehicleContract :: where ( 'id' , $id ) -> update ([ 'url' => json_encode ( $url )]);
return true ;
} else {
return false ;
2023-08-30 13:37:20 +08:00
}
}
2023-08-26 17:22:43 +08:00
2023-08-25 13:58:06 +08:00
}