/** * 获取指定社区栏目的资讯列表数据. * * @access public * @param integer $catId 栏目 ID. * @param array $where where 条件. * @param integer $page 请求的页码. * @param integer $pageSize 每页显示的条数. * @return array lists: 包含 id, title, create_time, picurl, content; totalRows: 总条数. */ public function fetchListByCategory($catId, array $where = [], $page = 1, $pageSize = 10) { $joins = ["LEFT JOIN __SQ_FDATA__ AS b ON a.id=b.dataID"]; $map = ['a.sid' => $catId, 'a.verify' => 1]; $map = array_merge($map, $where); $order = ['a.id DESC']; $field = ['a.id' => 'id', 'a.title' => 'title', 'a.postTime' => 'create_time', 'a.picUrl' => 'picurl', 'a.thumb' => 'thumb', 'b.content' => 'content', '(@app_is_top:=0)' => 'app_is_top']; // 获取置顶数据. $modelAppTopInfo = new AppTopInfoModel(); $topList = $modelAppTopInfo->fetchListOfSq($catId, C('app_top_info_num')); $ids = []; // 在列表要排除的 dataID. foreach ($topList['lists'] as $r) { $ids[] = (int) $r['id']; } if (!empty($ids)) { $map['a.id'] = ['NOT IN', $ids]; } $totalRows = $this->alias('a')->join($joins)->where($map)->count(); $result = $this->alias('a')->join($joins)->field($field)->where($map)->order($order)->page($page, $pageSize)->select(); $result = FALSE === $result || NULL === $result ? [] : $result; // 合并置顶数据到顶表, 只有第一页要合并. if ($page === 1) { foreach ($topList['lists'] as $r) { $r['app_is_top'] = (int) $r['app_is_top'] === 0 ? 1 : 0; array_unshift($result, $r); } } return ['lists' => $result, 'totalRows' => $totalRows]; }