info
This commit is contained in:
parent
ff4ead0156
commit
abd787ff0e
@ -12,7 +12,7 @@ use think\response\Json;
|
||||
*/
|
||||
class VehicleController extends BaseApiController
|
||||
{
|
||||
public array $notNeedLogin = ['checkNum','vehicleRent','companyCarList','addVehicle','getSelfCar','getCarLocal','getCarHistory'];
|
||||
public array $notNeedLogin = ['checkNum','vehicleRent','companyCarList','addVehicle','getSelfCar','carInfo','getCarLocal','getCarHistory'];
|
||||
|
||||
|
||||
//验证租赁数量
|
||||
@ -88,14 +88,33 @@ class VehicleController extends BaseApiController
|
||||
if(empty($company_id)){
|
||||
return $this->fail('缺少必要参数');
|
||||
}
|
||||
$car = Vehicle::field('id')->where('company_id',$company_id)->where('type',1)->find();
|
||||
if($car){
|
||||
$result = Vehicle::field('id')->where('company_id',$company_id)->where('type',2)->find();
|
||||
if($result){
|
||||
return $this->success('请求成功',['has_car'=>true]);
|
||||
}else{
|
||||
return $this->success('请求成功',['has_car'=>false]);
|
||||
}
|
||||
}
|
||||
|
||||
public function carInfo():Json {
|
||||
//获取参数
|
||||
$params = $this->request->post(['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 = VehicleLogic::carInfo($params);
|
||||
//返回数据
|
||||
if($result['code'] == 1){
|
||||
return $this->success($result['msg'],$result['data']);
|
||||
}else{
|
||||
return $this->fail($result['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
//获取车辆当前位置
|
||||
public function getCarLocal():Json {
|
||||
$params = $this->request->get(['car_id']);
|
||||
|
@ -32,7 +32,7 @@ class VehicleLogic extends BaseLogic
|
||||
public static function checkNum($num):array {
|
||||
try {
|
||||
//获取数据
|
||||
$cars = Vehicle::field('id,company_id')->where('status',0)->where('type',0)->where('type',0)->limit($num)->select();
|
||||
$cars = Vehicle::field('id,company_id')->where('status',1)->where('type',1)->limit($num)->select();
|
||||
//验证数据
|
||||
if($cars->count() < $num){
|
||||
return ['code'=>0,'msg'=>'车辆数量不足'];
|
||||
@ -71,7 +71,7 @@ class VehicleLogic extends BaseLogic
|
||||
}
|
||||
$res = (new VehicleRent()) -> saveAll($data);
|
||||
//更新车辆列表中的车辆状态
|
||||
Vehicle::where('id','in',$ids)->update(['status'=>1]);
|
||||
Vehicle::where('id','in',$ids)->update(['status'=>2]);
|
||||
}elseif($param['rent_type'] == 2){
|
||||
//获取数据
|
||||
$rent = VehicleRent::where('car_id',$param['car_id'])->find();
|
||||
@ -117,12 +117,13 @@ class VehicleLogic extends BaseLogic
|
||||
$companyName = $params['company_name'] ?? '';
|
||||
$rent = VehicleRent::alias('r')
|
||||
->leftJoin('vehicle v','r.car_id = v.id')
|
||||
->field('r.*,v.license')
|
||||
->field('r.*,v.license,v.type')
|
||||
->where('r.lessee_one_company_id',$params['company_id'])
|
||||
->where('r.lessee_two_flag',$lessee_two_flag)
|
||||
->where('v.license','like','%'.$license.'%')
|
||||
->where('v.lessee_two_company_name','like','%'.$companyName.'%')
|
||||
->where('r.lessee_two_company_name','like','%'.$companyName.'%')
|
||||
->page($pageNo,$pageSize)->order('r.lessee_one_start_time desc,r.car_id desc')->select()->each(function ($item){
|
||||
//todo
|
||||
$item['mileage'] = 10.0;
|
||||
return $item;
|
||||
});
|
||||
@ -145,10 +146,10 @@ class VehicleLogic extends BaseLogic
|
||||
'license' => $params['license'],
|
||||
'gps_imei' => '',
|
||||
'gps_carid' => 0,
|
||||
'type' => 1,
|
||||
'status' => 0,
|
||||
'is_check' => 0,
|
||||
'is_del' => 0,
|
||||
'type' => 2,
|
||||
'status' => 1,
|
||||
'is_check' => 1,
|
||||
'is_del' => 1,
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
]);
|
||||
@ -159,6 +160,64 @@ class VehicleLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
public static function carInfo($params):array {
|
||||
//判断车辆类型
|
||||
if($params['car_type'] == 1){
|
||||
//租赁车辆
|
||||
$rent = VehicleRent::field('lessee_one_company,lessee_one_user,lessee_one_phone,lessee_one_start_time,lessee_two_company_id,lessee_two_user,lessee_two_phone,lessee_two_start_time,lessee_two_flag')->where('car_id',$params['car_id'])->find();
|
||||
$info = Vehicle::field('id,license,type,gps_carid')->where('id',$params['car_id'])->find();
|
||||
if($rent && $info){
|
||||
$data['lessee_one_company'] = $rent['lessee_one_company'];
|
||||
$data['lessee_one_user'] = $rent['lessee_one_user'];
|
||||
$data['lessee_one_phone'] = $rent['lessee_one_phone'];
|
||||
$data['lessee_one_start_time'] = $rent['lessee_one_start_time'];
|
||||
$data['lessee_two_company_id'] = $rent['lessee_two_company_id'];
|
||||
$data['lessee_two_company_name'] = $rent['lessee_two_company_name'];
|
||||
$data['lessee_two_user'] = $rent['lessee_two_user'];
|
||||
$data['lessee_two_phone'] = $rent['lessee_two_phone'];
|
||||
$data['lessee_two_start_time'] = $rent['lessee_two_start_time'];
|
||||
$data['lessee_two_flag'] = $rent['lessee_two_flag'];
|
||||
$data['id'] = $info['id'];
|
||||
$data['license'] = $info['license'];
|
||||
$data['type'] = $info['type'];
|
||||
$local = (new GpsLogic()) -> status($info['gps_carid']);
|
||||
if($local['code'] == 1){
|
||||
$data['lat'] = $local['data']['carStatus']['latc'];
|
||||
$data['lon'] = $local['data']['carStatus']['lonc'];
|
||||
}else{
|
||||
$data['lat'] = '';
|
||||
$data['lon'] = '';
|
||||
}
|
||||
//todo 获取里程
|
||||
$data['mileage'] = 10;
|
||||
return ['code'=>1,'msg'=>'请求成功','data'=>$data];
|
||||
}else{
|
||||
return ['code'=>0,'msg'=>'请求失败'];
|
||||
}
|
||||
}elseif($params['car_type'] == 2){
|
||||
//自有车辆
|
||||
$data = Vehicle::field('id,company_id,license,type')->where('id',$params['car_id'])->where('type',2)->find();
|
||||
//获取车辆当前位置
|
||||
if($data){
|
||||
$local = (new GpsLogic()) -> status($data['gps_carid']);
|
||||
if($local['code'] == 1){
|
||||
$data['lat'] = $local['data']['carStatus']['latc'];
|
||||
$data['lon'] = $local['data']['carStatus']['lonc'];
|
||||
}else{
|
||||
$data['lat'] = '';
|
||||
$data['lon'] = '';
|
||||
}
|
||||
//todo 获取里程
|
||||
$data['mileage'] = 10;
|
||||
return ['code'=>1,'msg'=>'请求成功','data'=>$data->toArray()];
|
||||
}else{
|
||||
return ['code'=>0,'msg'=>'请求失败'];
|
||||
}
|
||||
}else{
|
||||
return ['code'=>0,'msg'=>'参数错误'];
|
||||
}
|
||||
}
|
||||
|
||||
public static function getCarLocal($params):array {
|
||||
$car = Vehicle::field('gps_carid')->where('id',$params['car_id'])->find();
|
||||
if(!$car){
|
||||
|
@ -31,4 +31,5 @@ Route::rule('getCarLocal','Vehicle/getCarLocal','get');
|
||||
Route::rule('getCarHistory','Vehicle/getCarHistory','get');
|
||||
Route::rule('companyCarList','Vehicle/companyCarList','post');
|
||||
Route::rule('addVehicle','Vehicle/addVehicle','post');
|
||||
Route::rule('getSelfCar','Vehicle/getSelfCar','post');
|
||||
Route::rule('getSelfCar','Vehicle/getSelfCar','post');
|
||||
Route::rule('carInfo','Vehicle/carInfo','post');
|
Loading…
x
Reference in New Issue
Block a user