request->get(['num']); if(empty($param['num'])){ return $this->fail('缺少必要参数'); } if(!intval($param['num'])){ return $this->fail('参数格式错误'); } $result = VehicleLogic::checkNum($param['num']); //返回数据 if($result['code'] == 1){ return $this->success($result['msg'],$result['data']); }else{ return $this->fail($result['msg']); } } public function vehicleRent():Json { //获取参数 $param = $this->request->post(['contract_id','car_id','company_id','company_name','company_user_id','company_user_name','company_user_phone','rent_type']); if(empty($param['contract_id']) || empty($param['car_id']) || empty($param['company_id']) || empty($param['company_name']) || empty($param['company_user_id']) || empty($param['company_user_name']) || empty($param['company_user_phone']) || empty($param['rent_type'])){ return $this->fail('缺少必要参数'); } //获取数据 $result = VehicleLogic::setRent($param); //返回数据 if($result['code'] == 1){ return $this->success($result['msg']); }else{ return $this->fail($result['msg']); } } public function companyCarList():Json { //获取参数 $params = $this->request->post(['company_id','is_rent','license','company_name','page_no','page_size']); //验证参数 if(empty($params['company_id']) || empty($params['is_rent'])){ return $this->fail('缺少必要参数'); } //获取数据 $result = VehicleLogic::companyCarList($params); //返回数据 if($result['code'] == 1){ return $this->success($result['msg'],$result['data']); }else{ return $this->fail($result['msg']); } } public function addVehicle():Json { //获取参数 $params = $this->request->post(['company_id','license']); if(empty($params['company_id']) || empty($params['license'])){ return $this->fail('缺少必要参数'); } $result = VehicleLogic::addVehicle($params); //返回数据 if($result['code'] == 1){ return $this->success($result['msg']); }else{ return $this->fail($result['msg']); } } public function getSelfCar():Json { //获取参数 $company_id = $this->request->post('company_id'); if(empty($company_id)){ return $this->fail('缺少必要参数'); } $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']); if(empty($params['car_id'])){ return $this->fail('缺少必要参数'); } $result = VehicleLogic::getCarLocal($params); //返回数据 if($result['code'] == 1){ return $this->success($result['msg'],$result['data']); }else{ return $this->fail($result['msg']); } } public function getCarHistory():Json { //获取参数 $params = $this->request->get(['car_id','start_time','end_time']); //验证参数 if(empty($params['car_id']) || empty($params['start_time']) || empty($params['end_time'])){ return $this->fail('缺少必要参数'); } //验证时间格式 if(!checkDateIsValid($params['start_time'],['Y-m-d H:i:s']) || !checkDateIsValid($params['end_time'],['Y-m-d H:i:s'])) { return $this->fail('日期格式错误'); } //获取数据 $result = VehicleLogic::getCarHistory($params); //返回数据 if($result['code'] == 1){ return $this->success($result['msg'],$result['data']); }else{ return $this->fail($result['msg']); } } }