This commit is contained in:
2016-08-05 18:07:36 +08:00
parent 2e17228a32
commit 9f5c4070cc
2 changed files with 57 additions and 56 deletions

View File

@@ -15,6 +15,7 @@ namespace app\common\model;
class Document extends \think\model\Merge{ class Document extends \think\model\Merge{
protected $fk = 'doc_id'; protected $fk = 'doc_id';
//protected static $relationModel = array('document_article');
// 定义需要自动写入时间戳格式的字段 // 定义需要自动写入时间戳格式的字段
protected $autoWriteTimestamp = array('create_time','update_time','deadline'); protected $autoWriteTimestamp = array('create_time','update_time','deadline');
@@ -78,7 +79,7 @@ class Document extends \think\model\Merge{
public function change(){ public function change(){
/* 获取数据对象 */ /* 获取数据对象 */
$data = input('post.'); $data = \think\Request::instance()->post();
if ($data !== false) { if ($data !== false) {
/* 添加或新增基础内容 */ /* 添加或新增基础内容 */

View File

@@ -10,18 +10,18 @@
namespace app\index\controller; namespace app\index\controller;
use app\common\controller\Fornt; use app\common\controller\Fornt;
class Content extends Fornt{ class Content extends Fornt {
protected $beforeActionList = array( protected $beforeActionList = array(
'setModel' => array('except' => 'category') 'setModel' => array('except' => 'category'),
); );
//模块频道首页 //模块频道首页
public function index(){ public function index() {
$id = input('id','','trim,intval'); $id = input('id', '', 'trim,intval');
$name = input('name','','trim'); $name = input('name', '', 'trim');
if ($name) { if ($name) {
$id = db('Category')->where(array('name'=>$name))->getField('id'); $id = db('Category')->where(array('name' => $name))->getField('id');
} }
if (!$id) { if (!$id) {
@@ -34,13 +34,13 @@ class Content extends Fornt{
$ids = get_category_child($id); $ids = get_category_child($id);
$data = array( $data = array(
'category' => $cate, 'category' => $cate,
'child_cate' => $ids 'child_cate' => $ids,
); );
if ($cate['template_index']) { if ($cate['template_index']) {
$teamplate = 'content/'.$this->modelInfo['name'].'/'.$cate['template_index']; $teamplate = 'content/' . $this->modelInfo['name'] . '/' . $cate['template_index'];
}else{ } else {
$teamplate = 'content/'.$this->modelInfo['name'].'/index'; $teamplate = 'content/' . $this->modelInfo['name'] . '/index';
} }
$this->assign($data); $this->assign($data);
$this->setSeo($cate['name']); $this->setSeo($cate['name']);
@@ -48,48 +48,48 @@ class Content extends Fornt{
} }
//模块列表页 //模块列表页
public function lists($id = '', $name = ''){ public function lists($id = '', $name = '') {
if ($name) { if ($name) {
$id = db('Category')->where(array('name'=>$name))->getField('id'); $id = db('Category')->where(array('name' => $name))->getField('id');
} }
if (!$id) { if (!$id) {
return $this->error("无此栏目!"); return $this->error("无此栏目!");
} }
$cate = $this->getCategory($id); $cate = $this->getCategory($id);
//获得当前栏目的所有子栏目 //获得当前栏目的所有子栏目
$ids = get_category_child($id); $ids = get_category_child($id);
$map['category_id'] = array('IN',$ids); $map['category_id'] = array('IN', $ids);
$map['model_id'] = $this->modelInfo['id']; $map['model_id'] = $this->modelInfo['id'];
$map['status'] = array('GT',0); $map['status'] = array('GT', 0);
if ($this->modelInfo['extend'] > 1) { if ($this->modelInfo['extend'] > 1) {
$order = "id desc"; $order = "id desc";
}else{ } else {
$order = "is_top desc,id desc"; $order = "is_top desc,id desc";
} }
$model = $this->model;
$list = $this->model->where($map)->order($order)->paginate(15); $list = $model->where($map)->order($order)->paginate(15);
$data = array( $data = array(
'list' => $list, 'list' => $list,
'cate' => $cate, 'cate' => $cate,
'page' => $list->render() 'page' => $list->render(),
); );
if ($cate['template_lists']) { if ($cate['template_lists']) {
$teamplate = 'content/'.$this->modelInfo['name'].'/'.$cate['template_lists']; $teamplate = 'content/' . $this->modelInfo['name'] . '/' . $cate['template_lists'];
}else{ } else {
$teamplate = 'content/'.$this->modelInfo['name'].'/list'; $teamplate = 'content/' . $this->modelInfo['name'] . '/list';
} }
$this->setSeo($cate['title']); $this->setSeo($cate['title']);
$this->assign($data); $this->assign($data);
return $this->fetch($teamplate); return $this->fetch($teamplate);
} }
public function category(){ public function category() {
$id = $this->request->param('id'); $id = $this->request->param('id');
if (!$id) { if (!$id) {
return $this->error("非法操作"); return $this->error("非法操作");
@@ -97,21 +97,21 @@ class Content extends Fornt{
$cate = $this->getCategory($id); $cate = $this->getCategory($id);
$category = get_category_child($id); $category = get_category_child($id);
$map = array( $map = array(
'category_id' => array('IN', $category) 'category_id' => array('IN', $category),
); );
$order = "id desc"; $order = "id desc";
$list = model('Document')->where($map)->order($order)->paginate(15); $list = model('Document')->where($map)->order($order)->paginate(15);
$data = array( $data = array(
'list' => $list, 'list' => $list,
'cate' => $cate, 'cate' => $cate,
'page' => $list->render() 'page' => $list->render(),
); );
if ($cate['template_lists']) { if ($cate['template_lists']) {
$teamplate = 'content/'.$cate['template_lists']; $teamplate = 'content/' . $cate['template_lists'];
}else{ } else {
$teamplate = 'content/list'; $teamplate = 'content/list';
} }
$this->setSeo($cate['title']); $this->setSeo($cate['title']);
@@ -120,14 +120,14 @@ class Content extends Fornt{
} }
//模块内容详情页 //模块内容详情页
public function detail($id = '', $name = ''){ public function detail($id = '', $name = '') {
//当为文章模型时 //当为文章模型时
$info = $this->model->detail($id); $info = $this->model->detail($id);
//文档模型数据统计,同一台电脑半小时更新一次 //文档模型数据统计,同一台电脑半小时更新一次
if ($this->modelInfo['extend'] = 1 && (time() - session('set_content_view')) > 1800) { if ($this->modelInfo['extend'] = 1 && (time() - session('set_content_view')) > 1800) {
db('Document')->where(array('id'=>$id))->setInc('view'); db('Document')->where(array('id' => $id))->setInc('view');
session('set_content_view',time()); session('set_content_view', time());
} }
if (empty($info)) { if (empty($info)) {
@@ -135,47 +135,47 @@ class Content extends Fornt{
} }
$data = array( $data = array(
'info' => $info 'info' => $info,
); );
if (isset($info['template_detail']) && $info['template_detail']) { if (isset($info['template_detail']) && $info['template_detail']) {
$teamplate = 'content/'.$this->modelInfo['name'].'/'.$info['template_detail']; $teamplate = 'content/' . $this->modelInfo['name'] . '/' . $info['template_detail'];
}else{ } else {
$teamplate = 'content/'.$this->modelInfo['name'].'/detail'; $teamplate = 'content/' . $this->modelInfo['name'] . '/detail';
} }
$this->assign($data); $this->assign($data);
$title = isset($info['title']) ? $info['title'] : ''; $title = isset($info['title']) ? $info['title'] : '';
$tags = isset($info['tags']) ? $info['tags'] : ''; $tags = isset($info['tags']) ? $info['tags'] : '';
$description = isset($info['description']) ? $info['description'] : ''; $description = isset($info['description']) ? $info['description'] : '';
$this->setSeo($title, $tags, $description); $this->setSeo($title, $tags, $description);
return $this->fetch($teamplate); return $this->fetch($teamplate);
} }
protected function getCategory($id){ protected function getCategory($id) {
$data = db('Category')->find($id); $data = db('Category')->find($id);
return $data; return $data;
} }
protected function setModel(){ protected function setModel() {
$model_name = $this->request->param('model'); $model_name = $this->request->param('model');
$model_id = $this->request->param('model_id'); $model_id = $this->request->param('model_id');
$row = db('Model')->select(); $row = db('Model')->select();
foreach ($row as $key => $value) { foreach ($row as $key => $value) {
$name_list[$value['name']] = $value; $name_list[$value['name']] = $value;
$id_list[$value['id']] = $value; $id_list[$value['id']] = $value;
} }
if (empty($name_list[$model_name]) && empty($id_list[$model_id])) { if (empty($name_list[$model_name]) && empty($id_list[$model_id])) {
return $this->error("无此模型!"); return $this->error("无此模型!");
}else { } else {
$this->modelInfo = $model_name ? $name_list[$model_name] : $id_list[$model_id]; $this->modelInfo = $model_name ? $name_list[$model_name] : $id_list[$model_id];
if ($this->modelInfo['extend'] > 1) { if ($this->modelInfo['extend'] > 1) {
$this->model = model($this->modelInfo['name']); $this->model = model($this->modelInfo['name']);
}else{ } else {
$this->model = model('Document')->extend($this->modelInfo['name']); $this->model = model('Document')->extend($this->modelInfo['name']);
} }
$this->assign('model_id',$this->modelInfo['id']); $this->assign('model_id', $this->modelInfo['id']);
$this->assign('model_list',$name_list); $this->assign('model_list', $name_list);
} }
} }
} }