feat: add user notification center
This commit is contained in:
@@ -18,6 +18,7 @@ use app\common\service\ai\AiService;
|
||||
use app\common\service\ai\KbSyncService;
|
||||
use app\common\service\chat\PrivateChatService;
|
||||
use app\common\service\FileService;
|
||||
use app\common\service\notice\UserNoticeService;
|
||||
use app\common\service\VipService;
|
||||
use think\facade\Db;
|
||||
|
||||
@@ -416,6 +417,19 @@ class CommunityController extends BaseApiController
|
||||
// 更新帖子评论数
|
||||
CommunityPost::where('id', $postId)->inc('comment_count')->update();
|
||||
|
||||
if ($parentId > 0) {
|
||||
$parentComment = CommunityComment::where('id', $parentId)
|
||||
->where('post_id', $postId)
|
||||
->where('status', 1)
|
||||
->findOrEmpty();
|
||||
$recipientUserId = $replyUserId > 0 ? $replyUserId : (int) ($parentComment->user_id ?? 0);
|
||||
if (!$parentComment->isEmpty()) {
|
||||
UserNoticeService::commentReply($recipientUserId, $this->userId, $postId, (int) $comment->id, $content);
|
||||
}
|
||||
} else {
|
||||
UserNoticeService::postComment((int) $post->user_id, $this->userId, $postId, (int) $comment->id, $content);
|
||||
}
|
||||
|
||||
return $this->data(['id' => $comment->id]);
|
||||
}
|
||||
|
||||
@@ -495,6 +509,11 @@ class CommunityController extends BaseApiController
|
||||
return $this->fail('不能关注自己');
|
||||
}
|
||||
|
||||
$followUser = User::where('id', $followUserId)->findOrEmpty();
|
||||
if ($followUser->isEmpty()) {
|
||||
return $this->fail('用户不存在');
|
||||
}
|
||||
|
||||
$exists = CommunityFollow::where([
|
||||
'user_id' => $this->userId,
|
||||
'follow_user_id' => $followUserId
|
||||
@@ -506,6 +525,7 @@ class CommunityController extends BaseApiController
|
||||
'follow_user_id' => $followUserId,
|
||||
'create_time' => time(),
|
||||
]);
|
||||
UserNoticeService::followed($followUserId, $this->userId);
|
||||
return $this->data(['is_followed' => true]);
|
||||
} else {
|
||||
$exists->delete();
|
||||
@@ -1079,6 +1099,7 @@ class CommunityController extends BaseApiController
|
||||
|
||||
$userPoints = User::where('id', $userId)->value('user_points') ?: 0;
|
||||
$chatUnreadCount = PrivateChatService::unreadCount($userId);
|
||||
$noticeUnreadCount = UserNoticeService::unreadCount($userId);
|
||||
|
||||
return $this->data([
|
||||
'post_count' => $postCount,
|
||||
@@ -1087,6 +1108,8 @@ class CommunityController extends BaseApiController
|
||||
'collect_count' => $collectCount,
|
||||
'user_points' => $userPoints,
|
||||
'chat_unread_count' => $chatUnreadCount,
|
||||
'notice_unread_count' => $noticeUnreadCount,
|
||||
'message_unread_count' => $chatUnreadCount + $noticeUnreadCount,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user