From d4f018f4c54a62bef55a7c41f87c48902ba02dde Mon Sep 17 00:00:00 2001 From: unknown <736250432@qq.com> Date: Thu, 31 Aug 2023 09:33:37 +0800 Subject: [PATCH] update --- app/api/controller/VehicleController.php | 33 +++++++++++++++++++++--- app/api/route/app.php | 3 ++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/api/controller/VehicleController.php b/app/api/controller/VehicleController.php index e821d4e8..0f0be707 100644 --- a/app/api/controller/VehicleController.php +++ b/app/api/controller/VehicleController.php @@ -4,7 +4,6 @@ namespace app\api\controller; use app\api\logic\VehicleLogic; use app\common\model\vehicle\Vehicle; use app\common\model\vehicle\VehicleRent; -use app\common\model\vehicle\VehicleUser; use think\facade\Db; use think\response\Json; @@ -15,7 +14,7 @@ use think\response\Json; */ class VehicleController extends BaseApiController { - public array $notNeedLogin = ['getCarLocal','getCarHistory','addSelfCar']; + public array $notNeedLogin = ['getCarLocal','getCarHistory','addSelfCar','updateVehicleRent']; //获取车辆当前位置 public function getCarLocal():Json { @@ -63,6 +62,11 @@ class VehicleController extends BaseApiController } Db::startTrans(); try { + //获取数据 + $vehicle = Vehicle::where('license',$params['license'])->find(); + if(!empty($vehicle)){ + return $this->fail('该车牌号的车辆已存在'); + } //写入数据 $vehicle = Vehicle::create([ 'license' => $params['license'], @@ -76,7 +80,7 @@ class VehicleController extends BaseApiController 'car_id'=> $vehicle->id, 'company_id' => $params['company_id'], 'company_name' => $params['company_name'], - 'company_user' => $params['company_a_user'], + 'company_user' => $params['company_user'], 'company_phone' => $params['company_phone'], ]); if($vehicle->id && $vehicleRent->id){ @@ -92,4 +96,27 @@ class VehicleController extends BaseApiController } } + + public function updateVehicleRent(){ + //获取参数 + $params = $this->request->post(['car_id','use_user_id','use_user_name','use_user_phone']); + if(empty($params['car_id']) || empty($params['use_user_id']) || empty($params['use_user_name']) || empty($params['use_user_phone'])){ + return false; + } + //更新 + $vehicleRent = VehicleRent::where('car_id',$params['car_id'])->find(); + if(empty($vehicleRent)){ + return false; + } + $result = VehicleRent::where('car_id',$params['car_id'])->update([ + 'use_user_id' => $params['use_user_id'], + 'use_user_name' => $params['use_user_name'], + 'use_user_phone' => $params['use_user_phone'], + ]); + if($result){ + return true; + }else{ + return false; + } + } } diff --git a/app/api/route/app.php b/app/api/route/app.php index 33da897e..d16b3e68 100755 --- a/app/api/route/app.php +++ b/app/api/route/app.php @@ -27,7 +27,8 @@ Route::rule('hasCourier','Logistics/hasCourier','get'); /*-------------------------------------------------------------------------------------------*/ Route::rule('getCarLocal','Vehicle/getCarLocal','get'); Route::rule('getCarHistory','Vehicle/getCarHistory','get'); -Route::rule('addSelfCar','Contract/addSelfCar','post'); +Route::rule('addSelfCar','Vehicle/addSelfCar','post'); +Route::rule('updateVehicleRent','Vehicle/updateVehicleRent','post'); /*-------------------------------------------------------------------------------------------*/