1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-26 20:52:44 +08:00
2021-05-12 20:41:24 +08:00

49 lines
1.3 KiB
PHP

<?php
namespace App\Services\Logic\Notice\System;
use App\Models\Comment as CommentModel;
use App\Models\Notification as NotificationModel;
use App\Repos\Article as ArticleRepo;
use App\Repos\User as UserRepo;
use App\Services\Logic\Service as LogicService;
class ArticleCommented extends LogicService
{
public function handle(CommentModel $comment)
{
$commentContent = kg_substr($comment->content, 0, 32);
$article = $this->findArticle($comment->item_id);
$notification = new NotificationModel();
$notification->sender_id = $comment->owner_id;
$notification->receiver_id = $article->owner_id;
$notification->event_id = $comment->id;
$notification->event_type = NotificationModel::TYPE_ARTICLE_COMMENTED;
$notification->event_info = [
'article' => ['id' => $article->id, 'title' => $article->title],
'comment' => ['id' => $comment->id, 'content' => $commentContent],
];
$notification->create();
}
protected function findArticle($id)
{
$articleRepo = new ArticleRepo();
return $articleRepo->findById($id);
}
protected function findUser($id)
{
$userRepo = new UserRepo();
return $userRepo->findById($id);
}
}