diff --git a/app/api/controller/VehicleController.php b/app/api/controller/VehicleController.php index 7ef13d40..09d97604 100644 --- a/app/api/controller/VehicleController.php +++ b/app/api/controller/VehicleController.php @@ -86,7 +86,7 @@ class VehicleController extends BaseApiController } } - public function getCompanyCars() { + public function getCompanyCars():Json { $params = $this->request->get(['company_id','company_type']); if(empty($params['company_id']) || empty($params['company_type'])){ return $this->fail('缺少必要参数'); @@ -101,7 +101,7 @@ class VehicleController extends BaseApiController } //获取车辆当前位置 - public function getCarLocal() { + public function getCarLocal():Json { $params = $this->request->get(['car_id','gps_imei']); if(empty($params['car_id']) || empty($params['gps_imei'])){ return $this->fail('缺少必要参数'); diff --git a/app/api/logic/GpsLogic.php b/app/api/logic/GpsLogic.php index ffa82f91..7e673d5f 100644 --- a/app/api/logic/GpsLogic.php +++ b/app/api/logic/GpsLogic.php @@ -47,6 +47,7 @@ class GpsLogic extends BaseLogic //验证请求结果 if(!empty($result['ret']) && isset($result['data'])){ //设置缓存数据 + Cache::set('gps_user_id', $result['data']['userId'], $this->expTime); Cache::set('gps_token', $result['data']['token'], $this->expTime); return $result['data']['token']; }else{ diff --git a/app/api/logic/VehicleLogic.php b/app/api/logic/VehicleLogic.php index d59cd252..6de9ea34 100644 --- a/app/api/logic/VehicleLogic.php +++ b/app/api/logic/VehicleLogic.php @@ -20,6 +20,8 @@ use app\common\model\vehicle\Company; use app\common\model\vehicle\Vehicle; use app\common\model\vehicle\VehicleRent; use app\common\model\vehicle\VehicleRentRecord; +use think\facade\Cache; +use think\facade\Log; /** @@ -29,6 +31,20 @@ use app\common\model\vehicle\VehicleRentRecord; */ class VehicleLogic extends BaseLogic { + public static function getTaskToken() { + //获取缓存数据 + $task_token = Cache::get('task_token'); + //验证缓存数据是否存在,如果缓存数据存在则直接返回缓存数据 + if(!empty($task_token)) return $task_token; + + $getToken = curl_post('https://worker-task.lihaink.cn/adminapi/login/account',[],['account'=>'admin','password'=>'123456','terminal'=>1]); + if($getToken['code'] == 0){ + return ''; + } + //设置缓存数据 + Cache::set('task_token', $getToken['data']['token'], 86400); + return $getToken['data']['token']; + } public static function companyInfo():array { $data = Company::field('id,company_name')->where('company_name',30)->select(); if($data){ @@ -53,14 +69,9 @@ class VehicleLogic extends BaseLogic //发起合同 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'] + 'token:'.self::getTaskToken() ],[ 'id' => $params['party_b'], 'party_a' => $params['party_a'], @@ -115,6 +126,13 @@ class VehicleLogic extends BaseLogic if(!$record){ return ['code'=>0,'msg'=>'数据不存在']; } + $res = curl_post('http://www.task.local/v1/notify_property',[ + 'token:'.self::getTaskToken(), + 'authority:worker-task.lihaink.cn', + ],[ + 'company_id'=>$record['party_b'], + 'object_id' => $record['car_ids'] + ]); VehicleRentRecord::startTrans(); try { if($record['rent_type'] == 1){ @@ -175,6 +193,14 @@ class VehicleLogic extends BaseLogic //写入数据 VehicleRent::update($data); } + $res = curl_post('https://worker-task.lihaink.cn/v1/notify_property',[ + 'token:'.self::getTaskToken(), + 'authority:worker-task.lihaink.cn', + ],[ + 'company_id'=>$record['part_b'], + 'object_id' => explode(',',$record['car_ids']) + ]); + Log::write($res); VehicleRentRecord::where('id',$record['id'])->update(['status'=>2,'update_time'=>time()]); VehicleRentRecord::commit(); return ['code'=>1,'msg'=>'操作成功']; @@ -186,7 +212,7 @@ class VehicleLogic extends BaseLogic public static function getCompanyCars($params):array { $company_str = $params['company_type'] == 1 ? 'lessee_one_company_id' : 'lessee_two_company_id'; - $data = VehicleRent::field('car_id')->where($company_str,$params['company_id'])->select()->each(function($item){ + $data = VehicleRent::where($company_str,$params['company_id'])->select()->each(function($item){ $car = Vehicle::field('license,gps_imei')->where('id',$item['car_id'])->find(); $item['gps_imei'] = $car['gps_imei']; $item['license'] = $car['license'];