/** * TAG表的like数 * * @return void * @author niancode **/ protected function _store_stat_with_tag($tag_id, $type = 'follow', $sum = true) { $num = $sum ? 1 : -1; $follow_num = 0; $tag_model = Tag::findOne(['tag_id' => $tag_id]); if ($tag_model) { // 关注 if ($type == 'follow') { $tag_model->updateCounters(['tag_follow_num' => $num]); $follow_num = $tag_model->tag_follow_num; } // like if ($type == 'like') { $tag_model->updateCounters(['tag_like_num' => $num]); $follow_num = $tag_model->tag_like_num; } } return $follow_num; }
/** * 获取资讯的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); }