优化更新

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

@@ -86,16 +86,31 @@ class NotificationService
*
* @param int $userId
* @param int $limit
* @param int $page
* @param string|null $type
* @return array
*/
public function getUnreadNotifications(int $userId, int $limit = 10): array
public function getUnreadNotifications(int $userId, int $limit = 10, int $page = 1, ?string $type = null): array
{
return Notification::where('user_id', $userId)
->where('is_read', false)
->orderBy('created_at', 'desc')
->limit($limit)
->get()
->toArray();
$query = Notification::where('user_id', $userId)
->where('is_read', false);
// 按类型过滤
if (!empty($type)) {
$query->where('type', $type);
}
$query->orderBy('created_at', 'desc');
// 分页处理
$list = $query->paginate($limit, ['*'], 'page', $page);
return [
'list' => $list->items(),
'total' => $list->total(),
'page' => $list->currentPage(),
'page_size' => $list->perPage(),
];
}
/**