Esempio n. 1
0
 public function actionAddComment()
 {
     try {
         $post = Yii::$app->getRequest()->post();
         if (empty($post['id'])) {
             throw new \Exception('获取页面数据丢失');
         }
         if (!$this->findModel($post['id'])) {
             throw new \Exception('日记信息异常');
         }
         $DiaryComment = new DiaryComment();
         $DiaryComment->diary_id = $post['id'];
         $DiaryComment->comment_id = isset($post['comment_id']) ? $post['comment_id'] : 0;
         $DiaryComment->comment_type = isset($post['comment_type']) ? $post['comment_type'] : 0;
         $DiaryComment->user_id = Yii::$app->getUser()->getId();
         $DiaryComment->comment_content = $post['comment_content'];
         $DiaryComment->status = 1;
         $DiaryComment->created_at = date('Y-m-d H:i:s');
         $DiaryComment->save();
         $error = $DiaryComment->getErrors();
     } catch (\Exception $exp) {
         Yii::$app->getSession()->setFlash('error', $exp->getMessage());
     }
     return $this->redirect(['view', 'id' => $post['id']]);
 }
 public function getUserResponse($userId)
 {
     $Query = (new Query())->select('b.comment_content,b.created_at')->addSelect('c.username')->addSelect('c.realname')->addSelect('d.avatar')->from(Diary::tableName() . ' as a')->leftJoin(['b' => DiaryComment::tableName()], 'b.diary_id = a.id')->leftJoin(['c' => User::tableName()], 'b.user_id = c.id')->leftJoin(['d' => UserExtend::tableName()], 'd.user_id = c.id')->where('1=1')->andFilterWhere(['a.created_by' => $userId])->andFilterWhere(['b.comment_id' => 0])->andFilterWhere(['b.comment_type' => 0])->orderBy(['b.created_at' => SORT_DESC])->limit(10);
     $result = $Query->createCommand()->queryAll();
     return $result;
 }
 public function getComment($operateId)
 {
     $query = (new Query())->select('a.*')->addSelect('b.username as username')->addSelect('c.avatar')->from(DiaryComment::tableName() . ' as a')->leftJoin(['b' => User::tableName()], 'a.user_id = b.id')->leftJoin(['c' => UserExtend::tableName()], 'a.user_id = c.user_id')->where('1=1')->andWhere(['a.diary_id' => $operateId])->orderBy(['a.created_at' => SORT_ASC]);
     return $query->createCommand()->queryAll();
 }
Esempio n. 4
0
 /**
  * Deletes an existing Diary model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $this->findModel($id)->delete();
     DiaryContent::deleteAll('diary_id = :diary_id', [':diary_id' => $id]);
     DiaryComment::deleteAll('diary_id = :diary_id', [':diary_id' => $id]);
     // 推荐队列
     RecommendQueue::deleteDiaryById($id);
     $result = ['statusCode' => '200', 'message' => '操作成功', 'navTabId' => 'diary_diary_index_id', 'forwardUrl' => '', 'callbackType' => ''];
     echo Json::encode($result);
 }