From 3427e6cae21184708dd953ca40bfdfa15435c63b Mon Sep 17 00:00:00 2001 From: unknown <736250432@qq.com> Date: Sat, 26 Aug 2023 14:03:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E6=9C=89=E8=BD=A6?= =?UTF-8?q?=E8=BE=86=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/VehicleController.php | 17 +++++++++++++- app/api/logic/VehicleLogic.php | 28 +++++++++++++++++++++++- app/api/route/app.php | 1 + 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/app/api/controller/VehicleController.php b/app/api/controller/VehicleController.php index 27a440b4..8566ac53 100644 --- a/app/api/controller/VehicleController.php +++ b/app/api/controller/VehicleController.php @@ -11,7 +11,7 @@ use think\response\Json; */ class VehicleController extends BaseApiController { - public array $notNeedLogin = ['checkNum','vehicleRent','companyCarList','getCarLocal','getCarHistory']; + public array $notNeedLogin = ['checkNum','vehicleRent','companyCarList','addVehicle','getCarLocal','getCarHistory']; //验证租赁数量 @@ -66,6 +66,21 @@ class VehicleController extends BaseApiController } } + 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 getCarLocal():Json { $params = $this->request->get(['car_id']); diff --git a/app/api/logic/VehicleLogic.php b/app/api/logic/VehicleLogic.php index dd178691..3a7c3677 100644 --- a/app/api/logic/VehicleLogic.php +++ b/app/api/logic/VehicleLogic.php @@ -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)->limit($num)->select(); + $cars = Vehicle::field('id,company_id')->where('status',0)->where('type',0)->where('type',0)->limit($num)->select(); //验证数据 if($cars->count() < $num){ return ['code'=>0,'msg'=>'车辆数量不足']; @@ -133,6 +133,32 @@ class VehicleLogic extends BaseLogic } } + public static function addVehicle($params):array { + //获取车辆 + $vehicle = Vehicle::where('company_id',$params['company_id'])->where('license',$params['license'])->find(); + if($vehicle){ + return ['code'=>0,'msg'=>'该公司已添加车辆']; + } + //创建 + $result = Vehicle::create([ + 'company_id' => $params['company_id'], + 'license' => $params['license'], + 'gps_imei' => '', + 'gps_carid' => 0, + 'type' => 1, + 'status' => 0, + 'is_check' => 0, + 'is_del' => 0, + 'create_time' => time(), + 'update_time' => time(), + ]); + if($result){ + return ['code'=>1,'msg'=>'添加成功,等待审核']; + }else{ + return ['code'=>1,'msg'=>'添加失败']; + } + } + public static function getCarLocal($params):array { $car = Vehicle::field('gps_carid')->where('id',$params['car_id'])->find(); if(!$car){ diff --git a/app/api/route/app.php b/app/api/route/app.php index 83b83e49..a6d04ce5 100755 --- a/app/api/route/app.php +++ b/app/api/route/app.php @@ -30,3 +30,4 @@ Route::rule('vehicleRent','Vehicle/vehicleRent','post'); Route::rule('getCarLocal','Vehicle/getCarLocal','get'); Route::rule('getCarHistory','Vehicle/getCarHistory','get'); Route::rule('companyCarList','Vehicle/companyCarList','post'); +Route::rule('addVehicle','Vehicle/addVehicle','post'); \ No newline at end of file