You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
4.5 KiB
PHTML

2 years ago
<?php
namespace Mobile\Controller;
use Think\Controller;
/**
* 新闻
*/
class NewsController extends BaseController {
protected function _initialize(){
$config = api('Config/lists');
C($config);
}
public function index(){
$page = $page ? $page : 1; //默认显示第一页数据
$row = 5;
$category = I('get.category',1);
switch ($category) {
case 1://资讯
$name = "news_wap";
$title = "资讯";
break;
case 2://公告
$name = "notice_wap";
$title = "公告";
break;
case 3://活动
$name = "activity_wap";
$title = "活动";
break;
default:
$name = "news_wap";
$title = "资讯";
}
$category = M("category")->where(['name'=>$name])->find();
$map['category_id'] = $category['id'];
$map['display'] = 1;
$map['status'] = 1;
$time = NOW_TIME;
$map['_string'] = "deadline < {$time} or deadline = 0";
$data = D('Document')
->field("id,title,description,create_time,cover_id as cover")
->where($map)
->order("level desc,id desc")
->page($page,$row)
->select();
foreach ($data as $key => $val) {
$data[$key]['cover'] = get_cover($val['cover'],'path');
$data[$key]['url'] = U("News/newsdetail",array('id'=>$val['id'],'category'=>I('category',1)));
$data[$key]['datetime'] = date('Y-m-d',$val['create_time']);
}
$this->assign('page',$page);
$this->assign('data',$data);
$this->assign('category',$category);
$this->assign('title',$title);
$this->display();
}
/**
* AJAX列表
* [ajaxlists description]
* @return [type] [description]
*/
public function ajaxlists(){
$p = I('post.p');
$status=0;
$row = C('LIST_ROWS');
$category = I('get.category');
switch ($category) {
case 1://资讯
$name = "news_wap";
break;
case 2://公告
$name = "notice_wap";
break;
case 3://活动
$name = "activity_wap";
break;
default:
$name = "news_wap";
}
$category = M("category")->where(['name'=>$name])->find();
$map['category_id'] = $category['id'];
$map['display'] = 1;
$map['status'] = 1;
$time = NOW_TIME;
$map['_string'] = "deadline < {$time} or deadline = 0";
$data = D('Document')
->field("id,title,description,create_time,cover_id as cover")
->where($map)
->order("level desc,id desc")
->page($p,$row)
->select();
foreach ($data as $key => $val) {
$data[$key]['cover'] = get_cover($val['cover'],'path');
$data[$key]['url'] = U("News/newsdetail?id=".$val['id']);
$data[$key]['datetime'] = date('Y-m-d',$val['create_time']);
}
if (!empty($lists) && is_array($lists)) {
$status = 1;
}
echo json_encode(array('status'=>$status,'page'=>$p,'lists'=>$lists));
}
public function newsdetail() {
$id = I('get.id');
$category = I('get.category') ? I('get.category') : 1;
if(!($id && is_numeric($id))){
$this->error('文档ID错误');
}
$data = D('Document')
->alias('d')
->field("d.id,title,description,create_time,cover_id as cover,a.content")
->join("sys_document_article a on a.id = d.id")
->where(array('d.id'=>$id))
->find();
//浏览量增加
D('Document')->where(array('id'=>$id))->setInc('view');
$data['cover'] = get_cover($val['cover'],'path');
$data['url'] = 'http://'.$_SERVER['HTTP_HOST'].U("News/newsdetail?id=".$id."&category=".$category);
$data['datetime'] = date('Y-m-d H:i',$val['create_time']);
$category = I('get.category');
switch ($category) {
case 1://资讯
$title = "资讯";
break;
case 2://公告
$title = "公告";
break;
case 3://活动
$title = "活动";
break;
default:
$title = "资讯";
}
$this->assign('title',$title.'详情');
$this->assign('data',$data);
$this->display();
}
public function protocol(){
$map1['name']='agreement';
$map['status']=1;
$map['create_time']=array("elt",time());
$map['deadline']=array("not between",array(1,time()));
$cid = M('category')->field('id')->where($map1)->find();
$map['category_id']=$cid['id'];
$dataid = M('Document')->field('id,title')->where($map)->order("update_time desc")->find();
$data = M('document_article')->where(array('id'=>$dataid['id']))->find();
$this->assign('data',$data);
$this->assign('title',$dataid['title']);
$this->assign('category', $category);
$this->display();
}
}