Example #1
0
 public function index()
 {
     //var_dump($_SESSION['qq']);
     $articleId = $_GET['articleId'];
     $article = new ArticleModel();
     $content = $article->getArticleById($articleId);
     $collect = new CollectModel();
     $comment = new CommentModel();
     $commentNum = $comment->getCommentCountByArticleId($articleId);
     $content['commentNum'] = $commentNum;
     if ($this->isLogin()) {
         if ($collect->getCollects($article, $_SESSION['qq']['userId'])) {
             $this->assign('collects', '已收藏');
         } else {
             $collectNum = $collect->getCollectCountByuserId($article);
             $this->assign('collectNum', $collectNum);
             $this->assign('collects', '收藏');
         }
     }
     $this->assign('article', $content);
     //评论查询
     $comments = $comment->getComment($articleId);
     $user = new UserModel();
     $arr = array();
     foreach ($comments as $key => $val) {
         $val[$key]['user'] = $user->getUserById($val['userId']);
     }
     $this->assign('comments', $comments);
     $this->display();
 }
Example #2
0
 public function addCollect()
 {
     if (!$_SESSION['qq']) {
         $result['code'] = '021';
         $result['message'] = '未登录,请登录账号!';
     } else {
         //实例化Model
         $collectModel = new CollectModel();
         $articleId = Data::get($_GET['articleId'], Data::Int);
         // var_dump($_GET);exit;
         $if_collect = $collectModel->getCollects($articleId, $_SESSION['qq']['userId']);
         if ($if_collect) {
             $collectId = $collectModel->deleteCollect($articleId, $_SESSION['qq']['userId']);
             if ($collectId) {
                 $result['code'] = '001';
                 $result['message'] = '取消收藏成功!';
             } else {
                 $result['code'] = '002';
                 $result['message'] = '取消收藏失败!';
             }
         } else {
             $collectId = $collectModel->addCollect(array('articleId' => $articleId, 'userId' => $_SESSION['qq']['userId']));
             if ($collectId) {
                 $result['code'] = '003';
                 $result['message'] = '恭喜,收藏成功!';
             } else {
                 $result['code'] = '002';
                 $result['message'] = '抱歉,收藏失败!';
             }
         }
     }
     echo json_encode($result);
     exit;
 }