优化更新

This commit is contained in:
2026-02-18 22:28:08 +08:00
parent b6c133952b
commit 0ecb088569
8 changed files with 107 additions and 38 deletions

View File

@@ -89,12 +89,28 @@ class Permission extends Controller
'type' => 'required|in:menu,api,button',
'route' => 'nullable|string|max:200',
'component' => 'nullable|string|max:200',
'parent_id' => 'nullable|integer|exists:auth_permissions,id',
'parent_id' => 'nullable|integer|min:0',
'sort' => 'nullable|integer|min:0',
'status' => 'nullable|integer|in:0,1',
'meta' => 'nullable|array',
], [], [
'parent_id.exists' => '父级权限不存在',
]);
// 额外验证:如果 parent_id 不为 0则必须存在
if (!empty($validated['parent_id']) && $validated['parent_id'] != 0) {
$parent = \App\Models\Auth\Permission::find($validated['parent_id']);
if (!$parent) {
return response()->json([
'code' => 422,
'message' => '验证失败',
'data' => [
'parent_id' => ['父级权限不存在']
]
], 422);
}
}
$result = $this->permissionService->create($validated);
return response()->json([
@@ -115,12 +131,28 @@ class Permission extends Controller
'type' => 'nullable|in:menu,api,button',
'route' => 'nullable|string|max:200',
'component' => 'nullable|string|max:200',
'parent_id' => 'nullable|integer|exists:auth_permissions,id',
'parent_id' => 'nullable|integer|min:0',
'sort' => 'nullable|integer|min:0',
'status' => 'nullable|integer|in:0,1',
'meta' => 'nullable|array',
], [], [
'parent_id.exists' => '父级权限不存在',
]);
// 额外验证:如果 parent_id 不为 0则必须存在
if (isset($validated['parent_id']) && !empty($validated['parent_id']) && $validated['parent_id'] != 0) {
$parent = \App\Models\Auth\Permission::find($validated['parent_id']);
if (!$parent) {
return response()->json([
'code' => 422,
'message' => '验证失败',
'data' => [
'parent_id' => ['父级权限不存在']
]
], 422);
}
}
$result = $this->permissionService->update($id, $validated);
return response()->json([

View File

@@ -55,16 +55,16 @@ class Notification extends Controller
public function unread(Request $request): JsonResponse
{
$userId = auth('admin')->id();
$limit = $request->input('limit', 10);
$limit = $request->input('limit', $request->input('page_size', 10));
$page = $request->input('page', 1);
$type = $request->input('type');
$notifications = $this->notificationService->getUnreadNotifications($userId, $limit);
$result = $this->notificationService->getUnreadNotifications($userId, $limit, $page, $type);
return response()->json([
'code' => 200,
'message' => 'success',
'data' => [
'list' => $notifications
]
'data' => $result
]);
}