Example #1
0
 /**
  * 评论写入接口
  */
 public function actionIndex()
 {
     $mComment = new Comment();
     // print_r(Yii::$app->request->post());exit;
     //xxx 方便测试用
     // $newsId = Yii::$app->request->get('id', false);
     if (Yii::$app->request->getIsPost()) {
         $params = Yii::$app->request->post();
         // print_r($params);exit;
         // $params['cmt_name'] ? '' : Yii::$app->util->msg('评论内容不能为空');
         //获取用户id
         $user = Yii::$app->util->isLogin();
         //匿名用户验证码检测
         if (empty($user)) {
             if (isset($params['vcode']) && $params['vcode']) {
                 //获取验证码
                 $session = Yii::$app->session;
                 $session->isActive ? '' : $session->open();
                 $cmtcode = $session->get('__captcha/comment/cmtcode');
                 if ($cmtcode !== $params['vcode']) {
                     Yii::$app->util->msg('验证码错误!');
                 }
             } else {
                 Yii::$app->util->msg('请输入验证码!');
             }
         }
         $params['owner_id'] = $user['uid'] ? $user['uid'] : '';
         $params['cmt_type_id'] = 1;
         //评论类型为资讯评论
         // print_r($params);exit;
         //xxx 方便测试用
         // $params['news_id'] = $newsId ? $newsId : 0;
         if (isset($params['news_id']) && $params['news_id'] > 0) {
             // print_r($params);exit;
             $mComment->saveStore($params);
             $mPostAttrVal = new PostAttrVal();
             $options = ['news_id' => $params['news_id'], 'attr_id' => PostAttribute::COMMENT, 'attr_value_text' => $mComment->cmt_id];
             $mPostAttrVal->saveStore($options);
             $mPostAttrStat = new PostAttrStat();
             $mPostAttrStat->addNum($params['news_id'], 'attr_stat_comment_num', 1);
             $this->redirect(Url::toRoute(['news/detail', 'id' => $params['news_id'], '#' => 'comments']));
             // echo $re;
         } else {
             echo "params news_id is missing";
         }
         // print_r($params);exit;
         // $mComment = new Comment();
         // $re = $mComment->saveStore($params);
         // echo "<pre>";
         // echo $re;exit;
     }
 }
Example #2
0
 /**
  * Action Detail
  * @param $id int 资讯id
  */
 public function actionDetail($id)
 {
     //增加总访问量
     $mPostAttrStat = new PostAttrStat();
     $mPostAttrStat->modify('attr_stat_view_num', intval($id), 1, true);
     //访问日志
     $mViewsLog = new ViewsLog();
     $mViewsLog->modify(intval($id), ViewsLog::ARTICLE_TYPE);
     //增加周访问量,月访问量
     $week_num = $mViewsLog->ViewsNum(intval($id), ViewsLog::ARTICLE_TYPE, 7);
     $month_num = $mViewsLog->ViewsNum(intval($id), ViewsLog::ARTICLE_TYPE, 30);
     $mPostAttrStat->modifyviewnum('week_views_num', intval($id), $week_num);
     $mPostAttrStat->modifyviewnum('month_views_num', intval($id), $month_num);
     //获取资讯详情信息
     $mNewsMessage = new Post();
     $mNewsMessage = $mNewsMessage->getNewsDetail($id);
     if (!empty($mNewsMessage[0]['news_video_url'])) {
         $url = preg_match_all('/http:\\/\\/(.*?)?\\.(.*?)?\\.com\\/(.*)/', $mNewsMessage[0]['news_video_url'], $types);
         if (!empty($types) && !empty($types[2]) && $types[2][0] == "youku") {
             $mNewsMessage[0]['news_video_url'] = Yii::$app->util->generalVideo($mNewsMessage[0]['news_video_url']);
             //视频地址处理
         } else {
             $mNewsMessage[0]['news_video_url'] = "";
         }
     }
     // echo "<pre>";
     // var_dump($mNewsMessage[0]);die;
     //获取热门产品
     $mProductStat = new IProductStat();
     $HotProducts = $mProductStat->getHotProduct();
     // echo "<pre>";
     // var_dump($HotProducts);die;
     //获取热门文章
     $mPostStat = new PostAttrStat();
     $HotArticles = $mPostStat->getHotArticle();
     // echo "<pre>";
     // var_dump($HotArticles);die;
     //获取相关用户
     $mPostMember = new PostAttrVal();
     $similarMember = $mPostMember->getSimilarMember($id);
     // echo "<pre>";
     // var_dump($HotArticles);die;
     //获取相关文章
     $mPostNews = new PostAttrVal();
     $similarNews = $mPostNews->getSimilarNews($id);
     // echo "<pre>";
     // var_dump($HotArticles);die;
     //登录用户获取用户信息
     $follow = ['follow' => false, 'like' => false];
     if ($user = Yii::$app->util->isLogin()) {
         $mMember = new Member();
         $re = $mMember->getByUid($user['uid']);
         $user['avatar'] = $re['avatar'];
         // 获取用户是否喜欢/Like
         $mFollow = new Follow();
         $follow['follow'] = $mFollow->getUserFollow($id, $user['uid']);
         $follow['like'] = $mFollow->getUserLike($id, $user['uid']);
     }
     //评论
     $mComment = new Comment();
     $comment = $mComment->getCommentsByNewsId($id, false, 0, Comment::NEWS_COMMENT_PAGESIZE);
     $total = $mComment->getCommentsByNewsId($id, true);
     // print_r($comment);exit;
     // print_r($total);exit;
     if (isset($mNewsMessage[0])) {
         return $this->render('detail', ['detail' => $mNewsMessage[0], 'products' => $HotProducts, 'article' => $HotArticles, 'similarMember' => $similarMember, 'similarNews' => $similarNews, 'user' => $user ? $user : '', 'comment' => $comment, 'total' => $total, 'follow' => $follow]);
     } else {
         return $this->redirect(['news/index']);
         //跳转到资讯首页
     }
 }
Example #3
0
 /**
  * 获取资讯的tag,此方法限用于本model中的afterFind()
  * 
  * @param  int $news_id 资讯id
  * @return string 资讯tag用逗号隔开字符串 
  */
 protected function get_rel_tag($news_id)
 {
     $mPostAttrVal = new PostAttrVal();
     $vals = $mPostAttrVal->getValues(['news_id' => $news_id, 'attr_id' => PostAttribute::TAG]);
     $mTag = new Tag();
     $tags = $mTag->getTagsBycond(['tag_id' => $vals]);
     return implode(',', $tags);
 }