public function beforeSave($insert)
{
if ($insert) {
$userActionNotify = (new NotificationService())->findUserActionNotify($this);
if ($userActionNotify) {
$userActionNotify->delete();
}
// 点赞、感谢和收藏会收到通知
if (in_array($this->type, ['like', 'favorite', 'thanks'])) {
switch ($this->target_type) {
case 'topic':
(new NotificationService())->newActionNotify($this->target_type . '_' . $this->type, Yii::$app->user->id, $this->topic->user_id, $this->topic);
break;
case 'tweet':
(new NotificationService())->newActionNotify($this->target_type . '_' . $this->type, Yii::$app->user->id, $this->tweet->user_id, $this->tweet);
break;
case 'comment':
(new NotificationService())->newActionNotify($this->target_type . '_' . $this->type, Yii::$app->user->id, $this->comment->user_id, $this->comment->topic, $this->comment);
break;
default:
break;
}
}
}
return parent::beforeSave($insert);
}