// +---------------------------------------------------------------------- namespace Home\Controller; use mysql_xdevapi\Exception; /** * 文档模型控制器 * 文档模型列表和详情 */ class ArticleController extends HomeController { /* 文档模型频道页 */ public function index(){ /* 分类信息 */ $category = $this->category(); //频道页只显示模板,默认不读取任何内容 //内容可以通过模板标签自行定制 /* 模板赋值并渲染模板 */ $this->assign('category', $category); $this->display($category['template_index']); } /* 文档模型列表页 */ public function lists($p = 1){ /* 分类信息 */ $category = $this->category(); /* 获取当前分类列表 */ $Document = D('Document'); $list = $Document->page($p, $category['list_row'])->lists($category['id']); if(false === $list){ $this->error('获取列表数据失败!'); } /* 模板赋值并渲染模板 */ $this->assign('category', $category); $this->assign('list', $list); $this->display($category['template_lists']); } public function game_list($p=0){ $page = intval($p); $page = $page ? $page : 1; //默认显示第一页数据 $row = 25; $game = M('Game','tab_'); $map['game_status']=1; empty($_REQUEST['gt']) || $map['game_type_id']=$_REQUEST['gt']; empty($_REQUEST['dt']) || $map['sdk_version']=$_REQUEST['dt']; $data = $game->where($map)->order('sort desc,id desc')->page($page,$row)->select(); $count = $game->where($map)->count(); //分页 if($count > $row){ $page = new \Think\Page($count, $row); $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%'); $this->assign('_page', $page->show()); } $this->assign('count', $count); $this->assign('list_data', $data); $this->display(); } /* 文档模型详情页 */ public function detail($id = 0, $p = 1){ /* 标识正确性检测 */ if(!($id && is_numeric($id))){ $this->error('文档ID错误!'); } $field = 'id as document_id,category_id'; $decumentData = M('document')->field($field)->where("id={$id}")->find(); $promote_id = get_pid(); if(empty($promote_id)) { $promote_id = 0; } foreach ($decumentData as $key => $value) { $decumentData['promote_id'] = $promote_id; $decumentData['create_time'] = time(); } M('document_read')->startTrans(); //事物 try { $haveRead = M('document_read')->where("document_id={$id} and promote_id={$promote_id}")->find(); if (!$haveRead) { M('document_read')->add($decumentData); } } catch (Exception $e) { M('document_read')->rollback();//回滚 } M('document_read')->commit(); //提交事物 /* 页码检测 */ $p = intval($p); $p = empty($p) ? 1 : $p; /* 获取详细信息 */ $Document = D('Document'); $info = $Document->detail($id); if(!$info){ $this->error($Document->getError()); } /* 分类信息 */ $category = $this->category($info['category_id']); /* 获取模板 */ if(!empty($info['template'])){//已定制模板 $tmpl = $info['template']; } elseif (!empty($category['template_detail'])){ //分类已定制模板 $tmpl = $category['template_detail']; } else { //使用默认模板 $tmpl = 'Article/'. get_document_model($info['model_id'],'name') .'/detail'; } /* 更新浏览数 */ $map = array('id' => $id); $Document->where($map)->setInc('view'); /* 模板赋值并渲染模板 */ $this->assign('category', $category); $this->assign('info', $info); $this->assign('page', $p); //页码 $this->display($tmpl); } public function more_lists($type='gg',$p=1){ /* 分类信息 */ if($type=='gg'){ $category = $this->category('tui_gg');//公告 }else{ $category = $this->category('tui_zx');//资讯公告 } /* 获取当前分类列表 */ $Document = D('Document'); $list = $Document->page($p, $category['list_row'])->lists($category['id'],'level desc,id desc'); if(false === $list){ $this->error('获取列表数据失败!'); } $count = $Document->listCount($category['id']); $row = $category['list_row']?$category['list_row']:10; if($count > $row){ $page = new \Think\Page($count, $row); $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%'); $this->assign('_page', $page->show()); } /* 模板赋值并渲染模板 */ $this->assign('category', $category); $this->assign('list', $list); if(!empty($list)){//联盟公告 $Document = D('Document'); $info = $Document->detail($list[0]['id']); if(!$info){ $this->error($Document->getError()); } } $this->assign('info',$info); $this->display($category['template_lists']); } /* 文档模型详情页 */ public function detail_ajax($id = 0, $p = 1){ /* 标识正确性检测 */ if(!($id && is_numeric($id))){ $this->ajaxReturn(array('status'=>0,'msg'=>'文档ID错误!')); } /* 页码检测 */ $p = intval($p); $p = empty($p) ? 1 : $p; /* 获取详细信息 */ $Document = D('Document'); $info = $Document->detail($id); if(!$info){ $this->ajaxReturn(array('status'=>0,'msg'=>$Document->getError())); } /* 分类信息 */ $category = $this->category($info['category_id']); /* 获取模板 */ if(!empty($info['template'])){//已定制模板 $tmpl = $info['template']; } elseif (!empty($category['template_detail'])){ //分类已定制模板 $tmpl = $category['template_detail']; } else { //使用默认模板 $tmpl = 'Article/'. get_document_model($info['model_id'],'name') .'/detail'; } /* 更新浏览数 */ $map = array('id' => $id); $Document->where($map)->setInc('view'); $info['update_time'] = set_show_time($info['update_time']); $this->ajaxReturn(array('status'=>1,'msg'=>$info)); } /* 文档分类检测 */ private function category($id = 0){ /* 标识正确性检测 */ $id = $id ? $id : I('get.category', 0); if(empty($id)){ $this->error('没有指定文档分类!'); } /* 获取分类信息 */ $category = D('Category')->info($id); if($category && 1 == $category['status']){ switch ($category['display']) { case 0: $this->error('该分类禁止显示!'); break; //TODO: 更多分类显示状态判断 default: return $category; } } else { $this->error('分类不存在或被禁用!'); } } }