common\services\NotificationService::newActionNotify PHP Method

newActionNotify() public method

点赞和其他动作通知
public newActionNotify ( $type, $fromUserId, $toUserId, Post $post, PostComment $comment = null )
$type
$fromUserId
$toUserId
$post common\models\Post
$comment common\models\PostComment
    public function newActionNotify($type, $fromUserId, $toUserId, Post $post, PostComment $comment = null)
    {
        $model = new Notification();
        $model->setAttributes(['from_user_id' => $fromUserId, 'user_id' => $toUserId, 'post_id' => $post->id, 'comment_id' => $comment ? $comment->id : 0, 'data' => $comment ? $comment->comment : $post->content, 'type' => $type]);
        if ($model->save()) {
            User::updateAllCounters(['notification_count' => 1], ['id' => $toUserId]);
        } else {
            throw new Exception(array_values($model->getFirstErrors())[0]);
        }
    }