/** * 赞话题和评论 * @param $type * @param $id * @return array|string * @throws NotFoundHttpException */ public function actionLike($type, $id) { switch ($type) { case 'topic': $topicService = new TopicService(); list($result, $data) = $topicService->userDoAction($id, 'like'); break; case 'tweet': $tweetService = new TweetService(); list($result, $data) = $tweetService->userDoAction($id, 'like'); break; case 'comment': $commentService = new CommentService(); list($result, $data) = $commentService->userDoAction($id, 'like'); break; default: throw new NotFoundHttpException(); break; } if ($result) { return $this->message('提交成功!', 'success'); } else { return $this->message($data ? $data->getErrors() : '提交失败!'); } }