q
This commit is contained in:
parent
c74b01a1c8
commit
c8c3118ecc
@ -86,7 +86,7 @@ class VehicleController extends BaseApiController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCompanyCars() {
|
public function getCompanyCars():Json {
|
||||||
$params = $this->request->get(['company_id','company_type']);
|
$params = $this->request->get(['company_id','company_type']);
|
||||||
if(empty($params['company_id']) || empty($params['company_type'])){
|
if(empty($params['company_id']) || empty($params['company_type'])){
|
||||||
return $this->fail('缺少必要参数');
|
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']);
|
$params = $this->request->get(['car_id','gps_imei']);
|
||||||
if(empty($params['car_id']) || empty($params['gps_imei'])){
|
if(empty($params['car_id']) || empty($params['gps_imei'])){
|
||||||
return $this->fail('缺少必要参数');
|
return $this->fail('缺少必要参数');
|
||||||
|
@ -47,6 +47,7 @@ class GpsLogic extends BaseLogic
|
|||||||
//验证请求结果
|
//验证请求结果
|
||||||
if(!empty($result['ret']) && isset($result['data'])){
|
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);
|
Cache::set('gps_token', $result['data']['token'], $this->expTime);
|
||||||
return $result['data']['token'];
|
return $result['data']['token'];
|
||||||
}else{
|
}else{
|
||||||
|
@ -20,6 +20,8 @@ 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;
|
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
|
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 {
|
public static function companyInfo():array {
|
||||||
$data = Company::field('id,company_name')->where('company_name',30)->select();
|
$data = Company::field('id,company_name')->where('company_name',30)->select();
|
||||||
if($data){
|
if($data){
|
||||||
@ -53,14 +69,9 @@ class VehicleLogic extends BaseLogic
|
|||||||
//发起合同
|
//发起合同
|
||||||
VehicleRentRecord::startTrans();
|
VehicleRentRecord::startTrans();
|
||||||
try {
|
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',[
|
$setContract = curl_post('https://worker-task.lihaink.cn/adminapi/company/initiate_contract',[
|
||||||
'token:'.$getToken['data']['token']
|
'token:'.self::getTaskToken()
|
||||||
],[
|
],[
|
||||||
'id' => $params['party_b'],
|
'id' => $params['party_b'],
|
||||||
'party_a' => $params['party_a'],
|
'party_a' => $params['party_a'],
|
||||||
@ -115,6 +126,13 @@ class VehicleLogic extends BaseLogic
|
|||||||
if(!$record){
|
if(!$record){
|
||||||
return ['code'=>0,'msg'=>'数据不存在'];
|
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();
|
VehicleRentRecord::startTrans();
|
||||||
try {
|
try {
|
||||||
if($record['rent_type'] == 1){
|
if($record['rent_type'] == 1){
|
||||||
@ -175,6 +193,14 @@ class VehicleLogic extends BaseLogic
|
|||||||
//写入数据
|
//写入数据
|
||||||
VehicleRent::update($data);
|
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::where('id',$record['id'])->update(['status'=>2,'update_time'=>time()]);
|
||||||
VehicleRentRecord::commit();
|
VehicleRentRecord::commit();
|
||||||
return ['code'=>1,'msg'=>'操作成功'];
|
return ['code'=>1,'msg'=>'操作成功'];
|
||||||
@ -186,7 +212,7 @@ class VehicleLogic extends BaseLogic
|
|||||||
|
|
||||||
public static function getCompanyCars($params):array {
|
public static function getCompanyCars($params):array {
|
||||||
$company_str = $params['company_type'] == 1 ? 'lessee_one_company_id' : 'lessee_two_company_id';
|
$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();
|
$car = Vehicle::field('license,gps_imei')->where('id',$item['car_id'])->find();
|
||||||
$item['gps_imei'] = $car['gps_imei'];
|
$item['gps_imei'] = $car['gps_imei'];
|
||||||
$item['license'] = $car['license'];
|
$item['license'] = $car['license'];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user