Esempio n. 1
0
 /**
  * 保存/修改资讯数据
  *
  * @params array $params 保存数据
  * @return boolean 是否保存成功
  */
 public function saveNewsData($params = [])
 {
     // $params = Yii::$app->request->post('Post',false);
     $isNewRecord = $this->isNewRecord;
     //判断是新增还是修改
     if (!$params) {
         return false;
     } else {
         $news_id = $this->storeSave($params);
         $conditions = [];
         if (!$news_id) {
             return false;
         } else {
             if ($isNewRecord) {
                 $model = new PostAttrStat();
                 $model->news_id = $news_id;
                 $model->save(false);
             }
             $conditions['news_id'] = $news_id;
             //相关用户
             if (isset($params['rel_user'])) {
                 //数据处理
                 $params['rel_user'] = $this->getDataId($params['rel_user']);
                 $conditions['attr_id'] = PostAttribute::USER;
                 $this->saveAttrVals($conditions, $params['rel_user']);
             }
             //相关产品
             if (isset($params['rel_product'])) {
                 //数据处理
                 $params['rel_product'] = $this->getDataId($params['rel_product']);
                 $conditions['attr_id'] = PostAttribute::PRODUCT;
                 $this->saveAttrVals($conditions, $params['rel_product']);
             }
             //相关资讯
             if (isset($params['rel_news'])) {
                 $conditions['attr_id'] = PostAttribute::SIMILAR_NEWS;
                 $this->saveAttrVals($conditions, $params['rel_news']);
             }
             //相关标签
             if (isset($params['rel_tag'])) {
                 //获取标签对应的tag_id组成的字符串
                 $mTag = new Tag();
                 $tagStr = $mTag->rebackTagIds($params['rel_tag']);
                 $conditions['attr_id'] = PostAttribute::TAG;
                 $this->saveAttrVals($conditions, $tagStr);
             }
             return true;
         }
     }
 }
Esempio n. 2
0
 /**
  * Action Tag
  * @param $id int 标签id
  */
 public function actionTag($id, $page = 1)
 {
     //获取资讯列表信息
     $pagesize = Post::PAGE_SIZE;
     $start = ($page - 1) * $pagesize;
     $mNewsMes = new Post();
     $mNewsMessage = $mNewsMes->getTagnews($id, '', $pagesize, $start);
     $count = $mNewsMes->getTagnews($id, "true");
     $totalpage = ceil($count / $pagesize);
     // $pages = new Pagination([
     //     'totalCount' => $mNewsMessage->count(),
     //     'pageSize' => Post::PAGE_SIZE
     // ]);
     // $mNewsMessage = $mNewsMessage->asArray()->all();
     // 获取首页标签信息
     $mTag = new Tag();
     $tags = $mTag->getTags();
     $condition = array('tag_id' => $id);
     $tag_name = $mTag->getTagsBycond($condition);
     $tag_result = $mTag->findOne($id);
     $tag_des = isset($tag_result->tag_des) && $tag_result->tag_des ? $tag_result->tag_des : '让我们一起发现美丽与你共创美好的生活';
     // 获取热门活动
     $mPageBlock = new PageCustomBlock();
     $slideOption['customId'] = PageCustomBlock::NEWS_PAGE_ACTIVITIES;
     $activity = $mPageBlock->block($slideOption);
     // 获取热门产品
     $mProductStat = new IProductStat();
     $HotProducts = $mProductStat->getHotProduct();
     // 获取热门文章
     $mPostStat = new PostAttrStat();
     $HotArticles = $mPostStat->getHotArticle();
     // 获取关注用户
     $mFollow = new FollowTag();
     $followUser = $mFollow->getFollowUser($id);
     $follow = ['tag_follow' => false];
     if ($user = Yii::$app->util->isLogin()) {
         // 获取用户是否喜欢/Like
         $mFollow = new Follow();
         $follow['tag_follow'] = $mFollow->getUserTagFollow($id, $user['uid']);
     }
     return $this->render('tag', ['data' => $mNewsMessage, 'tags' => $tags, 'activity' => $activity, 'products' => $HotProducts, 'article' => $HotArticles, 'tag_name' => $tag_name[0], 'tag_des' => $tag_des, 'tag_id' => $id, 'follow_user' => $followUser, 'totalpage' => $totalpage, 'follow' => $follow]);
 }