From b6bbd25203af74808ec25c8bb7a02f9b18f6be77 Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Wed, 10 Sep 2025 10:12:11 +0800 Subject: [PATCH] update --- app/Http/Controllers/GateController.php | 77 +++++++++++++++++-------- lang/en/gate.php | 1 + lang/zh_CN/gate.php | 1 + routes/api.php | 5 +- 4 files changed, 59 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/GateController.php b/app/Http/Controllers/GateController.php index cdedb6f..58a08d6 100644 --- a/app/Http/Controllers/GateController.php +++ b/app/Http/Controllers/GateController.php @@ -25,6 +25,25 @@ class GateController extends Controller { use ApiResponse; + /** + * @OA\Get( + * path="/api/admin/gate/user-list", + * tags={"门岗端接口"}, + * summary="门岗用户列表", + * description="", + * @OA\Response( + * response="200", + * description="暂无" + * ) + * ) + */ + public function uerList() + { + $admin = Admin::whereHas('role', function ($query) { + $query->where('name', 'like', '%门岗%'); + })->get(); + return $this->success($admin); + } /** * @OA\Get( @@ -35,7 +54,7 @@ class GateController extends Controller * @OA\Parameter(name="date", in="query", @OA\Schema(type="string"), required=false, description="查询日期,格式:Y-m-d,默认今天"), * @OA\Parameter(name="status", in="query", @OA\Schema(type="string"), required=false, description="状态筛选:1通过(待进厂)3已进厂4已离厂"), * @OA\Parameter(name="type", in="query", @OA\Schema(type="string"), required=false, description="类型筛选:1访客2访客车辆3物流车辆"), - * @OA\Parameter(name="keyword", in="query", @OA\Schema(type="string"), required=false, description="关键词搜索(姓名、手机号、车牌号)"), + * @OA\Parameter(name="keyword", in="query", @OA\Schema(type="string"), required=false, description="关键词搜索(人牌,身份证,核销码)"), * @OA\Parameter(name="page", in="query", @OA\Schema(type="integer"), required=false, description="页码,默认1"), * @OA\Parameter(name="page_size", in="query", @OA\Schema(type="integer"), required=false, description="每页数量,默认20"), * @OA\Response( @@ -88,10 +107,9 @@ class GateController extends Controller // 关键词搜索 if ($keyword) { $query->where(function ($q) use ($keyword) { - $q->where('name', 'like', "%{$keyword}%") - ->orWhere('mobile', 'like', "%{$keyword}%") - ->orWhere('plate', 'like', "%{$keyword}%") - ->orWhere('code', 'like', "%{$keyword}%"); + $q->where('person_no', "{$keyword}") + ->orWhere('idcard', "{$keyword}") + ->orWhere('code', "{$keyword}"); }); } @@ -106,12 +124,17 @@ class GateController extends Controller } /** - * @OA\Get( - * path="/api/gate/visits/{id}", + * @OA\Post( + * path="/api/gate/visits/detail", * tags={"门岗端接口"}, * summary="拜访详情信息", * description="获取指定拜访的详细信息", - * @OA\Parameter(name="id", in="path", @OA\Schema(type="integer"), required=true, description="拜访ID"), + * @OA\RequestBody( + * required=true, + * @OA\JsonContent( + * @OA\Property(property="id", type="integer", description="拜访ID") + * ) + * ), * @OA\Response( * response="200", * description="成功获取拜访详情", @@ -123,9 +146,15 @@ class GateController extends Controller * ) * ) */ - public function visitDetail($id) + public function visitDetail(Request $request) { try { + $id = $request->input('id'); + + if (!$id) { + return $this->fail([ResponseCode::ERROR_PARAMETER, __('gate.visit_id_required')]); + } + $visit = Visit::with([ 'visitArea', 'visitTime', @@ -151,14 +180,14 @@ class GateController extends Controller /** * @OA\Post( - * path="/api/gate/visits/{id}/update", + * path="/api/gate/visits/update", * tags={"门岗端接口"}, * summary="更新拜访信息", * description="门岗端更新拜访信息(绑定ID卡、修改状态、上传货车图片等)", - * @OA\Parameter(name="id", in="path", @OA\Schema(type="integer"), required=true, description="拜访ID"), * @OA\RequestBody( * required=true, * @OA\JsonContent( + * @OA\Property(property="id", type="integer", description="拜访ID"), * @OA\Property(property="action", type="string", description="操作类型:bind_card绑定ID卡,enter进厂,leave离厂,upload_vehicle上传货车图片"), * @OA\Property(property="person_no", type="string", description="人牌号(绑定ID卡时必填)"), * @OA\Property(property="car_no", type="string", description="停车牌号(绑定ID卡时必填)"), @@ -177,9 +206,15 @@ class GateController extends Controller * ) * ) */ - public function updateVisit(Request $request, $id) + public function updateVisit(Request $request) { try { + $id = $request->input('id'); + + if (!$id) { + return $this->fail([ResponseCode::ERROR_PARAMETER, __('gate.visit_id_required')]); + } + $visit = Visit::find($id); if (!$visit) { return $this->fail([ResponseCode::ERROR_BUSINESS, __('gate.visit_not_found')]); @@ -318,10 +353,7 @@ class GateController extends Controller * summary="核销", * description="", * @OA\Parameter(name="admin_id", in="query", @OA\Schema(type="string"), required=false, description="管理员id"), - * @OA\Parameter(name="code", in="query", @OA\Schema(type="string"), required=false, description="编码(二选一)"), - * @OA\Parameter(name="idcard", in="query", @OA\Schema(type="string"), required=false, description="身份证(二选一)"), - * @OA\Parameter(name="car_no", in="query", @OA\Schema(type="string"), required=false, description="停车牌"), - * @OA\Parameter(name="person_no", in="query", @OA\Schema(type="string"), required=false, description="人牌"), + * @OA\Parameter(name="keyword", in="query", @OA\Schema(type="string"), required=false, description="关键词(人牌,身份证,核销码)"), * @OA\Parameter(name="type", in="query", @OA\Schema(type="string"), required=false, description="1进厂2离厂"), * @OA\Response( * response="200", @@ -333,10 +365,12 @@ class GateController extends Controller { $all = \request()->all(); $messages = [ + 'keyword.required' => __('关键词'), 'type.required' => __('gate.validation.type_required'), 'admin_id.required' => __('gate.validation.admin_id_required') ]; $validator = Validator::make($all, [ + 'keyword' => 'required', 'type' => 'required', 'admin_id' => 'required' ], $messages); @@ -348,13 +382,10 @@ class GateController extends Controller if (empty($idcard) && empty($code)) { return $this->fail([ResponseCode::ERROR_PARAMETER, __('gate.validation.code_or_idcard_required')]); } - $check = Visit::where(function ($query) use ($idcard, $code) { - if (!empty($idcard)) { - $query->where('idcard', $idcard); - } - if (!empty($code)) { - $query->where('code', $code); - } + $check = Visit::where(function ($query) use ($all) { + $query->where('person_no', "{$all['keyword']}") + ->orWhere('idcard', "{$all['keyword']}") + ->orWhere('code', "{$all['keyword']}"); })->first(); if (empty($check)) { return $this->fail([ResponseCode::ERROR_BUSINESS, __('gate.business.visit_not_found')]); diff --git a/lang/en/gate.php b/lang/en/gate.php index d4dec59..94e60c5 100644 --- a/lang/en/gate.php +++ b/lang/en/gate.php @@ -15,6 +15,7 @@ return [ ], // Direct keys (for compatibility with existing code) 'visit_not_found' => 'Visit record not found', + 'visit_id_required' => 'Visit ID is required', 'get_visit_list_failed' => 'Failed to get visit list', 'get_visit_detail_failed' => 'Failed to get visit detail', 'person_no_required' => 'Person number is required', diff --git a/lang/zh_CN/gate.php b/lang/zh_CN/gate.php index e497abc..bd7ca68 100644 --- a/lang/zh_CN/gate.php +++ b/lang/zh_CN/gate.php @@ -15,6 +15,7 @@ return [ ], // 直接键名(为了兼容现有代码) 'visit_not_found' => '拜访记录不存在', + 'visit_id_required' => '拜访ID必填', 'get_visit_list_failed' => '获取拜访列表失败', 'get_visit_detail_failed' => '获取拜访详情失败', 'person_no_required' => '人牌号必填', diff --git a/routes/api.php b/routes/api.php index 8c4e47d..aa86440 100644 --- a/routes/api.php +++ b/routes/api.php @@ -23,11 +23,12 @@ Route::any('test', [\App\Http\Controllers\Admin\OtherController::class, "test"]) // 门岗端接口路由组(无需鉴权,但支持多语言) Route::prefix('gate')->middleware(['set.locale'])->group(function () { + Route::get("user-list", [\App\Http\Controllers\GateController::class, "uerList"]); Route::get('visits', [\App\Http\Controllers\GateController::class, 'visits']); - Route::get('visits/{id}', [\App\Http\Controllers\GateController::class, 'visitDetail']); + Route::post('visits/detail', [\App\Http\Controllers\GateController::class, 'visitDetail']); Route::get("visits/use-code", [\App\Http\Controllers\GateController::class, "useCode"]); - Route::post('visits/{id}/update', [\App\Http\Controllers\GateController::class, 'updateVisit']); + Route::post('visits/update', [\App\Http\Controllers\GateController::class, 'updateVisit']); }); // 后台管理接口路由组(支持多语言)