优化更新
This commit is contained in:
@@ -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(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user