73 lines
3.0 KiB
PHP
Executable File
73 lines
3.0 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Home\Controller;
|
|
|
|
use Gy_Library\DBCont;
|
|
use Gy_Library\HomeController;
|
|
|
|
class TopicController extends HomeController
|
|
{
|
|
|
|
public function index()
|
|
{
|
|
$this->meta_title = '专题';
|
|
if(is_mobile()){
|
|
//页码
|
|
$page = I('page');
|
|
$page == '' && $page = 1;
|
|
$per_page = !empty(C('HOME_PER_PAGE_NUM'))?C('HOME_PER_PAGE_NUM'): 1 ;
|
|
$model = D('Topic');
|
|
$map = ['status'=>DBCont::YES_BOOL_STATUS];
|
|
$count = $model->getListForCount($map);
|
|
$topic_list=D('Topic')->where(['status'=>DBCont::YES_BOOL_STATUS])->order('sort asc,id asc')->page($page,$per_page)->select();
|
|
foreach ($topic_list as &$item){
|
|
$news_id = D('TopicFromNews')->where(['topic_id'=>$item['id'],'status'=>DBCont::YES_BOOL_STATUS])->order('sort asc,id asc')->getField('news_id',true);
|
|
if(!empty($news_id)){
|
|
$news_id_sort = implode(',',$news_id);
|
|
$item['news_list'] = D('News')->where(['id'=>['IN',$news_id]])->order("FIELD (id,{$news_id_sort})")->limit(4)->select();
|
|
}
|
|
}
|
|
if ($per_page === false) {
|
|
$para = array($count);
|
|
} else {
|
|
$para = array($count, $per_page);
|
|
}
|
|
$class = new \ReflectionClass('\Gy_Library\GyPage');
|
|
$page_object = $class->newInstanceArgs($para);
|
|
$pagination = $page_object->show();
|
|
$this->assign('pagination', $pagination);
|
|
$this->topic_list= $topic_list;
|
|
}else{
|
|
$topic_list = D('Topic')->where(['status'=>DBCont::YES_BOOL_STATUS])->order('sort asc,id asc')->select();
|
|
foreach ($topic_list as &$item){
|
|
$news_id = D('TopicFromNews')->where(['topic_id'=>$item['id'],'status'=>DBCont::YES_BOOL_STATUS])->order('sort asc')->getField('news_id',true);
|
|
if(!empty($news_id)){
|
|
$news_id_sort = implode(',',$news_id);
|
|
$item['news_list'] = D('News')->where(['id'=>['IN',$news_id]])->order("FIELD (id,{$news_id_sort})")->limit(4)->select();
|
|
}
|
|
}
|
|
$this->topic_list= $topic_list;
|
|
}
|
|
$this->share_title = '专题';
|
|
$this->display();
|
|
}
|
|
public function detail()
|
|
{
|
|
$this->meta_title = '专题详情';
|
|
$topic_id = I('get.topic_id');
|
|
$topic_res = D('Topic')->where(['id'=>$topic_id])->find();
|
|
//聚合页页面点击次数+1
|
|
D('Topic')->where(['id'=>$topic_id])->setField('click_time',$topic_res['click_time']+1);
|
|
$this->topic_id= $topic_id;
|
|
$this->topic_res= $topic_res;
|
|
$this->share_title = $topic_res['name'];
|
|
$img=showFileUrl($topic_res['cover_id']);
|
|
if (filter_var($img,FILTER_VALIDATE_URL)){
|
|
$this->share_img = $img;
|
|
}else{
|
|
$this->share_img = HTTP_PROTOCOL.'://'.SITE_URL.$img;
|
|
}
|
|
$this->display();
|
|
}
|
|
}
|