Inheritance: extends PostService
Esempio n. 1
0
 /**
  * 赞话题和评论
  * @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() : '提交失败!');
     }
 }
Esempio n. 2
0
 /**
  * 伪删除
  * @param $id
  * @return \yii\web\Response
  * @throws NotFoundHttpException
  */
 public function actionDelete($id)
 {
     $model = Tweet::findTweet($id);
     if (!$model->isCurrent()) {
         throw new NotFoundHttpException();
     }
     if ($model->comment_count) {
         $this->flash("已有评论,属于共有财产,不能删除", 'warning');
     } else {
         TweetService::delete($model);
         $this->flash("删除成功。 ", 'success');
     }
     return $this->redirect(['index']);
 }