/**
  * 获取活动相关文章列表,按活动相关标签来显示
  * @Author   罗江涛
  * @DateTime 2016-03-24T09:19:55+0800
  */
 public function getCampaignUnionArticleList()
 {
     // 接收活动的ID
     $campaignId = I("campaignId", 0, "intval");
     //没有活动ID
     if (!$campaignId) {
         $result = $this->getStandResult(0, '没有活动ID', '', '');
         $this->json($result);
         return;
     }
     $table = "campaign_tags ct";
     $where = " ct.campaignId = {$campaignId} ";
     $field = "ct.tagId";
     //分页查询
     $tagIdList = M($table)->where($where)->field($field)->select();
     //未查询到数据的处理
     if (empty($tagIdList)) {
         $result = $this->getStandResult(0, '该活动没有标签,所以没有相关文章', '', '');
         $this->json($result);
         return;
     }
     $tagId = array();
     foreach ($tagIdList as $key => $value) {
         // 把标签id转化为一维数组
         $tagId[] = $value["tagId"];
     }
     $articleIdList = M("article_tags")->where(array('tagId' => array('IN', $tagId)))->field("articleId")->select();
     //未查询到数据的处理
     if (empty($articleIdList)) {
         $result = $this->getStandResult(0, '该活动关联的标签,没有相关文章', '', '');
         $this->json($result);
         return;
     }
     $articleId = array();
     foreach ($articleIdList as $key => $value) {
         // 把articleId转化为一维数组
         $articleId[] = $value["articleId"];
     }
     // 获取活动相关文章列表,按活动相关标签来搜索
     $articleList = M("article")->where(array('articleId' => array('IN', $articleId), "status" => 3))->field("articleId, title, creatorName, summary, publishTime, logo")->limit(5)->select();
     //兼容原有的logo图片地址格式,无logo的加入默认Logo,地址转换为统一形式
     foreach ($articleList as $key => $value) {
         //时间格式转化
         // $articleList[$key]['publishTime'] = getTimeDifference($value['publishTime']);
     }
     //logo图片地址补全
     $articleList = checkLogo($articleList);
     //组装数据
     $result = $this->getStandResult(1, '获取数据成功', '', $articleList);
     // 输出数据
     $this->json($result);
 }
 /**
  * 获取订阅文章列表数据
  * @author 罗江涛
  * @DateTime 2016-01-12T15:18:22+0800
  */
 public function getSubscribeArticleList()
 {
     // 用于分页
     $page = I('page', 0, 'intval');
     // 获取用户信息
     $userId = $this->_user['userId'];
     // 没有用户信息
     if (!$userId) {
         $result = $this->getStandResult(0, "没有登录", "", "");
         $this->json($result);
         return;
     }
     //定义数据模型
     $db = M("tag t, subscribe s");
     $where = " t.tagId = s.tagId and s.userId = {$userId}";
     //获取我已订阅标签ID
     $subscribeTagId = $db->order('t.tagId DESC')->field('t.tagId')->where($where)->select();
     // 没有订阅标签
     if (!$subscribeTagId) {
         $result = $this->getStandResult(0, "没有订阅标签", "", "");
         $this->json($result);
         return;
     }
     $tagIdList = array();
     // 如果有订阅,则组装tagId一维数组
     foreach ($subscribeTagId as $key => $value) {
         $tagIdList[] = $value['tagId'];
     }
     //定义数据模型
     $db = M("article a, article_tags at");
     $where = " a.articleId = at.articleId and at.tagId in (select tagId from subscribe where userId = {$userId}) ";
     // 获取用户订阅的文章
     $article = $db->order('a.publishTime DESC')->field('a.articleId, a.title, a.logo, a.creatorName, a.publishTime')->page($page)->where($where)->limit(10)->group('a.articleId')->select();
     // 没有订阅文章
     if (!$article) {
         $result = $this->getStandResult(0, "订阅标签下没有文章", "", "");
         $this->json($result);
         return;
     }
     //logo图片地址补全
     $article = checkLogo($article);
     // 组装并输出标准接口数据
     $result = $this->getStandResult(1, "查询成功", "", $article);
     $this->json($result);
 }
 /**
  * 获取热门文章列表,按点击量排序
  * @Author   罗江涛
  * @DateTime 2016-03-25T09:27:16+0800
  */
 public function getHotArticleList()
 {
     // 搜索文章id, 按点击量排序
     $sql = "select articleId, count(1) as count from article_click group by articleId order by count(1) DESC LIMIT 5";
     $articleClick = M()->query($sql);
     // 取出文章id,这是一维数组
     $articleIdList = array();
     foreach ($articleClick as $key => $value) {
         $articleIdList[] = $value["articleId"];
     }
     //定义数据模型
     $db = M("article");
     $where = array("articleId" => array("IN", $articleIdList));
     // 按$articleIdList 即热门文章的点击量排序
     $order = "FIND_IN_SET(articleId,'" . implode(",", $articleIdList) . "')";
     // 获取文章,按发布时间排序
     $article = $db->order($order)->field('articleId, title, logo,  creatorName, publishTime, categoryId')->where($where)->select();
     // 如果查询结果为空
     if (!$article) {
         $result = $this->getStandResult(0, "没有查询到结果", "", "");
         $this->json($result);
         return;
     }
     //logo图片地址补全
     $article = checkLogo($article);
     // 组装并输出标准数据
     $result = $this->getStandResult(1, "查询热点文章成功", "", $article);
     $this->json($result);
 }