public function getList($limit = 20, $type = 0, $keywords = '', $order = '', $findPage = true)
{
$map = array();
$map['state'] = array('GT', 0);
if ($keywords) {
$map['news_title'] = array('like', '%' . $keywords . '%');
}
if ($order == '') {
$order = 'is_top desc,news_id desc';
}
if ($type) {
//获取子分类
$childs = $this->getChildTids($type);
if ($childs) {
$childs[] = $type;
$map['type_id'] = array('in', $childs);
} else {
$map['type_id'] = $type;
}
}
$this->where($map)->order($order);
if ($findPage) {
$list = $this->findPage($limit);
$data = $list['data'];
} else {
$data = $this->findAll(array('limit' => $limit));
}
foreach ($data as $k => $v) {
$thumb = APPS_URL . '/' . APP_NAME . '/_static/nopic.jpg';
if ($v['image']) {
$attach = model('Attach')->getAttachById($v['image']);
if ($attach) {
$thumb = getImageUrl($attach['save_path'] . $attach['save_name'], 100, 100);
}
}
$data[$k]['image'] = $thumb;
$data[$k]['title_intro'] = msubstr($v['news_title'], 0, 30);
$data[$k]['content_intro'] = msubstr(strip_tags($v['news_content']), 0, 100);
//获取评论数量
$data[$k]['comment_count'] = model('Comment')->where(array('app' => 'news', 'table' => 'news', 'is_del' => 0, 'row_id' => $v['news_id']))->count();
}
if ($findPage) {
$list['data'] = $data;
return $list;
} else {
return $data;
}
}