后台代码格式化,内核更新

This commit is contained in:
2016-08-29 16:51:13 +08:00
parent 1710eb742c
commit dff622f0ac
21 changed files with 842 additions and 838 deletions

View File

@@ -9,14 +9,14 @@
return array( return array(
'user_administrator' => 1, 'user_administrator' => 1,
//'url_common_param'=>true, //'url_common_param'=>true,
'template' => array( 'template' => array(
), ),
'view_replace_str' => array( 'view_replace_str' => array(
'__ADDONS__' => BASE_PATH . '/addons', '__ADDONS__' => BASE_PATH . '/addons',
'__PUBLIC__' => BASE_PATH . '/public', '__PUBLIC__' => BASE_PATH . '/public',
'__STATIC__' => BASE_PATH . '/application/admin/static', '__STATIC__' => BASE_PATH . '/application/admin/static',
@@ -25,9 +25,9 @@ return array(
'__JS__' => BASE_PATH . '/application/admin/static/js', '__JS__' => BASE_PATH . '/application/admin/static/js',
), ),
'session' => array( 'session' => array(
'prefix' => 'admin', 'prefix' => 'admin',
'type' => '', 'type' => '',
'auto_start' => true, 'auto_start' => true,
), ),
); );

View File

@@ -26,8 +26,8 @@ class Action extends Admin {
// 记录当前列表页的cookie // 记录当前列表页的cookie
Cookie('__forward__', $_SERVER['REQUEST_URI']); Cookie('__forward__', $_SERVER['REQUEST_URI']);
$data = array( $data = array(
'list' => $list, 'list' => $list,
'page' => $list->render() 'page' => $list->render(),
); );
$this->assign($data); $this->assign($data);
$this->setMeta('用户行为'); $this->setMeta('用户行为');
@@ -38,20 +38,20 @@ class Action extends Admin {
* 新建用户行为 * 新建用户行为
* @author colin <colin@tensent.cn> * @author colin <colin@tensent.cn>
*/ */
public function add(){ public function add() {
$model = model('Action'); $model = model('Action');
if(IS_POST){ if (IS_POST) {
$data = input('post.'); $data = input('post.');
$result = $model->save($data); $result = $model->save($data);
if (false != $result) { if (false != $result) {
action_log('add_action', 'Action', $result, session('user_auth.uid')); action_log('add_action', 'Action', $result, session('user_auth.uid'));
return $this->success('添加成功!',url('index')); return $this->success('添加成功!', url('index'));
}else{ } else {
return $this->error($model->getError()); return $this->error($model->getError());
} }
}else{ } else {
$data = array( $data = array(
'keyList' => $model->fieldlist 'keyList' => $model->fieldlist,
); );
$this->assign($data); $this->assign($data);
$this->setMeta("添加行为"); $this->setMeta("添加行为");
@@ -63,25 +63,25 @@ class Action extends Admin {
* 编辑用户行为 * 编辑用户行为
* @author colin <colin@tensent.cn> * @author colin <colin@tensent.cn>
*/ */
public function edit($id = null){ public function edit($id = null) {
$model = model('Action'); $model = model('Action');
if(IS_POST){ if (IS_POST) {
$data = input('post.'); $data = input('post.');
$result = $model->save($data, array('id'=>$data['id'])); $result = $model->save($data, array('id' => $data['id']));
if ($result !== false) { if ($result !== false) {
action_log('edit_action', 'Action', $id, session('user_auth.uid')); action_log('edit_action', 'Action', $id, session('user_auth.uid'));
return $this->success('编辑成功!',url('index')); return $this->success('编辑成功!', url('index'));
}else{ } else {
return $this->error($model->getError()); return $this->error($model->getError());
} }
}else{ } else {
$info = $model::where(array('id'=>$id))->find(); $info = $model::where(array('id' => $id))->find();
if (!$info) { if (!$info) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
$data = array( $data = array(
'info' => $info, 'info' => $info,
'keyList' => $model->fieldlist 'keyList' => $model->fieldlist,
); );
$this->assign($data); $this->assign($data);
$this->setMeta("编辑行为"); $this->setMeta("编辑行为");
@@ -93,17 +93,17 @@ class Action extends Admin {
* 删除用户行为状态 * 删除用户行为状态
* @author colin <colin@tensent.cn> * @author colin <colin@tensent.cn>
*/ */
public function del(){ public function del() {
$id = $this->getArrayParam('id'); $id = $this->getArrayParam('id');
if(empty($id)){ if (empty($id)) {
return $this->error("非法操作!",''); return $this->error("非法操作!", '');
} }
$map['id'] = array('IN',$id); $map['id'] = array('IN', $id);
$result = db('Action')->where($map)->delete(); $result = db('Action')->where($map)->delete();
if ($result) { if ($result) {
action_log('delete_action', 'Action', $id, session('user_auth.uid')); action_log('delete_action', 'Action', $id, session('user_auth.uid'));
return $this->success('删除成功!'); return $this->success('删除成功!');
}else{ } else {
return $this->error('删除失败!'); return $this->error('删除失败!');
} }
} }
@@ -112,20 +112,20 @@ class Action extends Admin {
* 修改用户行为状态 * 修改用户行为状态
* @author colin <colin@tensent.cn> * @author colin <colin@tensent.cn>
*/ */
public function setstatus(){ public function setstatus() {
$id = $this->getArrayParam('id'); $id = $this->getArrayParam('id');
if(empty($id)){ if (empty($id)) {
return $this->error("非法操作!",''); return $this->error("非法操作!", '');
} }
$status = input('get.status','','trim,intval'); $status = input('get.status', '', 'trim,intval');
$message = !$status ? '禁用' : '启用'; $message = !$status ? '禁用' : '启用';
$map['id'] = array('IN',$id); $map['id'] = array('IN', $id);
$result = db('Action')->where($map)->setField('status',$status); $result = db('Action')->where($map)->setField('status', $status);
if ($result !== false) { if ($result !== false) {
action_log('setstatus_action', 'Action', $id, session('user_auth.uid')); action_log('setstatus_action', 'Action', $id, session('user_auth.uid'));
return $this->success('设置'.$message.'状态成功!'); return $this->success('设置' . $message . '状态成功!');
}else{ } else {
return $this->error('设置'.$message.'状态失败!'); return $this->error('设置' . $message . '状态失败!');
} }
} }
@@ -143,8 +143,8 @@ class Action extends Admin {
$list = model('ActionLog')->where($map)->order($order)->paginate(10); $list = model('ActionLog')->where($map)->order($order)->paginate(10);
$data = array( $data = array(
'list' => $list, 'list' => $list,
'page' => $list->render() 'page' => $list->render(),
); );
$this->assign($data); $this->assign($data);
$this->setMeta('行为日志'); $this->setMeta('行为日志');
@@ -162,13 +162,13 @@ class Action extends Admin {
$info = $model::get($id); $info = $model::get($id);
$info['title'] = get_action($info['action_id'],'title'); $info['title'] = get_action($info['action_id'], 'title');
$info['user_id'] = get_username($info['user_id']); $info['user_id'] = get_username($info['user_id']);
$info['action_ip'] = long2ip($info['action_ip']); $info['action_ip'] = long2ip($info['action_ip']);
$info['create_time'] = date('Y-m-d H:i:s',$info['create_time']); $info['create_time'] = date('Y-m-d H:i:s', $info['create_time']);
$data = array( $data = array(
'info' => $info, 'info' => $info,
'keyList' => $model->keyList 'keyList' => $model->keyList,
); );
$this->assign($data); $this->assign($data);
$this->setMeta('查看行为日志'); $this->setMeta('查看行为日志');
@@ -181,11 +181,11 @@ class Action extends Admin {
*/ */
public function dellog() { public function dellog() {
$id = $this->getArrayParam('id'); $id = $this->getArrayParam('id');
if(empty($id)){ if (empty($id)) {
return $this->error("非法操作!",''); return $this->error("非法操作!", '');
} }
$map['id'] = array('IN',$id); $map['id'] = array('IN', $id);
$res = db('ActionLog')->where($map)->delete(); $res = db('ActionLog')->where($map)->delete();
if ($res !== false) { if ($res !== false) {
action_log('delete_actionlog', 'ActionLog', $id, session('user_auth.uid')); action_log('delete_actionlog', 'ActionLog', $id, session('user_auth.uid'));
return $this->success('删除成功!'); return $this->success('删除成功!');
@@ -202,8 +202,7 @@ class Action extends Admin {
//记录行为 //记录行为
action_log('clear_actionlog', 'ActionLog', $id, session('user_auth.uid')); action_log('clear_actionlog', 'ActionLog', $id, session('user_auth.uid'));
return $this->success('日志清空成功!'); return $this->success('日志清空成功!');
} } else {
else {
return $this->error('日志清空失败!'); return $this->error('日志清空失败!');
} }
} }

View File

@@ -15,22 +15,22 @@ class Ad extends Admin {
protected $ad; protected $ad;
protected $adplace; protected $adplace;
public function _initialize(){ public function _initialize() {
parent::_initialize(); parent::_initialize();
$this->ad = db('Ad'); $this->ad = db('Ad');
$this->adplace = db('AdPlace'); $this->adplace = db('AdPlace');
} }
/** /**
* 插件列表 * 插件列表
*/ */
public function index(){ public function index() {
$map = array(); $map = array();
$order = "id desc"; $order = "id desc";
$list = db('AdPlace')->where($map)->order($order)->paginate(10); $list = db('AdPlace')->where($map)->order($order)->paginate(10);
$data = array( $data = array(
'list' => $list, 'list' => $list,
'page' => $list->render() 'page' => $list->render(),
); );
$this->assign($data); $this->assign($data);
$this->setMeta("广告管理"); $this->setMeta("广告管理");
@@ -40,18 +40,18 @@ class Ad extends Admin {
/** /**
* 广告位添加 * 广告位添加
*/ */
public function add(){ public function add() {
$place = model('AdPlace'); $place = model('AdPlace');
if (IS_POST) { if (IS_POST) {
$result = $place->change(); $result = $place->change();
if (false !== false) { if (false !== false) {
return $this->success("添加成功!"); return $this->success("添加成功!");
}else{ } else {
return $this->error($place->getError()); return $this->error($place->getError());
} }
}else{ } else {
$data = array( $data = array(
'keyList' => $place->keyList 'keyList' => $place->keyList,
); );
$this->assign($data); $this->assign($data);
$this->setMeta("添加广告位"); $this->setMeta("添加广告位");
@@ -59,23 +59,23 @@ class Ad extends Admin {
} }
} }
public function edit($id = null){ public function edit($id = null) {
$place = model('AdPlace'); $place = model('AdPlace');
if (IS_POST) { if (IS_POST) {
$result = $place->change(); $result = $place->change();
if ($result) { if ($result) {
return $this->success("修改成功!", url('admin/ad/index')); return $this->success("修改成功!", url('admin/ad/index'));
}else{ } else {
return $this->error($this->adplace->getError()); return $this->error($this->adplace->getError());
} }
}else{ } else {
$info = db('AdPlace')->where(array('id'=>$id))->find(); $info = db('AdPlace')->where(array('id' => $id))->find();
if (!$info) { if (!$info) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
$data = array( $data = array(
'info' => $info, 'info' => $info,
'keyList' => $place->keyList 'keyList' => $place->keyList,
); );
$this->assign($data); $this->assign($data);
$this->setMeta("编辑广告位"); $this->setMeta("编辑广告位");
@@ -83,50 +83,50 @@ class Ad extends Admin {
} }
} }
public function del(){ public function del() {
$id = $this->getArrayParam('id'); $id = $this->getArrayParam('id');
if (empty($id)) { if (empty($id)) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
$map['id'] = array('IN',$id); $map['id'] = array('IN', $id);
$result = $this->adplace->where($map)->delete(); $result = $this->adplace->where($map)->delete();
if ($result) { if ($result) {
return $this->success("删除成功!"); return $this->success("删除成功!");
}else{ } else {
return $this->error("删除失败!"); return $this->error("删除失败!");
} }
} }
public function lists($id = null){ public function lists($id = null) {
$map['place_id'] = $id; $map['place_id'] = $id;
$order = "id desc"; $order = "id desc";
$list = db('Ad')->where($map)->order($order)->paginate(10); $list = db('Ad')->where($map)->order($order)->paginate(10);
$data = array( $data = array(
'id' => $id, 'id' => $id,
'list' => $list, 'list' => $list,
'page' => $list->render() 'page' => $list->render(),
); );
$this->assign($data); $this->assign($data);
$this->setMeta("广告管理"); $this->setMeta("广告管理");
return $this->fetch(); return $this->fetch();
} }
public function addad($id){ public function addad($id) {
$ad = model('ad'); $ad = model('ad');
if (IS_POST) { if (IS_POST) {
$result = $ad->change(); $result = $ad->change();
if ($result) { if ($result) {
return $this->success("添加成功!", url('admin/ad/lists',array('id'=>$this->param['place_id']))); return $this->success("添加成功!", url('admin/ad/lists', array('id' => $this->param['place_id'])));
}else{ } else {
return $this->error($ad->getError()); return $this->error($ad->getError());
} }
}else{ } else {
$info['place_id'] = $id; $info['place_id'] = $id;
$data = array( $data = array(
'info' => $info, 'info' => $info,
'keyList' => $ad->keyList 'keyList' => $ad->keyList,
); );
$this->assign($data); $this->assign($data);
$this->setMeta("添加广告位"); $this->setMeta("添加广告位");
@@ -134,23 +134,23 @@ class Ad extends Admin {
} }
} }
public function editad($id = null){ public function editad($id = null) {
$ad = model('ad'); $ad = model('ad');
if (IS_POST) { if (IS_POST) {
$result = $ad->change(); $result = $ad->change();
if ($result) { if ($result) {
return $this->success("修改成功!", url('admin/ad/lists',array('id'=>$this->param['place_id']))); return $this->success("修改成功!", url('admin/ad/lists', array('id' => $this->param['place_id'])));
}else{ } else {
return $this->error($ad->getError()); return $this->error($ad->getError());
} }
}else{ } else {
$info = db('ad')->where(array('id'=>$id))->find(); $info = db('ad')->where(array('id' => $id))->find();
if (!$info) { if (!$info) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
$data = array( $data = array(
'info' => $info, 'info' => $info,
'keyList' => $ad->keyList 'keyList' => $ad->keyList,
); );
$this->assign($data); $this->assign($data);
$this->setMeta("编辑广告位"); $this->setMeta("编辑广告位");
@@ -158,17 +158,17 @@ class Ad extends Admin {
} }
} }
public function delad(){ public function delad() {
$id = $this->getArrayParam('id'); $id = $this->getArrayParam('id');
if (empty($id)) { if (empty($id)) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
$map['id'] = array('IN',$id); $map['id'] = array('IN', $id);
$result = db('ad')->where($map)->delete(); $result = db('ad')->where($map)->delete();
if ($result) { if ($result) {
return $this->success("删除成功!"); return $this->success("删除成功!");
}else{ } else {
return $this->error("删除失败!"); return $this->error("删除失败!");
} }
} }

View File

@@ -275,10 +275,8 @@ class Addons extends Admin {
//超级管理员删除钩子 //超级管理员删除钩子
public function delhook() { public function delhook() {
$id = input('id', '', 'trim,intval'); $id = $this->getArrayParam('id');
$ids = input('post.ids/a', array()); $map['id'] = array('IN', $id);
array_push($ids, $id);
$map['id'] = array('IN', $ids);
$result = $this->hooks->where($map)->delete(); $result = $this->hooks->where($map)->delete();
if ($result !== false) { if ($result !== false) {
return $this->success('删除成功'); return $this->success('删除成功');

View File

@@ -17,7 +17,7 @@ class Attribute extends Admin {
protected $attr; protected $attr;
//初始化 //初始化
public function _initialize(){ public function _initialize() {
parent::_initialize(); parent::_initialize();
$this->getContentMenu(); $this->getContentMenu();
$this->model = model('Attribute'); $this->model = model('Attribute');
@@ -26,27 +26,26 @@ class Attribute extends Admin {
$this->attr[$key] = $value[0]; $this->attr[$key] = $value[0];
} }
$this->validate_rule = array( $this->validate_rule = array(
0=>'请选择', 0 => '请选择',
'regex'=>'正则验证', 'regex' => '正则验证',
'function'=>'函数验证', 'function' => '函数验证',
'unique'=>'唯一验证', 'unique' => '唯一验证',
'length'=>'长度验证', 'length' => '长度验证',
'in'=>'验证在范围内', 'in' => '验证在范围内',
'notin'=>'验证不在范围内', 'notin' => '验证不在范围内',
'between'=>'区间验证', 'between' => '区间验证',
'notbetween'=>'不在区间验证' 'notbetween' => '不在区间验证',
); );
$this->auto_type = array(0=>'请选择','function'=>'函数','field'=>'字段','string'=>'字符串'); $this->auto_type = array(0 => '请选择', 'function' => '函数', 'field' => '字段', 'string' => '字符串');
$this->the_time = array(0=>'请选择','3'=>'始 终','1'=>'新 增','2'=>'编 辑'); $this->the_time = array(0 => '请选择', '3' => '始 终', '1' => '新 增', '2' => '编 辑');
$this->field = $this->getField(); $this->field = $this->getField();
} }
/** /**
* index方法 * index方法
* @author colin <colin@tensent.cn> * @author colin <colin@tensent.cn>
*/ */
public function index($model_id = null){ public function index($model_id = null) {
$map['model_id'] = $model_id; $map['model_id'] = $model_id;
if (!$model_id) { if (!$model_id) {
return $this->error("非法操作!"); return $this->error("非法操作!");
@@ -55,9 +54,9 @@ class Attribute extends Admin {
$list = model('Attribute')->where($map)->order('id desc')->paginate(25); $list = model('Attribute')->where($map)->order('id desc')->paginate(25);
$data = array( $data = array(
'list' => $list, 'list' => $list,
'model_id'=> $model_id, 'model_id' => $model_id,
'page' => $list->render() 'page' => $list->render(),
); );
$this->assign($data); $this->assign($data);
$this->setMeta('字段管理'); $this->setMeta('字段管理');
@@ -68,22 +67,22 @@ class Attribute extends Admin {
* 创建字段 * 创建字段
* @author colin <colin@tensent.cn> * @author colin <colin@tensent.cn>
*/ */
public function add(){ public function add() {
$model_id = input('model_id','','trim,intval'); $model_id = input('model_id', '', 'trim,intval');
if(IS_POST){ if (IS_POST) {
$result = $this->model->change(); $result = $this->model->change();
if ($result) { if ($result) {
return $this->success("创建成功!",url('Attribute/index',array('model_id'=>$model_id))); return $this->success("创建成功!", url('Attribute/index', array('model_id' => $model_id)));
}else{ } else {
return $this->error($this->model->getError()); return $this->error($this->model->getError());
} }
}else{ } else {
if (!$model_id) { if (!$model_id) {
return $this->error('非法操作!'); return $this->error('非法操作!');
} }
$data = array( $data = array(
'info' => array('model_id'=>$model_id), 'info' => array('model_id' => $model_id),
'fieldGroup' => $this->field 'fieldGroup' => $this->field,
); );
$this->assign($data); $this->assign($data);
$this->setMeta('添加字段'); $this->setMeta('添加字段');
@@ -95,20 +94,20 @@ class Attribute extends Admin {
* 编辑字段方法 * 编辑字段方法
* @author colin <colin@tensent.cn> * @author colin <colin@tensent.cn>
*/ */
public function edit(){ public function edit() {
if(IS_POST){ if (IS_POST) {
$result = $this->model->change(); $result = $this->model->change();
if ($result) { if ($result) {
return $this->success("修改成功!",url('Attribute/index',array('model_id'=>$_POST['model_id']))); return $this->success("修改成功!", url('Attribute/index', array('model_id' => $_POST['model_id'])));
}else{ } else {
return $this->error($this->model->getError()); return $this->error($this->model->getError());
} }
}else{ } else {
$id = input('id','','trim,intval'); $id = input('id', '', 'trim,intval');
$info = db('Attribute')->find($id); $info = db('Attribute')->find($id);
$data = array( $data = array(
'info' => $info, 'info' => $info,
'fieldGroup' => $this->field 'fieldGroup' => $this->field,
); );
$this->assign($data); $this->assign($data);
$this->setMeta('编辑字段'); $this->setMeta('编辑字段');
@@ -121,8 +120,8 @@ class Attribute extends Admin {
* @var delattr 是否删除字段表里的字段 * @var delattr 是否删除字段表里的字段
* @author colin <colin@tensent.cn> * @author colin <colin@tensent.cn>
*/ */
public function del(){ public function del() {
$id = input('id','','trim,intval'); $id = input('id', '', 'trim,intval');
if (!$id) { if (!$id) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
@@ -130,35 +129,35 @@ class Attribute extends Admin {
$result = $this->model->del($id); $result = $this->model->del($id);
if ($result) { if ($result) {
return $this->success("删除成功!"); return $this->success("删除成功!");
}else{ } else {
return $this->error($this->model->getError()); return $this->error($this->model->getError());
} }
} }
//字段编辑所需字段 //字段编辑所需字段
protected function getField(){ protected function getField() {
return array( return array(
'基础' => array( '基础' => array(
array('name'=>'id','title'=>'id','help'=>'','type'=>'hidden'), array('name' => 'id', 'title' => 'id', 'help' => '', 'type' => 'hidden'),
array('name'=>'model_id','title'=>'model_id','help'=>'','type'=>'hidden'), array('name' => 'model_id', 'title' => 'model_id', 'help' => '', 'type' => 'hidden'),
array('name'=>'name','title'=>'字段名','help'=>'英文字母开头长度不超过30','type'=>'text'), array('name' => 'name', 'title' => '字段名', 'help' => '英文字母开头长度不超过30', 'type' => 'text'),
array('name'=>'title','title'=>'字段标题','help'=>'请输入字段标题,用于表单显示','type'=>'text'), array('name' => 'title', 'title' => '字段标题', 'help' => '请输入字段标题,用于表单显示', 'type' => 'text'),
array('name'=>'type','title'=>'字段类型','help'=>'用于表单中的展示方式','type'=>'select','option'=>$this->attr,'help'=>''), array('name' => 'type', 'title' => '字段类型', 'help' => '用于表单中的展示方式', 'type' => 'select', 'option' => $this->attr, 'help' => ''),
array('name'=>'length','title'=>'字段长度','help'=>'字段的长度值','type'=>'text'), array('name' => 'length', 'title' => '字段长度', 'help' => '字段的长度值', 'type' => 'text'),
array('name'=>'extra','title'=>'参数','help'=>'布尔、枚举、多选字段类型的定义数据','type'=>'textarea'), array('name' => 'extra', 'title' => '参数', 'help' => '布尔、枚举、多选字段类型的定义数据', 'type' => 'textarea'),
array('name'=>'value','title'=>'默认值','help'=>'字段的默认值','type'=>'text'), array('name' => 'value', 'title' => '默认值', 'help' => '字段的默认值', 'type' => 'text'),
array('name'=>'remark','title'=>'字段备注','help'=>'用于表单中的提示','type'=>'text'), array('name' => 'remark', 'title' => '字段备注', 'help' => '用于表单中的提示', 'type' => 'text'),
array('name'=>'is_show','title'=>'是否显示','help'=>'是否显示在表单中','type'=>'select','option'=>array('1'=>'始终显示','2'=>'新增显示','3'=>'编辑显示','0'=>'不显示'),'value'=>1), array('name' => 'is_show', 'title' => '是否显示', 'help' => '是否显示在表单中', 'type' => 'select', 'option' => array('1' => '始终显示', '2' => '新增显示', '3' => '编辑显示', '0' => '不显示'), 'value' => 1),
array('name'=>'is_must','title'=>'是否必填','help'=>'用于自动验证','type'=>'select','option'=>array('0'=>'否','1'=>'是')) array('name' => 'is_must', 'title' => '是否必填', 'help' => '用于自动验证', 'type' => 'select', 'option' => array('0' => '否', '1' => '是')),
), ),
'高级' => array( '高级' => array(
array('name'=>'validate_type','title'=>'验证方式','type'=>'select','option'=>$this->validate_rule,'help'=>''), array('name' => 'validate_type', 'title' => '验证方式', 'type' => 'select', 'option' => $this->validate_rule, 'help' => ''),
array('name'=>'validate_rule','title'=>'验证规则','help'=>'根据验证方式定义相关验证规则','type'=>'text'), array('name' => 'validate_rule', 'title' => '验证规则', 'help' => '根据验证方式定义相关验证规则', 'type' => 'text'),
array('name'=>'error_info','title'=>'出错提示','type'=>'text','help'=>''), array('name' => 'error_info', 'title' => '出错提示', 'type' => 'text', 'help' => ''),
array('name'=>'validate_time','title'=>'验证时间','help'=>'英文字母开头长度不超过30','type'=>'select','option'=>$this->the_time,'help'=>''), array('name' => 'validate_time', 'title' => '验证时间', 'help' => '英文字母开头长度不超过30', 'type' => 'select', 'option' => $this->the_time, 'help' => ''),
array('name'=>'auto_type','title'=>'自动完成方式','help'=>'英文字母开头长度不超过30','type'=>'select','option'=>$this->auto_type,'help'=>''), array('name' => 'auto_type', 'title' => '自动完成方式', 'help' => '英文字母开头长度不超过30', 'type' => 'select', 'option' => $this->auto_type, 'help' => ''),
array('name'=>'auto_rule','title'=>'自动完成规则','help'=>'根据完成方式订阅相关规则','type'=>'text'), array('name' => 'auto_rule', 'title' => '自动完成规则', 'help' => '根据完成方式订阅相关规则', 'type' => 'text'),
array('name'=>'auto_time','title'=>'自动完成时间','help'=>'英文字母开头长度不超过30','type'=>'select','option'=>$this->the_time), array('name' => 'auto_time', 'title' => '自动完成时间', 'help' => '英文字母开头长度不超过30', 'type' => 'select', 'option' => $this->the_time),
), ),
); );
} }

View File

@@ -218,7 +218,7 @@ class Category extends Admin {
} }
public function status() { public function status() {
$id = $this->getArrayParam('id'); $id = $this->getArrayParam('id');
$status = input('status', '0', 'trim,intval'); $status = input('status', '0', 'trim,intval');
if (!$id) { if (!$id) {

View File

@@ -10,23 +10,23 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\common\controller\Admin; use app\common\controller\Admin;
class Channel extends Admin{ class Channel extends Admin {
public function _initialize(){ public function _initialize() {
parent::_initialize(); parent::_initialize();
} }
public function index(){ public function index() {
$pid = input('pid', 0); $pid = input('pid', 0);
/* 获取频道列表 */ /* 获取频道列表 */
//$map = array('status' => array('gt', -1), 'pid'=>$pid); //$map = array('status' => array('gt', -1), 'pid'=>$pid);
$map = array('status' => array('gt', -1)); $map = array('status' => array('gt', -1));
$list = db('Channel')->where($map)->order('sort asc,id asc')->column('*','id'); $list = db('Channel')->where($map)->order('sort asc,id asc')->column('*', 'id');
if (!empty($list)) { if (!empty($list)) {
$tree = new \com\Tree(); $tree = new \com\Tree();
$list = $tree->toFormatTree($list); $list = $tree->toFormatTree($list);
} }
config('_sys_get_channel_tree_', true); config('_sys_get_channel_tree_', true);
@@ -50,7 +50,7 @@ class Channel extends Admin{
public function add() { public function add() {
if (IS_POST) { if (IS_POST) {
$Channel = model('Channel'); $Channel = model('Channel');
$data = $this->request->post(); $data = $this->request->post();
if ($data) { if ($data) {
$id = $Channel->save($data); $id = $Channel->save($data);
if ($id) { if ($id) {
@@ -86,9 +86,9 @@ class Channel extends Admin{
public function edit($id = 0) { public function edit($id = 0) {
if (IS_POST) { if (IS_POST) {
$Channel = model('Channel'); $Channel = model('Channel');
$data = $this->request->post(); $data = $this->request->post();
if ($data) { if ($data) {
if (false !== $Channel->save($data,array('id'=>$data['id']))) { if (false !== $Channel->save($data, array('id' => $data['id']))) {
//记录行为 //记录行为
action_log('update_channel', 'channel', $data['id'], session('user_auth.uid')); action_log('update_channel', 'channel', $data['id'], session('user_auth.uid'));
return $this->success('编辑成功', url('index')); return $this->success('编辑成功', url('index'));
@@ -171,7 +171,7 @@ class Channel extends Admin{
$res = db('Channel')->where(array('id' => $value))->setField('sort', $key + 1); $res = db('Channel')->where(array('id' => $value))->setField('sort', $key + 1);
} }
if ($res !== false) { if ($res !== false) {
return $this->success('排序成功!',url('admin/channel/index')); return $this->success('排序成功!', url('admin/channel/index'));
} else { } else {
return $this->error('排序失败!'); return $this->error('排序失败!');
} }
@@ -180,19 +180,19 @@ class Channel extends Admin{
} }
} }
public function setStatus(){ public function setStatus() {
$id = array_unique((array)input('ids', 0)); $id = array_unique((array) input('ids', 0));
$status = input('status','0','trim'); $status = input('status', '0', 'trim');
if (empty($id)) { if (empty($id)) {
return $this->error('请选择要操作的数据!'); return $this->error('请选择要操作的数据!');
} }
$map = array('id' => array('in', $id)); $map = array('id' => array('in', $id));
$result = db('Channel')->where($map)->update(array('status'=>$status)); $result = db('Channel')->where($map)->update(array('status' => $status));
if ($result) { if ($result) {
return $this->success("操作成功!"); return $this->success("操作成功!");
}else{ } else {
return $this->error("操作失败!"); return $this->error("操作失败!");
} }
} }

View File

@@ -10,9 +10,9 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\common\controller\Admin; use app\common\controller\Admin;
class Config extends Admin{ class Config extends Admin {
public function _initialize(){ public function _initialize() {
parent::_initialize(); parent::_initialize();
$this->model = model('Config'); $this->model = model('Config');
} }
@@ -29,7 +29,7 @@ class Config extends Admin{
$map['group'] = input('group', 0); $map['group'] = input('group', 0);
} }
if (isset($_GET['name'])) { if (isset($_GET['name'])) {
$map['name'] = array('like', '%' . (string)input('name') . '%'); $map['name'] = array('like', '%' . (string) input('name') . '%');
} }
$list = $this->model->where($map)->order('id desc')->paginate(25); $list = $this->model->where($map)->order('id desc')->paginate(25);
@@ -37,11 +37,11 @@ class Config extends Admin{
Cookie('__forward__', $_SERVER['REQUEST_URI']); Cookie('__forward__', $_SERVER['REQUEST_URI']);
$data = array( $data = array(
'group' => config('config_group_list'), 'group' => config('config_group_list'),
'config_type' => config('config_config_list'), 'config_type' => config('config_config_list'),
'page' => $list->render(), 'page' => $list->render(),
'group_id' => input('get.group', 0), 'group_id' => input('get.group', 0),
'list' => $list 'list' => $list,
); );
$this->assign($data); $this->assign($data);
@@ -49,17 +49,17 @@ class Config extends Admin{
return $this->fetch(); return $this->fetch();
} }
public function group($id = 1){ public function group($id = 1) {
if (IS_POST) { if (IS_POST) {
$config = $this->request->post('config/a'); $config = $this->request->post('config/a');
$model = model('Config'); $model = model('Config');
foreach ($config as $key => $value) { foreach ($config as $key => $value) {
$model->where(array('name'=>$key))->setField('value', $value); $model->where(array('name' => $key))->setField('value', $value);
} }
//清除db_config_data缓存 //清除db_config_data缓存
cache('db_config_data', null); cache('db_config_data', null);
return $this->success("更新成功!"); return $this->success("更新成功!");
}else{ } else {
$type = config('config_group_list'); $type = config('config_group_list');
$list = db("Config")->where(array('status' => 1, 'group' => $id))->field('id,name,title,extra,value,remark,type')->order('sort')->select(); $list = db("Config")->where(array('status' => 1, 'group' => $id))->field('id,name,title,extra,value,remark,type')->order('sort')->select();
if ($list) { if ($list) {
@@ -78,7 +78,7 @@ class Config extends Admin{
public function add() { public function add() {
if (IS_POST) { if (IS_POST) {
$config = model('Config'); $config = model('Config');
$data = $this->request->post(); $data = $this->request->post();
if ($data) { if ($data) {
$id = $config->validate(true)->save($data); $id = $config->validate(true)->save($data);
if ($id) { if ($id) {
@@ -86,23 +86,19 @@ class Config extends Admin{
//记录行为 //记录行为
action_log('update_config', 'config', $id, session('user_auth.uid')); action_log('update_config', 'config', $id, session('user_auth.uid'));
return $this->success('新增成功', url('index')); return $this->success('新增成功', url('index'));
} } else {
else {
return $this->error('新增失败'); return $this->error('新增失败');
} }
} } else {
else {
return $this->error($config->getError()); return $this->error($config->getError());
} }
} } else {
else {
$this->setMeta('新增配置'); $this->setMeta('新增配置');
$this->assign('info', null); $this->assign('info', null);
return $this->fetch('edit'); return $this->fetch('edit');
} }
} }
/** /**
* 编辑配置 * 编辑配置
* @author 麦当苗儿 <zuojiazi@vip.qq.com> * @author 麦当苗儿 <zuojiazi@vip.qq.com>
@@ -110,9 +106,9 @@ class Config extends Admin{
public function edit($id = 0) { public function edit($id = 0) {
if (IS_POST) { if (IS_POST) {
$config = model('Config'); $config = model('Config');
$data = $this->request->post(); $data = $this->request->post();
if ($data) { if ($data) {
$result = $config->validate('Config.edit')->save($data,array('id'=>$data['id'])); $result = $config->validate('Config.edit')->save($data, array('id' => $data['id']));
if (false !== $result) { if (false !== $result) {
cache('db_config_data', null); cache('db_config_data', null);
//记录行为 //记录行为
@@ -121,10 +117,10 @@ class Config extends Admin{
} else { } else {
return $this->error($config->getError(), ''); return $this->error($config->getError(), '');
} }
}else { } else {
return $this->error($config->getError()); return $this->error($config->getError());
} }
}else{ } else {
$info = array(); $info = array();
/* 获取数据 */ /* 获取数据 */
$info = db('Config')->field(true)->find($id); $info = db('Config')->field(true)->find($id);
@@ -157,7 +153,7 @@ class Config extends Admin{
* @author 麦当苗儿 <zuojiazi@vip.qq.com> * @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/ */
public function del() { public function del() {
$id = array_unique((array)input('id', 0)); $id = array_unique((array) input('id', 0));
if (empty($id)) { if (empty($id)) {
return $this->error('请选择要操作的数据!'); return $this->error('请选择要操作的数据!');
@@ -174,7 +170,6 @@ class Config extends Admin{
} }
} }
/** /**
* 配置排序 * 配置排序
* @author huajie <banhuajie@163.com> * @author huajie <banhuajie@163.com>
@@ -186,8 +181,7 @@ class Config extends Admin{
$map = array('status' => array('gt', -1)); $map = array('status' => array('gt', -1));
if (!empty($ids)) { if (!empty($ids)) {
$map['id'] = array('in', $ids); $map['id'] = array('in', $ids);
} } elseif (input('group')) {
elseif (input('group')) {
$map['group'] = input('group'); $map['group'] = input('group');
} }
$list = db('Config')->where($map)->field('id,title')->order('sort asc,id asc')->select(); $list = db('Config')->where($map)->field('id,title')->order('sort asc,id asc')->select();
@@ -195,8 +189,7 @@ class Config extends Admin{
$this->assign('list', $list); $this->assign('list', $list);
$this->setMeta('配置排序'); $this->setMeta('配置排序');
return $this->fetch(); return $this->fetch();
} } elseif (IS_POST) {
elseif (IS_POST) {
$ids = input('post.ids'); $ids = input('post.ids');
$ids = explode(',', $ids); $ids = explode(',', $ids);
foreach ($ids as $key => $value) { foreach ($ids as $key => $value) {
@@ -204,12 +197,10 @@ class Config extends Admin{
} }
if ($res !== false) { if ($res !== false) {
return $this->success('排序成功!', Cookie('__forward__')); return $this->success('排序成功!', Cookie('__forward__'));
} } else {
else {
return $this->error('排序失败!'); return $this->error('排序失败!');
} }
} } else {
else {
return $this->error('非法请求!'); return $this->error('非法请求!');
} }
} }

View File

@@ -10,30 +10,30 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\common\controller\Admin; use app\common\controller\Admin;
class Content extends Admin{ class Content extends Admin {
public function _initialize(){ public function _initialize() {
parent::_initialize(); parent::_initialize();
$this->getContentMenu(); $this->getContentMenu();
$this->model_id = $model_id = $this->request->param('model_id'); $this->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) {
$list[$value['id']] = $value; $list[$value['id']] = $value;
} }
if (empty($list[$model_id])) { if (empty($list[$model_id])) {
return $this->error("无此模型!"); return $this->error("无此模型!");
}else { } else {
$this->modelInfo = $list[$model_id]; $this->modelInfo = $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',$model_id); $this->assign('model_id', $model_id);
$this->assign('model_list',$list); $this->assign('model_list', $list);
} }
/** /**
@@ -41,32 +41,32 @@ class Content extends Admin{
* @return [html] [页面内容] * @return [html] [页面内容]
* @author molong <ycgpp@126.com> * @author molong <ycgpp@126.com>
*/ */
public function index(){ public function index() {
if ($this->modelInfo['list_grid'] == '') { if ($this->modelInfo['list_grid'] == '') {
return $this->error("列表定义不正确!", url('admin/model/edit',array('id'=>$this->modelInfo['id']))); return $this->error("列表定义不正确!", url('admin/model/edit', array('id' => $this->modelInfo['id'])));
} }
$grid_list = get_grid_list($this->modelInfo['list_grid']); $grid_list = get_grid_list($this->modelInfo['list_grid']);
$order = "id desc"; $order = "id desc";
$map = $this->buildMap(); $map = $this->buildMap();
$field = array_filter($grid_list['fields']); $field = array_filter($grid_list['fields']);
if ($this->modelInfo['extend'] == 1) { if ($this->modelInfo['extend'] == 1) {
array_push($field, 'is_top'); array_push($field, 'is_top');
}else{ } else {
unset($map['model_id']); unset($map['model_id']);
} }
$list = $this->model->where($map)->order($order)->paginate(15, false, array( $list = $this->model->where($map)->order($order)->paginate(15, false, array(
'query' => $this->param 'query' => $this->param,
)); ));
$data = array( $data = array(
'grid' => $grid_list, 'grid' => $grid_list,
'list' => $list, 'list' => $list,
'page' => $list->render() 'page' => $list->render(),
); );
if($this->modelInfo['template_list']){ if ($this->modelInfo['template_list']) {
$template = 'content/' . $this->modelInfo['template_list']; $template = 'content/' . $this->modelInfo['template_list'];
}else{ } else {
$template = 'content/index'; $template = 'content/index';
} }
$this->assign($data); $this->assign($data);
@@ -78,29 +78,29 @@ class Content extends Admin{
* 内容添加 * 内容添加
* @author molong <ycgpp@126.com> * @author molong <ycgpp@126.com>
*/ */
public function add(){ public function add() {
if (IS_POST) { if (IS_POST) {
$result = $this->model->change(); $result = $this->model->change();
if ($result) { if ($result) {
return $this->success("添加成功!", url('admin/content/index',array('model_id'=>$this->modelInfo['id']))); return $this->success("添加成功!", url('admin/content/index', array('model_id' => $this->modelInfo['id'])));
}else{ } else {
return $this->error($this->model->getError(), url('admin/content/add',array('model_id'=>$this->modelInfo['id']))); return $this->error($this->model->getError(), url('admin/content/add', array('model_id' => $this->modelInfo['id'])));
} }
}else{ } else {
$info = array( $info = array(
'model_id' => $this->modelInfo['id'] 'model_id' => $this->modelInfo['id'],
); );
$data = array( $data = array(
'info' => $info, 'info' => $info,
'fieldGroup' => $this->getField($this->modelInfo) 'fieldGroup' => $this->getField($this->modelInfo),
); );
if($this->modelInfo['template_add']){ if ($this->modelInfo['template_add']) {
$template = 'content/' . $this->modelInfo['template_add']; $template = 'content/' . $this->modelInfo['template_add'];
}else{ } else {
$template = 'public/edit'; $template = 'public/edit';
} }
$this->assign($data); $this->assign($data);
$this->setMeta("添加".$this->modelInfo['title']); $this->setMeta("添加" . $this->modelInfo['title']);
return $this->fetch($template); return $this->fetch($template);
} }
} }
@@ -109,15 +109,15 @@ class Content extends Admin{
* 内容修改 * 内容修改
* @author molong <ycgpp@126.com> * @author molong <ycgpp@126.com>
*/ */
public function edit($id){ public function edit($id) {
if (IS_POST) { if (IS_POST) {
$result = $this->model->change(); $result = $this->model->change();
if ($result !== false) { if ($result !== false) {
return $this->success("更新成功!",url('admin/content/index',array('model_id'=>$this->modelInfo['id']))); return $this->success("更新成功!", url('admin/content/index', array('model_id' => $this->modelInfo['id'])));
}else{ } else {
return $this->error($this->model->getError(), url('admin/content/edit',array('model_id'=>$this->modelInfo['id'],'id'=>$id))); return $this->error($this->model->getError(), url('admin/content/edit', array('model_id' => $this->modelInfo['id'], 'id' => $id)));
} }
}else{ } else {
if (!$id) { if (!$id) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
@@ -126,17 +126,17 @@ class Content extends Admin{
return $this->error($this->model->getError()); return $this->error($this->model->getError());
} }
$info['model_id'] = $this->modelInfo['id']; $info['model_id'] = $this->modelInfo['id'];
$data = array( $data = array(
'info' => $info, 'info' => $info,
'fieldGroup' => $this->getField($this->modelInfo) 'fieldGroup' => $this->getField($this->modelInfo),
); );
if($this->modelInfo['template_edit']){ if ($this->modelInfo['template_edit']) {
$template = 'content/' . $this->modelInfo['template_edit']; $template = 'content/' . $this->modelInfo['template_edit'];
}else{ } else {
$template = 'public/edit'; $template = 'public/edit';
} }
$this->assign($data); $this->assign($data);
$this->setMeta("编辑".$this->modelInfo['title']); $this->setMeta("编辑" . $this->modelInfo['title']);
return $this->fetch($template); return $this->fetch($template);
} }
} }
@@ -145,18 +145,18 @@ class Content extends Admin{
* 内容删除 * 内容删除
* @author molong <ycgpp@126.com> * @author molong <ycgpp@126.com>
*/ */
public function del(){ public function del() {
$id = $this->getArrayParam('id'); $id = $this->getArrayParam('id');
if (empty($id)) { if (empty($id)) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
$map['id'] = array('IN',$id); $map['id'] = array('IN', $id);
$result = $this->model->del($map); $result = $this->model->del($map);
if ($result) { if ($result) {
return $this->success("删除成功!"); return $this->success("删除成功!");
}else{ } else {
return $this->error("删除失败!"); return $this->error("删除失败!");
} }
} }
@@ -165,14 +165,14 @@ class Content extends Admin{
* 设置状态 * 设置状态
* @author molong <ycgpp@126.com> * @author molong <ycgpp@126.com>
*/ */
public function status($id, $status){ public function status($id, $status) {
$model = $this->model; $model = $this->model;
$map['id'] = $id; $map['id'] = $id;
$result = $model::where($map)->setField('status',$status); $result = $model::where($map)->setField('status', $status);
if (false !== $result) { if (false !== $result) {
return $this->success("操作成功!"); return $this->success("操作成功!");
}else{ } else {
return $this->error("操作失败!!"); return $this->error("操作失败!!");
} }
} }
@@ -181,14 +181,14 @@ class Content extends Admin{
* 设置置顶 * 设置置顶
* @author molong <ycgpp@126.com> * @author molong <ycgpp@126.com>
*/ */
public function settop($id, $is_top){ public function settop($id, $is_top) {
$model = $this->model; $model = $this->model;
$map['id'] = $id; $map['id'] = $id;
$result = $model::where($map)->setField('is_top',$is_top); $result = $model::where($map)->setField('is_top', $is_top);
if (false !== $result) { if (false !== $result) {
return $this->success("操作成功!"); return $this->success("操作成功!");
}else{ } else {
return $this->error("操作失败!!"); return $this->error("操作失败!!");
} }
} }
@@ -198,26 +198,26 @@ class Content extends Admin{
* @return array 字段数组 * @return array 字段数组
* @author molong <ycgpp@126.com> * @author molong <ycgpp@126.com>
*/ */
protected function getField(){ protected function getField() {
$field_group = parse_config_attr($this->modelInfo['field_group']); $field_group = parse_config_attr($this->modelInfo['field_group']);
$field_sort = json_decode($this->modelInfo['field_sort'],true); $field_sort = json_decode($this->modelInfo['field_sort'], true);
if ($this->modelInfo['extend'] > 1) { if ($this->modelInfo['extend'] > 1) {
$map['model_id'] = $this->modelInfo['id']; $map['model_id'] = $this->modelInfo['id'];
}else{ } else {
$model_id[] = $this->modelInfo['id']; $model_id[] = $this->modelInfo['id'];
$model_id[] = 1; $model_id[] = 1;
$map['model_id'] = array('IN',$model_id); $map['model_id'] = array('IN', $model_id);
} }
if ($this->request->action() == 'add') { if ($this->request->action() == 'add') {
$map['is_show'] = array('in',array('1','2')); $map['is_show'] = array('in', array('1', '2'));
}elseif($this->request->action() == 'edit'){ } elseif ($this->request->action() == 'edit') {
$map['is_show'] = array('in',array('1','3')); $map['is_show'] = array('in', array('1', '3'));
} }
//获得数组的第一条数组 //获得数组的第一条数组
$first_key = array_keys($field_group); $first_key = array_keys($field_group);
$fields = model('Attribute')->getFieldlist($map); $fields = model('Attribute')->getFieldlist($map);
if (!empty($field_sort)) { if (!empty($field_sort)) {
foreach ($field_sort as $key => $value) { foreach ($field_sort as $key => $value) {
foreach ($value as $index) { foreach ($value as $index) {
@@ -229,8 +229,8 @@ class Content extends Admin{
} }
} }
//未进行排序的放入第一组中 //未进行排序的放入第一组中
$fields[] = array('name'=>'model_id','type'=>'hidden'); //加入模型ID值 $fields[] = array('name' => 'model_id', 'type' => 'hidden'); //加入模型ID值
$fields[] = array('name'=>'id','type'=>'hidden'); //加入模型ID值 $fields[] = array('name' => 'id', 'type' => 'hidden'); //加入模型ID值
foreach ($fields as $key => $value) { foreach ($fields as $key => $value) {
$groupfield[$first_key[0]][] = $value; $groupfield[$first_key[0]][] = $value;
} }
@@ -247,18 +247,18 @@ class Content extends Admin{
* 创建搜索 * 创建搜索
* @return [array] [查询条件] * @return [array] [查询条件]
*/ */
protected function buildMap(){ protected function buildMap() {
$map = array(); $map = array();
$data = $this->request->get(); $data = $this->request->get();
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
if ($value) { if ($value) {
if ($key == 'keyword') { if ($key == 'keyword') {
$map['title'] = array("LIKE", "%$value%"); $map['title'] = array("LIKE", "%$value%");
}elseif($key == 'category'){ } elseif ($key == 'category') {
$map['category_id'] = $value; $map['category_id'] = $value;
}elseif($key == 'create_time'){ } elseif ($key == 'create_time') {
$map['create_time'] = array('BETWEEN',array(strtotime($value[0]),strtotime($value[1]))); $map['create_time'] = array('BETWEEN', array(strtotime($value[0]), strtotime($value[1])));
}else{ } else {
$map[$key] = $value; $map[$key] = $value;
} }
} }
@@ -267,7 +267,7 @@ class Content extends Admin{
unset($map['page']); unset($map['page']);
} }
if ($this->modelInfo['extend'] == 1) { if ($this->modelInfo['extend'] == 1) {
$category = isset($data['category']) ? $data['category'] : ''; $category = isset($data['category']) ? $data['category'] : '';
$cate_list = parse_field_bind('category', $category, 0); $cate_list = parse_field_bind('category', $category, 0);
$this->assign('cate_list', $cate_list); $this->assign('cate_list', $cate_list);
} }
@@ -285,20 +285,20 @@ class Content extends Admin{
* *
* @author 朱亚杰 <xcoolcc@gmail.com> * @author 朱亚杰 <xcoolcc@gmail.com>
*/ */
protected function checkDynamic(){ protected function checkDynamic() {
$model_id = $this->request->param('model_id'); $model_id = $this->request->param('model_id');
if(IS_ROOT){ if (IS_ROOT) {
return true;//管理员允许访问任何页面 return true; //管理员允许访问任何页面
} }
$models = model('AuthGroup')->getAuthModels(session('user_auth.uid')); $models = model('AuthGroup')->getAuthModels(session('user_auth.uid'));
if (!$model_id) { if (!$model_id) {
return false; return false;
}elseif (in_array($model_id, $models)) { } elseif (in_array($model_id, $models)) {
//返回null继续判断操作权限 //返回null继续判断操作权限
return null; return null;
}else{ } else {
return false;//无权限 return false; //无权限
} }
return false; return false;
} }
} }

View File

@@ -18,52 +18,52 @@ class Database extends Admin {
*/ */
public function index($type = null) { public function index($type = null) {
switch ($type) { switch ($type) {
/* 数据还原 */ /* 数据还原 */
case 'import': case 'import':
//列出备份文件列表 //列出备份文件列表
$path = config('data_backup_path'); $path = config('data_backup_path');
if (!is_dir($path)) { if (!is_dir($path)) {
mkdir($path, 0755, true); mkdir($path, 0755, true);
} }
$path = realpath($path); $path = realpath($path);
$flag = \FilesystemIterator::KEY_AS_FILENAME; $flag = \FilesystemIterator::KEY_AS_FILENAME;
$glob = new \FilesystemIterator($path, $flag); $glob = new \FilesystemIterator($path, $flag);
$list = array(); $list = array();
foreach ($glob as $name => $file) { foreach ($glob as $name => $file) {
if (preg_match('/^\d{8,8}-\d{6,6}-\d+\.sql(?:\.gz)?$/', $name)) { if (preg_match('/^\d{8,8}-\d{6,6}-\d+\.sql(?:\.gz)?$/', $name)) {
$name = sscanf($name, '%4s%2s%2s-%2s%2s%2s-%d'); $name = sscanf($name, '%4s%2s%2s-%2s%2s%2s-%d');
$date = "{$name[0]}-{$name[1]}-{$name[2]}"; $date = "{$name[0]}-{$name[1]}-{$name[2]}";
$time = "{$name[3]}:{$name[4]}:{$name[5]}"; $time = "{$name[3]}:{$name[4]}:{$name[5]}";
$part = $name[6]; $part = $name[6];
if (isset($list["{$date} {$time}"])) { if (isset($list["{$date} {$time}"])) {
$info = $list["{$date} {$time}"]; $info = $list["{$date} {$time}"];
$info['part'] = max($info['part'], $part); $info['part'] = max($info['part'], $part);
$info['size'] = $info['size'] + $file->getSize(); $info['size'] = $info['size'] + $file->getSize();
} else { } else {
$info['part'] = $part; $info['part'] = $part;
$info['size'] = $file->getSize(); $info['size'] = $file->getSize();
}
$extension = strtoupper(pathinfo($file->getFilename(), PATHINFO_EXTENSION));
$info['compress'] = ($extension === 'SQL') ? '-' : $extension;
$info['time'] = strtotime("{$date} {$time}");
$list["{$date} {$time}"] = $info;
} }
$extension = strtoupper(pathinfo($file->getFilename(), PATHINFO_EXTENSION));
$info['compress'] = ($extension === 'SQL') ? '-' : $extension;
$info['time'] = strtotime("{$date} {$time}");
$list["{$date} {$time}"] = $info;
} }
$title = '数据还原'; }
$title = '数据还原';
break; break;
/* 数据备份 */ /* 数据备份 */
case 'export': case 'export':
$Db = \think\Db::connect(); $Db = \think\Db::connect();
$list = $Db->query('SHOW TABLE STATUS'); $list = $Db->query('SHOW TABLE STATUS');
$list = array_map('array_change_key_case', $list); $list = array_map('array_change_key_case', $list);
$title = '数据备份'; $title = '数据备份';
break; break;
default: default:
return $this->error('参数错误!'); return $this->error('参数错误!');
} }
//渲染模板 //渲染模板
$this->setMeta($title); $this->setMeta($title);
@@ -80,7 +80,7 @@ class Database extends Admin {
$Db = \think\Db::connect(); $Db = \think\Db::connect();
if (is_array($tables)) { if (is_array($tables)) {
$tables = implode('`,`', $tables); $tables = implode('`,`', $tables);
$list = $Db->query("OPTIMIZE TABLE `{$tables}`"); $list = $Db->query("OPTIMIZE TABLE `{$tables}`");
if ($list) { if ($list) {
return $this->success("数据表优化完成!"); return $this->success("数据表优化完成!");
@@ -109,7 +109,7 @@ class Database extends Admin {
$Db = \think\Db::connect(); $Db = \think\Db::connect();
if (is_array($tables)) { if (is_array($tables)) {
$tables = implode('`,`', $tables); $tables = implode('`,`', $tables);
$list = $Db->query("REPAIR TABLE `{$tables}`"); $list = $Db->query("REPAIR TABLE `{$tables}`");
if ($list) { if ($list) {
return $this->success("数据表修复完成!"); return $this->success("数据表修复完成!");
@@ -155,13 +155,14 @@ class Database extends Admin {
* @author 麦当苗儿 <zuojiazi@vip.qq.com> * @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/ */
public function export($tables = null, $id = null, $start = null) { public function export($tables = null, $id = null, $start = null) {
if (IS_POST && !empty($tables) && is_array($tables)) { //初始化 if (IS_POST && !empty($tables) && is_array($tables)) {
//初始化
$path = config('data_backup_path'); $path = config('data_backup_path');
if (!is_dir($path)) { if (!is_dir($path)) {
mkdir($path, 0755, true); mkdir($path, 0755, true);
} }
//读取备份配置 //读取备份配置
$config = array('path' => realpath($path) . DIRECTORY_SEPARATOR, 'part' => config('data_backup_part_size'), 'compress' => config('data_backup_compress'), 'level' => config('data_backup_compress_level'),); $config = array('path' => realpath($path) . DIRECTORY_SEPARATOR, 'part' => config('data_backup_part_size'), 'compress' => config('data_backup_compress'), 'level' => config('data_backup_compress_level'));
//检查是否有正在执行的任务 //检查是否有正在执行的任务
$lock = "{$config['path']}backup.lock"; $lock = "{$config['path']}backup.lock";
if (is_file($lock)) { if (is_file($lock)) {
@@ -176,7 +177,7 @@ class Database extends Admin {
} }
session('backup_config', $config); session('backup_config', $config);
//生成备份文件信息 //生成备份文件信息
$file = array('name' => date('Ymd-His', time()), 'part' => 1,); $file = array('name' => date('Ymd-His', time()), 'part' => 1);
session('backup_file', $file); session('backup_file', $file);
//缓存要备份的表 //缓存要备份的表
session('backup_tables', $tables); session('backup_tables', $tables);
@@ -188,18 +189,22 @@ class Database extends Admin {
} else { } else {
return $this->error('初始化失败,备份文件创建失败!'); return $this->error('初始化失败,备份文件创建失败!');
} }
} elseif (IS_GET && is_numeric($id) && is_numeric($start)) { //备份数据 } elseif (IS_GET && is_numeric($id) && is_numeric($start)) {
//备份数据
$tables = session('backup_tables'); $tables = session('backup_tables');
//备份指定表 //备份指定表
$Database = new \com\Database(session('backup_file'), session('backup_config')); $Database = new \com\Database(session('backup_file'), session('backup_config'));
$start = $Database->backup($tables[$id], $start); $start = $Database->backup($tables[$id], $start);
if (false === $start) { //出错 if (false === $start) {
//出错
return $this->error('备份出错!'); return $this->error('备份出错!');
} elseif (0 === $start) { //下一表 } elseif (0 === $start) {
//下一表
if (isset($tables[++$id])) { if (isset($tables[++$id])) {
$tab = array('id' => $id, 'start' => 0); $tab = array('id' => $id, 'start' => 0);
return $this->success('备份完成!', '', array('tab' => $tab)); return $this->success('备份完成!', '', array('tab' => $tab));
} else { //备份完成,清空缓存 } else {
//备份完成,清空缓存
unlink(session('backup_config.path') . 'backup.lock'); unlink(session('backup_config.path') . 'backup.lock');
session('backup_tables', null); session('backup_tables', null);
session('backup_file', null); session('backup_file', null);
@@ -207,11 +212,12 @@ class Database extends Admin {
return $this->success('备份完成!'); return $this->success('备份完成!');
} }
} else { } else {
$tab = array('id' => $id, 'start' => $start[0]); $tab = array('id' => $id, 'start' => $start[0]);
$rate = floor(100 * ($start[0] / $start[1])); $rate = floor(100 * ($start[0] / $start[1]));
return $this->success("正在备份...({$rate}%)", '', array('tab' => $tab)); return $this->success("正在备份...({$rate}%)", '', array('tab' => $tab));
} }
} else { //出错 } else {
//出错
return $this->error('参数错误!'); return $this->error('参数错误!');
} }
} }
@@ -220,16 +226,17 @@ class Database extends Admin {
* @author 麦当苗儿 <zuojiazi@vip.qq.com> * @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/ */
public function import($time = 0, $part = null, $start = null) { public function import($time = 0, $part = null, $start = null) {
if (is_numeric($time) && is_null($part) && is_null($start)) { //初始化 if (is_numeric($time) && is_null($part) && is_null($start)) {
//初始化
//获取备份文件信息 //获取备份文件信息
$name = date('Ymd-His', $time) . '-*.sql*'; $name = date('Ymd-His', $time) . '-*.sql*';
$path = realpath(config('data_backup_path')) . DIRECTORY_SEPARATOR . $name; $path = realpath(config('data_backup_path')) . DIRECTORY_SEPARATOR . $name;
$files = glob($path); $files = glob($path);
$list = array(); $list = array();
foreach ($files as $name) { foreach ($files as $name) {
$basename = basename($name); $basename = basename($name);
$match = sscanf($basename, '%4s%2s%2s-%2s%2s%2s-%d'); $match = sscanf($basename, '%4s%2s%2s-%2s%2s%2s-%d');
$gz = preg_match('/^\d{8,8}-\d{6,6}-\d+\.sql.gz$/', $basename); $gz = preg_match('/^\d{8,8}-\d{6,6}-\d+\.sql.gz$/', $basename);
$list[$match[6]] = array($match[6], $name, $gz); $list[$match[6]] = array($match[6], $name, $gz);
} }
ksort($list); ksort($list);
@@ -250,7 +257,8 @@ class Database extends Admin {
if (false === $start) { if (false === $start) {
return $this->error('还原数据出错!'); return $this->error('还原数据出错!');
} elseif (0 === $start) { //下一卷 } elseif (0 === $start) {
//下一卷
if (isset($list[++$part])) { if (isset($list[++$part])) {
$data = array('part' => $part, 'start' => 0); $data = array('part' => $part, 'start' => 0);
return $this->success("正在还原...#{$part}", '', $data); return $this->success("正在还原...#{$part}", '', $data);
@@ -263,8 +271,7 @@ class Database extends Admin {
if ($start[1]) { if ($start[1]) {
$rate = floor(100 * ($start[0] / $start[1])); $rate = floor(100 * ($start[0] / $start[1]));
return $this->success("正在还原...#{$part} ({$rate}%)", '', $data); return $this->success("正在还原...#{$part} ({$rate}%)", '', $data);
} } else {
else {
$data['gz'] = 1; $data['gz'] = 1;
return $this->success("正在还原...#{$part}", '', $data); return $this->success("正在还原...#{$part}", '', $data);
} }

View File

@@ -15,23 +15,22 @@ class Group extends Admin {
protected $model; protected $model;
protected $rule; protected $rule;
public function _initialize(){ public function _initialize() {
parent::_initialize(); parent::_initialize();
$this->group = model('AuthGroup'); $this->group = model('AuthGroup');
$this->rule = model('AuthRule'); $this->rule = model('AuthRule');
} }
//会员分组首页控制器 //会员分组首页控制器
public function index($type = 'admin'){ public function index($type = 'admin') {
$map['module'] = $type; $map['module'] = $type;
$list = db('AuthGroup')->where($map)->order('id desc')->paginate(10); $list = db('AuthGroup')->where($map)->order('id desc')->paginate(10);
$data = array( $data = array(
'list' => $list, 'list' => $list,
'page' => $list->render(), 'page' => $list->render(),
'type' => $type 'type' => $type,
); );
$this->assign($data); $this->assign($data);
$this->setMeta('用户组管理'); $this->setMeta('用户组管理');
@@ -39,18 +38,18 @@ class Group extends Admin {
} }
//会员分组添加控制器 //会员分组添加控制器
public function add($type = 'admin'){ public function add($type = 'admin') {
if (IS_POST) { if (IS_POST) {
$result = $this->group->change(); $result = $this->group->change();
if ($result) { if ($result) {
return $this->success("添加成功!", url('admin/group/index')); return $this->success("添加成功!", url('admin/group/index'));
}else{ } else {
return $this->error("添加失败!"); return $this->error("添加失败!");
} }
}else{ } else {
$data = array( $data = array(
'info' => array('module' => $type,'status' => 1), 'info' => array('module' => $type, 'status' => 1),
'keyList' => $this->group->keyList 'keyList' => $this->group->keyList,
); );
$this->assign($data); $this->assign($data);
$this->setMeta('添加用户组'); $this->setMeta('添加用户组');
@@ -59,7 +58,7 @@ class Group extends Admin {
} }
//会员分组编辑控制器 //会员分组编辑控制器
public function edit($id){ public function edit($id) {
if (!$id) { if (!$id) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
@@ -67,14 +66,14 @@ class Group extends Admin {
$result = $this->group->change(); $result = $this->group->change();
if ($result) { if ($result) {
return $this->success("编辑成功!", url('admin/group/index')); return $this->success("编辑成功!", url('admin/group/index'));
}else{ } else {
return $this->error("编辑失败!"); return $this->error("编辑失败!");
} }
}else{ } else {
$info = $this->group->where(array('id'=>$id))->find(); $info = $this->group->where(array('id' => $id))->find();
$data = array( $data = array(
'info' => $info, 'info' => $info,
'keyList' => $this->group->keyList 'keyList' => $this->group->keyList,
); );
$this->assign($data); $this->assign($data);
$this->setMeta('编辑用户组'); $this->setMeta('编辑用户组');
@@ -83,42 +82,42 @@ class Group extends Admin {
} }
//会员分组编辑字段控制器 //会员分组编辑字段控制器
public function editable(){ public function editable() {
$pk = input('pk','','trim,intval'); $pk = input('pk', '', 'trim,intval');
$name = input('name','','trim'); $name = input('name', '', 'trim');
$value = input('value','','trim'); $value = input('value', '', 'trim');
$result = $this->group->where(array('id'=>$pk))->setField($name,$value); $result = $this->group->where(array('id' => $pk))->setField($name, $value);
if ($result) { if ($result) {
return $this->success("删除成功!"); return $this->success("删除成功!");
}else{ } else {
return $this->error("删除失败!"); return $this->error("删除失败!");
} }
} }
//会员分组删除控制器 //会员分组删除控制器
public function del(){ public function del() {
$id = $this->getArrayParam('id'); $id = $this->getArrayParam('id');
if (empty($id)) { if (empty($id)) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
$result = $this->group->where(array('id'=>array('IN', $id)))->delete(); $result = $this->group->where(array('id' => array('IN', $id)))->delete();
if ($result) { if ($result) {
return $this->success("删除成功!"); return $this->success("删除成功!");
}else{ } else {
return $this->error("删除失败!"); return $this->error("删除失败!");
} }
} }
//权限节点控制器 //权限节点控制器
public function access($type = 'admin'){ public function access($type = 'admin') {
$map['module'] = $type; $map['module'] = $type;
$list = db('AuthRule')->where($map)->order('id desc')->paginate(15); $list = db('AuthRule')->where($map)->order('id desc')->paginate(15);
$data = array( $data = array(
'list' => $list, 'list' => $list,
'page' => $list->render(), 'page' => $list->render(),
'type' => $type 'type' => $type,
); );
$this->assign($data); $this->assign($data);
$this->setMeta('权限节点'); $this->setMeta('权限节点');
@@ -126,62 +125,62 @@ class Group extends Admin {
} }
//根据菜单更新节点 //根据菜单更新节点
public function upnode($type){ public function upnode($type) {
$rule = model('Menu')->getAuthNodes($type); $rule = model('Menu')->getAuthNodes($type);
foreach ($rule as $value) { foreach ($rule as $value) {
$data = array( $data = array(
'module' => $type, 'module' => $type,
'type' => 2, 'type' => 2,
'name' => $value['url'], 'name' => $value['url'],
'title' => $value['title'], 'title' => $value['title'],
'group' => $value['group'], 'group' => $value['group'],
'status' => 1 'status' => 1,
); );
$id = $this->rule->where(array('name'=>$data['name']))->value('id'); $id = $this->rule->where(array('name' => $data['name']))->value('id');
if ($id) { if ($id) {
$data['id'] = $id; $data['id'] = $id;
$this->rule->save($data, array('id'=>$id)); $this->rule->save($data, array('id' => $id));
}else{ } else {
$this->rule->save($data); $this->rule->save($data);
} }
} }
return $this->success("更新成功!"); return $this->success("更新成功!");
} }
public function auth($id){ public function auth($id) {
if (!$id) { if (!$id) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
if (IS_POST) { if (IS_POST) {
$rule = $this->request->post('rule/a', array()); $rule = $this->request->post('rule/a', array());
$extend_rule = $this->request->post('extend_rule/a', array()); $extend_rule = $this->request->post('extend_rule/a', array());
$extend_result = $rule_result = false; $extend_result = $rule_result = false;
//扩展权限 //扩展权限
$extend_data = array(); $extend_data = array();
foreach ($extend_rule as $key => $value) { foreach ($extend_rule as $key => $value) {
foreach ($value as $item) { foreach ($value as $item) {
$extend_data[] = array('group_id'=> $id, 'extend_id' => $item, 'type'=> $key); $extend_data[] = array('group_id' => $id, 'extend_id' => $item, 'type' => $key);
} }
} }
if (!empty($extend_data)) { if (!empty($extend_data)) {
db('AuthExtend')->where(array('group_id'=>$id))->delete(); db('AuthExtend')->where(array('group_id' => $id))->delete();
$extend_result = db('AuthExtend')->insertAll($extend_data); $extend_result = db('AuthExtend')->insertAll($extend_data);
} }
if ($rule) { if ($rule) {
$rules = implode(',', $rule); $rules = implode(',', $rule);
$rule_result = $this->group->where(array('id'=>$id))->setField('rules',$rules); $rule_result = $this->group->where(array('id' => $id))->setField('rules', $rules);
} }
if ($rule_result !== false || $extend_result !== false) { if ($rule_result !== false || $extend_result !== false) {
return $this->success("授权成功!", url('admin/group/index')); return $this->success("授权成功!", url('admin/group/index'));
}else{ } else {
return $this->error("授权失败!"); return $this->error("授权失败!");
} }
}else{ } else {
$group = $this->group->where(array('id'=>$id))->find(); $group = $this->group->where(array('id' => $id))->find();
$map['module'] = $group['module']; $map['module'] = $group['module'];
$row = db('AuthRule')->where($map)->order('id desc')->select(); $row = db('AuthRule')->where($map)->order('id desc')->select();
$list = array(); $list = array();
foreach ($row as $key => $value) { foreach ($row as $key => $value) {
@@ -190,16 +189,16 @@ class Group extends Admin {
//模块 //模块
$model = db('model')->field('id,title,name') $model = db('model')->field('id,title,name')
->where(array('status' => array('gt',0), 'extend' => array('gt',0))) ->where(array('status' => array('gt', 0), 'extend' => array('gt', 0)))
->select(); ->select();
//扩展权限 //扩展权限
$extend_auth = db('AuthExtend')->where(array('group_id'=>$id,'type'=>2))->column('extend_id'); $extend_auth = db('AuthExtend')->where(array('group_id' => $id, 'type' => 2))->column('extend_id');
$data = array( $data = array(
'list' => $list, 'list' => $list,
'model' => $model, 'model' => $model,
'extend_auth' => $extend_auth, 'extend_auth' => $extend_auth,
'auth_list' => explode(',', $group['rules']), 'auth_list' => explode(',', $group['rules']),
'id' => $id 'id' => $id,
); );
$this->assign($data); $this->assign($data);
$this->setMeta('授权'); $this->setMeta('授权');
@@ -207,18 +206,18 @@ class Group extends Admin {
} }
} }
public function addnode($type = 'admin'){ public function addnode($type = 'admin') {
if (IS_POST) { if (IS_POST) {
$result = $this->rule->change(); $result = $this->rule->change();
if ($result) { if ($result) {
return $this->success("创建成功!", url('admin/group/access')); return $this->success("创建成功!", url('admin/group/access'));
}else{ } else {
return $this->error($this->rule->getError()); return $this->error($this->rule->getError());
} }
}else{ } else {
$data = array( $data = array(
'info' => array('module' => $type,'status' => 1), 'info' => array('module' => $type, 'status' => 1),
'keyList' => $this->rule->keyList 'keyList' => $this->rule->keyList,
); );
$this->assign($data); $this->assign($data);
$this->setMeta('添加节点'); $this->setMeta('添加节点');
@@ -226,22 +225,22 @@ class Group extends Admin {
} }
} }
public function editnode($id){ public function editnode($id) {
if (IS_POST) { if (IS_POST) {
$result = $this->rule->change(); $result = $this->rule->change();
if (false !== $result) { if (false !== $result) {
return $this->success("更新成功!", url('admin/group/access')); return $this->success("更新成功!", url('admin/group/access'));
}else{ } else {
return $this->error("更新失败!"); return $this->error("更新失败!");
} }
}else{ } else {
if (!$id) { if (!$id) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
$info = $this->rule->find($id); $info = $this->rule->find($id);
$data = array( $data = array(
'info' => $info, 'info' => $info,
'keyList' => $this->rule->keyList 'keyList' => $this->rule->keyList,
); );
$this->assign($data); $this->assign($data);
$this->setMeta('编辑节点'); $this->setMeta('编辑节点');
@@ -249,14 +248,14 @@ class Group extends Admin {
} }
} }
public function delnode($id){ public function delnode($id) {
if (!$id) { if (!$id) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
$result = $this->rule->where(array('id'=>$id))->delete(); $result = $this->rule->where(array('id' => $id))->delete();
if ($result) { if ($result) {
return $this->success("删除成功!"); return $this->success("删除成功!");
}else{ } else {
return $this->error("删除失败!"); return $this->error("删除失败!");
} }
} }

View File

@@ -10,67 +10,69 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\common\controller\Admin; use app\common\controller\Admin;
class Index extends Admin{ class Index extends Admin {
public function index(){ public function index() {
$this->setMeta('后台首页'); $this->setMeta('后台首页');
return $this->fetch(); return $this->fetch();
} }
public function login($username = '', $password = '', $verify = ''){ public function login($username = '', $password = '', $verify = '') {
if (IS_POST) { if (IS_POST) {
if (!$username || !$password) { if (!$username || !$password) {
return $this->error('用户名或者密码不能为空!',''); return $this->error('用户名或者密码不能为空!', '');
} }
//验证码验证 //验证码验证
$this->checkVerify($verify); $this->checkVerify($verify);
$user = model('User'); $user = model('User');
$uid = $user->login($username,$password); $uid = $user->login($username, $password);
if ($uid > 0) { if ($uid > 0) {
return $this->success('登录成功!',url('admin/index/index')); return $this->success('登录成功!', url('admin/index/index'));
}else{ } else {
switch($uid) { switch ($uid) {
case -1: $error = '用户不存在或被禁用!'; break; //系统级别禁用 case -1:$error = '用户不存在或被禁用!';
case -2: $error = '密码错误!'; break; break; //系统级别禁用
default: $error = '未知错误!'; break; // 0-接口参数错误(调试阶段使用) case -2:$error = '密码错误!';
break;
default:$error = '未知错误!';
break; // 0-接口参数错误(调试阶段使用)
} }
return $this->error($error,''); return $this->error($error, '');
} }
}else{ } else {
return $this->fetch(); return $this->fetch();
} }
} }
public function logout() {
public function logout(){
$user = model('User'); $user = model('User');
$user->logout(); $user->logout();
$this->redirect('index/login'); $this->redirect('index/login');
} }
public function clear(){ public function clear() {
if (IS_POST) { if (IS_POST) {
$clear = input('post.clear/a',array()); $clear = input('post.clear/a', array());
foreach ($clear as $key => $value) { foreach ($clear as $key => $value) {
if ($value == 'cache') { if ($value == 'cache') {
\think\Cache::clear(); // 清空缓存数据 \think\Cache::clear(); // 清空缓存数据
}elseif ($value == 'log') { } elseif ($value == 'log') {
\think\Log::clear(); \think\Log::clear();
} }
} }
return $this->success("更新成功!",url('admin/index/index')); return $this->success("更新成功!", url('admin/index/index'));
}else{ } else {
$keylist = array( $keylist = array(
array('name'=>'clear','title'=>'更新缓存','type'=>'checkbox','help'=>'','option'=>array( array('name' => 'clear', 'title' => '更新缓存', 'type' => 'checkbox', 'help' => '', 'option' => array(
'cache' => '缓存数据', 'cache' => '缓存数据',
'log' => '日志数据' 'log' => '日志数据',
) ),
) ),
); );
$data = array( $data = array(
'keyList' => $keylist, 'keyList' => $keylist,
); );
$this->assign($data); $this->assign($data);
$this->setMeta("更新缓存"); $this->setMeta("更新缓存");

View File

@@ -10,17 +10,17 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\common\controller\Admin; use app\common\controller\Admin;
class Link extends Admin{ class Link extends Admin {
public function index(){ public function index() {
$map = array(); $map = array();
$order = "id desc"; $order = "id desc";
$list = db('Link')->where($map)->order($order)->paginate(10); $list = db('Link')->where($map)->order($order)->paginate(10);
$data = array( $data = array(
'list' => $list, 'list' => $list,
'page' => $list->render() 'page' => $list->render(),
); );
$this->assign($data); $this->assign($data);
$this->setMeta("友情链接"); $this->setMeta("友情链接");
@@ -28,24 +28,24 @@ class Link extends Admin{
} }
//添加 //添加
public function add(){ public function add() {
$link = model('Link'); $link = model('Link');
if(IS_POST){ if (IS_POST) {
$data = input('post.'); $data = input('post.');
if ($data) { if ($data) {
unset($data['id']); unset($data['id']);
$result = $link->save($data); $result = $link->save($data);
if ($result) { if ($result) {
return $this->success("添加成功!",url('Link/index')); return $this->success("添加成功!", url('Link/index'));
}else{ } else {
return $this->error($link->getError()); return $this->error($link->getError());
} }
}else{ } else {
return $this->error($link->getError()); return $this->error($link->getError());
} }
}else{ } else {
$data = array( $data = array(
'keyList' => $link->keyList 'keyList' => $link->keyList,
); );
$this->assign($data); $this->assign($data);
$this->setMeta("添加友链"); $this->setMeta("添加友链");
@@ -54,28 +54,28 @@ class Link extends Admin{
} }
//修改 //修改
public function edit(){ public function edit() {
$link = model('Link'); $link = model('Link');
$id = input('id','','trim,intval'); $id = input('id', '', 'trim,intval');
if(IS_POST){ if (IS_POST) {
$data = input('post.'); $data = input('post.');
if ($data) { if ($data) {
$result = $link->save($data,array('id'=>$data['id'])); $result = $link->save($data, array('id' => $data['id']));
if ($result) { if ($result) {
return $this->success("修改成功!",url('Link/index')); return $this->success("修改成功!", url('Link/index'));
}else{ } else {
return $this->error("修改失败!"); return $this->error("修改失败!");
} }
}else{ } else {
return $this->error($link->getError()); return $this->error($link->getError());
} }
}else{ } else {
$map = array('id'=>$id); $map = array('id' => $id);
$info = db('Link')->where($map)->find(); $info = db('Link')->where($map)->find();
$data = array( $data = array(
'keyList' => $link->keyList, 'keyList' => $link->keyList,
'info' => $info 'info' => $info,
); );
$this->assign($data); $this->assign($data);
$this->setMeta("编辑友链"); $this->setMeta("编辑友链");
@@ -84,18 +84,18 @@ class Link extends Admin{
} }
//删除 //删除
public function delete(){ public function delete() {
$id = $this->getArrayParam('id'); $id = $this->getArrayParam('id');
if (empty($id)) { if (empty($id)) {
return $this->error('非法操作!'); return $this->error('非法操作!');
} }
$link = db('Link'); $link = db('Link');
$map = array('id'=>array('IN',$id)); $map = array('id' => array('IN', $id));
$result = $link->where($map)->delete(); $result = $link->where($map)->delete();
if ($result) { if ($result) {
return $this->success("删除成功!"); return $this->success("删除成功!");
}else{ } else {
return $this->error("删除失败!"); return $this->error("删除失败!");
} }
} }

View File

@@ -10,34 +10,34 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\common\controller\Admin; use app\common\controller\Admin;
class Menu extends Admin{ class Menu extends Admin {
public function _initialize(){ public function _initialize() {
parent::_initialize(); parent::_initialize();
} }
public function index(){ public function index() {
$map = array(); $map = array();
$title = trim(input('get.title')); $title = trim(input('get.title'));
$list = db("Menu")->where($map)->field(true)->order('sort asc,id asc')->column('*','id'); $list = db("Menu")->where($map)->field(true)->order('sort asc,id asc')->column('*', 'id');
int_to_string($list,array('hide'=>array(1=>'是',0=>'否'),'is_dev'=>array(1=>'是',0=>'否'))); int_to_string($list, array('hide' => array(1 => '是', 0 => '否'), 'is_dev' => array(1 => '是', 0 => '否')));
if (!empty($list)) { if (!empty($list)) {
$tree = new \com\Tree(); $tree = new \com\Tree();
$list = $tree->toFormatTree($list); $list = $tree->toFormatTree($list);
} }
// 记录当前列表页的cookie // 记录当前列表页的cookie
Cookie('__forward__',$_SERVER['REQUEST_URI']); Cookie('__forward__', $_SERVER['REQUEST_URI']);
$this->setMeta('菜单列表'); $this->setMeta('菜单列表');
$this->assign('list',$list); $this->assign('list', $list);
return $this->fetch(); return $this->fetch();
} }
/* 单字段编辑 */ /* 单字段编辑 */
public function editable($name=null,$value=null,$pk=null){ public function editable($name = null, $value = null, $pk = null) {
if ($name && ($value != null || $value != '') && $pk) { if ($name && ($value != null || $value != '') && $pk) {
db('Menu')->where(array('id'=>$pk))->setField($name,$value); db('Menu')->where(array('id' => $pk))->setField($name, $value);
} }
} }
@@ -45,210 +45,210 @@ class Menu extends Admin{
* 新增菜单 * 新增菜单
* @author yangweijie <yangweijiester@gmail.com> * @author yangweijie <yangweijiester@gmail.com>
*/ */
public function add(){ public function add() {
if(IS_POST){ if (IS_POST) {
$Menu = model('Menu'); $Menu = model('Menu');
$data = input('post.'); $data = input('post.');
$id = $Menu->save($data); $id = $Menu->save($data);
if($id){ if ($id) {
session('admin_menu_list',null); session('admin_menu_list', null);
//记录行为 //记录行为
action_log('update_menu', 'Menu', $id, session('user_auth.uid')); action_log('update_menu', 'Menu', $id, session('user_auth.uid'));
return $this->success('新增成功', Cookie('__forward__')); return $this->success('新增成功', Cookie('__forward__'));
} else { } else {
return $this->error('新增失败'); return $this->error('新增失败');
} }
} else { } else {
$this->assign('info',array('pid'=>input('pid'))); $this->assign('info', array('pid' => input('pid')));
$menus = db('Menu')->select(); $menus = db('Menu')->select();
$tree = new \com\Tree(); $tree = new \com\Tree();
$menus = $tree->toFormatTree($menus); $menus = $tree->toFormatTree($menus);
if (!empty($menus)) { if (!empty($menus)) {
$menus = array_merge(array(0=>array('id'=>0,'title_show'=>'顶级菜单')), $menus); $menus = array_merge(array(0 => array('id' => 0, 'title_show' => '顶级菜单')), $menus);
}else{ } else {
$menus = array(0=>array('id'=>0,'title_show'=>'顶级菜单')); $menus = array(0 => array('id' => 0, 'title_show' => '顶级菜单'));
} }
$this->assign('Menus', $menus); $this->assign('Menus', $menus);
$this->setMeta('新增菜单'); $this->setMeta('新增菜单');
return $this->fetch('edit'); return $this->fetch('edit');
} }
} }
/** /**
* 编辑配置 * 编辑配置
* @author yangweijie <yangweijiester@gmail.com> * @author yangweijie <yangweijiester@gmail.com>
*/ */
public function edit($id = 0){ public function edit($id = 0) {
if(IS_POST){ if (IS_POST) {
$Menu = model('Menu'); $Menu = model('Menu');
$data = input('post.'); $data = input('post.');
if($Menu->save($data,array('id'=>$data['id']))!== false){ if ($Menu->save($data, array('id' => $data['id'])) !== false) {
session('admin_menu_list',null); session('admin_menu_list', null);
//记录行为 //记录行为
action_log('update_menu', 'Menu', $data['id'], session('user_auth.uid')); action_log('update_menu', 'Menu', $data['id'], session('user_auth.uid'));
return $this->success('更新成功', Cookie('__forward__')); return $this->success('更新成功', Cookie('__forward__'));
} else { } else {
return $this->error('更新失败'); return $this->error('更新失败');
} }
} else { } else {
$info = array(); $info = array();
/* 获取数据 */ /* 获取数据 */
$info = db('Menu')->field(true)->find($id); $info = db('Menu')->field(true)->find($id);
$menus = db('Menu')->field(true)->select(); $menus = db('Menu')->field(true)->select();
$tree = new \com\Tree(); $tree = new \com\Tree();
$menus = $tree->toFormatTree($menus); $menus = $tree->toFormatTree($menus);
$menus = array_merge(array(0=>array('id'=>0,'title_show'=>'顶级菜单')), $menus); $menus = array_merge(array(0 => array('id' => 0, 'title_show' => '顶级菜单')), $menus);
$this->assign('Menus', $menus); $this->assign('Menus', $menus);
if(false === $info){ if (false === $info) {
return $this->error('获取后台菜单信息错误'); return $this->error('获取后台菜单信息错误');
} }
$this->assign('info', $info); $this->assign('info', $info);
$this->setMeta('编辑后台菜单'); $this->setMeta('编辑后台菜单');
return $this->fetch(); return $this->fetch();
} }
} }
/** /**
* 删除后台菜单 * 删除后台菜单
* @author yangweijie <yangweijiester@gmail.com> * @author yangweijie <yangweijiester@gmail.com>
*/ */
public function del(){ public function del() {
$id = $this->getArrayParam('id'); $id = $this->getArrayParam('id');
if (empty($id) ) { if (empty($id)) {
return $this->error('请选择要操作的数据!'); return $this->error('请选择要操作的数据!');
} }
$map = array('id' => array('in', $id) ); $map = array('id' => array('in', $id));
if(db('Menu')->where($map)->delete()){ if (db('Menu')->where($map)->delete()) {
session('admin_menu_list',null); session('admin_menu_list', null);
//记录行为 //记录行为
action_log('update_menu', 'Menu', $id, session('user_auth.uid')); action_log('update_menu', 'Menu', $id, session('user_auth.uid'));
return $this->success('删除成功'); return $this->success('删除成功');
} else { } else {
return $this->error('删除失败!'); return $this->error('删除失败!');
} }
} }
public function toogleHide($id,$value = 1){ public function toogleHide($id, $value = 1) {
session('admin_menu_list',null); session('admin_menu_list', null);
$result = db('Menu')->where(array('id'=>$id))->setField(array('hide'=>$value)); $result = db('Menu')->where(array('id' => $id))->setField(array('hide' => $value));
if($result !==false ) { if ($result !== false) {
return $this->success('操作成功!'); return $this->success('操作成功!');
}else{ } else {
return $this->error('操作失败!'); return $this->error('操作失败!');
} }
} }
public function toogleDev($id,$value = 1){ public function toogleDev($id, $value = 1) {
session('admin_menu_list',null); session('admin_menu_list', null);
$result = db('Menu')->where(array('id'=>$id))->setField(array('is_dev'=>$value)); $result = db('Menu')->where(array('id' => $id))->setField(array('is_dev' => $value));
if($result !==false ) { if ($result !== false) {
return $this->success('操作成功!'); return $this->success('操作成功!');
}else{ } else {
return $this->error('操作失败!'); return $this->error('操作失败!');
} }
} }
public function importFile($tree = null, $pid=0){ public function importFile($tree = null, $pid = 0) {
if($tree == null){ if ($tree == null) {
$file = APP_PATH."Admin/Conf/Menu.php"; $file = APP_PATH . "Admin/Conf/Menu.php";
$tree = require_once($file); $tree = require_once $file;
} }
$menuModel = D('Menu'); $menuModel = D('Menu');
foreach ($tree as $value) { foreach ($tree as $value) {
$add_pid = $menuModel->add( $add_pid = $menuModel->add(
array( array(
'title'=>$value['title'], 'title' => $value['title'],
'url'=>$value['url'], 'url' => $value['url'],
'pid'=>$pid, 'pid' => $pid,
'hide'=>isset($value['hide'])? (int)$value['hide'] : 0, 'hide' => isset($value['hide']) ? (int) $value['hide'] : 0,
'tip'=>isset($value['tip'])? $value['tip'] : '', 'tip' => isset($value['tip']) ? $value['tip'] : '',
'group'=>$value['group'], 'group' => $value['group'],
) )
); );
if($value['operator']){ if ($value['operator']) {
$this->import($value['operator'], $add_pid); $this->import($value['operator'], $add_pid);
} }
} }
} }
public function import(){ public function import() {
if(IS_POST){ if (IS_POST) {
$tree = input('post.tree'); $tree = input('post.tree');
$lists = explode(PHP_EOL, $tree); $lists = explode(PHP_EOL, $tree);
$menuModel = db('Menu'); $menuModel = db('Menu');
if($lists == array()){ if ($lists == array()) {
return $this->error('请按格式填写批量导入的菜单,至少一个菜单'); return $this->error('请按格式填写批量导入的菜单,至少一个菜单');
}else{ } else {
$pid = input('post.pid'); $pid = input('post.pid');
foreach ($lists as $key => $value) { foreach ($lists as $key => $value) {
$record = explode('|', $value); $record = explode('|', $value);
if(count($record) == 4){ if (count($record) == 4) {
$menuModel->add(array( $menuModel->add(array(
'title'=>$record[0], 'title' => $record[0],
'url'=>$record[1], 'url' => $record[1],
'pid'=>$record[2], 'pid' => $record[2],
'sort'=>0, 'sort' => 0,
'hide'=>0, 'hide' => 0,
'tip'=>'', 'tip' => '',
'is_dev'=>0, 'is_dev' => 0,
'group'=>$record[3], 'group' => $record[3],
)); ));
} }
} }
session('admin_menu_list',null); session('admin_menu_list', null);
return $this->success('导入成功',url('index?pid='.$pid)); return $this->success('导入成功', url('index?pid=' . $pid));
} }
}else{ } else {
$this->setMeta('批量导入后台菜单'); $this->setMeta('批量导入后台菜单');
$pid = (int)input('get.pid'); $pid = (int) input('get.pid');
$this->assign('pid', $pid); $this->assign('pid', $pid);
$data = db('Menu')->where("id={$pid}")->field(true)->find(); $data = db('Menu')->where("id={$pid}")->field(true)->find();
$this->assign('data', $data); $this->assign('data', $data);
return $this->fetch(); return $this->fetch();
} }
} }
/** /**
* 菜单排序 * 菜单排序
* @author huajie <banhuajie@163.com> * @author huajie <banhuajie@163.com>
*/ */
public function sort(){ public function sort() {
if(IS_GET){ if (IS_GET) {
$ids = input('ids'); $ids = input('ids');
$pid = input('pid'); $pid = input('pid');
//获取排序的数据 //获取排序的数据
$map = array('status'=>array('gt',-1)); $map = array('status' => array('gt', -1));
if(!empty($ids)){ if (!empty($ids)) {
$map['id'] = array('in',$ids); $map['id'] = array('in', $ids);
}else{ } else {
if($pid !== ''){ if ($pid !== '') {
$map['pid'] = $pid; $map['pid'] = $pid;
} }
} }
$list = db('Menu')->where($map)->field('id,title')->order('sort asc,id asc')->select(); $list = db('Menu')->where($map)->field('id,title')->order('sort asc,id asc')->select();
$this->assign('list', $list); $this->assign('list', $list);
$this->setMeta('菜单排序'); $this->setMeta('菜单排序');
return $this->fetch(); return $this->fetch();
}elseif (IS_POST){ } elseif (IS_POST) {
$ids = input('post.ids'); $ids = input('post.ids');
$ids = explode(',', $ids); $ids = explode(',', $ids);
foreach ($ids as $key=>$value){ foreach ($ids as $key => $value) {
$res = db('Menu')->where(array('id'=>$value))->setField('sort', $key+1); $res = db('Menu')->where(array('id' => $value))->setField('sort', $key + 1);
} }
if($res !== false){ if ($res !== false) {
session('admin_menu_list',null); session('admin_menu_list', null);
return $this->success('排序成功!'); return $this->success('排序成功!');
}else{ } else {
return $this->error('排序失败!'); return $this->error('排序失败!');
} }
}else{ } else {
return $this->error('非法请求!'); return $this->error('非法请求!');
} }
} }
} }

View File

@@ -10,9 +10,9 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\common\controller\Admin; use app\common\controller\Admin;
class Model extends Admin{ class Model extends Admin {
public function _initialize(){ public function _initialize() {
parent::_initialize(); parent::_initialize();
$this->getContentMenu(); $this->getContentMenu();
} }
@@ -25,11 +25,11 @@ class Model extends Admin{
$map = array('status' => array('gt', -1)); $map = array('status' => array('gt', -1));
$order = "id desc"; $order = "id desc";
$list = model('Model')->where($map)->order($order)->paginate(10); $list = model('Model')->where($map)->order($order)->paginate(10);
$data = array( $data = array(
'list' => $list, 'list' => $list,
'page' => $list->render(), 'page' => $list->render(),
); );
// 记录当前列表页的cookie // 记录当前列表页的cookie
@@ -40,7 +40,6 @@ class Model extends Admin{
return $this->fetch(); return $this->fetch();
} }
/** /**
* 新增页面初始化 * 新增页面初始化
* @author huajie <banhuajie@163.com> * @author huajie <banhuajie@163.com>
@@ -67,7 +66,7 @@ class Model extends Admin{
/*获取一条记录的详细数据*/ /*获取一条记录的详细数据*/
$model = model('Model'); $model = model('Model');
$data = $model::find($id); $data = $model::find($id);
if (!$data) { if (!$data) {
return $this->error($Model->getError()); return $this->error($Model->getError());
} }
@@ -75,20 +74,20 @@ class Model extends Admin{
// 是否继承了其他模型 // 是否继承了其他模型
if ($data['extend'] == 1) { if ($data['extend'] == 1) {
$map['model_id'] = array('IN',array($data['id'],$data['extend'])); $map['model_id'] = array('IN', array($data['id'], $data['extend']));
}else{ } else {
$map['model_id'] = $data['id']; $map['model_id'] = $data['id'];
} }
$map['is_show'] = 1; $map['is_show'] = 1;
$fields = db('Attribute')->where($map)->select(); $fields = db('Attribute')->where($map)->select();
// 梳理属性的可见性 // 梳理属性的可见性
foreach ($fields as $key => $field) { foreach ($fields as $key => $field) {
if (!empty($data['attribute_list']) && !in_array($field['id'], $data['attribute_list'])) { if (!empty($data['attribute_list']) && !in_array($field['id'], $data['attribute_list'])) {
$field['is_show'] = 0; $field['is_show'] = 0;
} }
$field['group'] = -1; $field['group'] = -1;
$field['sort'] = 0; $field['sort'] = 0;
$fields_tem[$field['id']] = $field; $fields_tem[$field['id']] = $field;
} }
@@ -99,7 +98,7 @@ class Model extends Admin{
foreach ($ids as $key => $value) { foreach ($ids as $key => $value) {
if (!empty($fields_tem[$value])) { if (!empty($fields_tem[$value])) {
$fields_tem[$value]['group'] = $group; $fields_tem[$value]['group'] = $group;
$fields_tem[$value]['sort'] = $key; $fields_tem[$value]['sort'] = $key;
} }
} }
} }
@@ -121,7 +120,7 @@ class Model extends Admin{
* @author huajie <banhuajie@163.com> * @author huajie <banhuajie@163.com>
*/ */
public function del() { public function del() {
$mdoel = model('Model'); $mdoel = model('Model');
$result = $mdoel->del(); $result = $mdoel->del();
if ($result) { if ($result) {
return $this->success('删除模型成功!'); return $this->success('删除模型成功!');
@@ -136,9 +135,9 @@ class Model extends Admin{
*/ */
public function update() { public function update() {
$res = \think\Loader::model('Model')->change(); $res = \think\Loader::model('Model')->change();
if($res['status']){ if ($res['status']) {
return $this->success($res['info'], url('index')); return $this->success($res['info'], url('index'));
}else{ } else {
return $this->error($res['info']); return $this->error($res['info']);
} }
} }
@@ -147,20 +146,22 @@ class Model extends Admin{
* 更新数据 * 更新数据
* @author colin <colin@tensent.cn> * @author colin <colin@tensent.cn>
*/ */
public function status(){ public function status() {
$map['id'] = $this->request->param('ids'); $map['id'] = $this->request->param('ids');
if(null == $map['id'])return $this->error('参数不正确!'); if (null == $map['id']) {
return $this->error('参数不正确!');
}
$data['status'] = input('get.status'); $data['status'] = input('get.status');
if(null == $data['status']){ if (null == $data['status']) {
//实现单条数据数据修改 //实现单条数据数据修改
$status = db('Model')->where($map)->field('status')->find(); $status = db('Model')->where($map)->field('status')->find();
$data['status'] = $status['status'] ? 0 : 1; $data['status'] = $status['status'] ? 0 : 1;
db('Model')->where($map)->update($data); db('Model')->where($map)->update($data);
}else{ } else {
//实现多条数据同时修改 //实现多条数据同时修改
$map['id'] = array('IN',$map['id']); $map['id'] = array('IN', $map['id']);
db('Model')->where($map)->update($data); db('Model')->where($map)->update($data);
} }
return $this->success('状态设置成功!'); return $this->success('状态设置成功!');

View File

@@ -10,44 +10,44 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\common\controller\Admin; use app\common\controller\Admin;
class Seo extends Admin{ class Seo extends Admin {
protected $seo; protected $seo;
protected $rewrite; protected $rewrite;
public function _initialize(){ public function _initialize() {
parent::_initialize(); parent::_initialize();
$this->seo = model('SeoRule'); $this->seo = model('SeoRule');
$this->rewrite = model('Rewrite'); $this->rewrite = model('Rewrite');
} }
public function index($page = 1, $r = 20){ public function index($page = 1, $r = 20) {
//读取规则列表 //读取规则列表
$map = array('status' => array('EGT', 0)); $map = array('status' => array('EGT', 0));
$list = $this->seo->where($map)->order('sort asc')->paginate(10); $list = $this->seo->where($map)->order('sort asc')->paginate(10);
$data = array( $data = array(
'list' => $list, 'list' => $list,
'page' => $list->render(), 'page' => $list->render(),
); );
$this->assign($data); $this->assign($data);
$this->setMeta("规则列表"); $this->setMeta("规则列表");
return $this->fetch(); return $this->fetch();
} }
public function add(){ public function add() {
if (IS_POST) { if (IS_POST) {
$data = $this->request->post(); $data = $this->request->post();
$result = $this->seo->save($data); $result = $this->seo->save($data);
if ($result) { if ($result) {
return $this->success("添加成功!"); return $this->success("添加成功!");
}else{ } else {
return $this->error("添加失败!"); return $this->error("添加失败!");
} }
}else{ } else {
$data = array( $data = array(
'keyList' => $this->seo->keyList 'keyList' => $this->seo->keyList,
); );
$this->assign($data); $this->assign($data);
$this->setMeta("添加规则"); $this->setMeta("添加规则");
@@ -55,21 +55,21 @@ class Seo extends Admin{
} }
} }
public function edit($id = null){ public function edit($id = null) {
if (IS_POST) { if (IS_POST) {
$data = $this->request->post(); $data = $this->request->post();
$result = $this->seo->save($data,array('id'=>$data['id'])); $result = $this->seo->save($data, array('id' => $data['id']));
if (false !== $result) { if (false !== $result) {
return $this->success("修改成功!"); return $this->success("修改成功!");
}else{ } else {
return $this->error("修改失败!"); return $this->error("修改失败!");
} }
}else{ } else {
$id = input('id','','trim,intval'); $id = input('id', '', 'trim,intval');
$info = $this->seo->where(array('id'=>$id))->find(); $info = $this->seo->where(array('id' => $id))->find();
$data = array( $data = array(
'info' => $info, 'info' => $info,
'keyList' => $this->seo->keyList 'keyList' => $this->seo->keyList,
); );
$this->assign($data); $this->assign($data);
$this->setMeta("编辑规则"); $this->setMeta("编辑规则");
@@ -77,42 +77,42 @@ class Seo extends Admin{
} }
} }
public function del(){ public function del() {
$id = $this->getArrayParam('id'); $id = $this->getArrayParam('id');
if (empty($id)) { if (empty($id)) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
$result = $this->seo->where(array('id'=>array('IN',$id)))->delete(); $result = $this->seo->where(array('id' => array('IN', $id)))->delete();
if ($result) { if ($result) {
return $this->success("删除成功!"); return $this->success("删除成功!");
}else{ } else {
return $this->error("删除失败!"); return $this->error("删除失败!");
} }
} }
public function rewrite(){ public function rewrite() {
$list = db('Rewrite')->paginate(10); $list = db('Rewrite')->paginate(10);
$data = array( $data = array(
'list' => $list, 'list' => $list,
'page' => $list->render() 'page' => $list->render(),
); );
$this->assign($data); $this->assign($data);
$this->setMeta("路由规则"); $this->setMeta("路由规则");
return $this->fetch(); return $this->fetch();
} }
public function addrewrite(){ public function addrewrite() {
if (IS_POST) { if (IS_POST) {
$result = model('Rewrite')->change(); $result = model('Rewrite')->change();
if (false != $result) { if (false != $result) {
return $this->success("添加成功!", url('admin/seo/rewrite')); return $this->success("添加成功!", url('admin/seo/rewrite'));
}else{ } else {
return $this->error(model('Rewrite')->getError()); return $this->error(model('Rewrite')->getError());
} }
}else{ } else {
$data = array( $data = array(
'keyList' => $this->rewrite->keyList 'keyList' => $this->rewrite->keyList,
); );
$this->assign($data); $this->assign($data);
$this->setMeta("添加路由规则"); $this->setMeta("添加路由规则");
@@ -120,20 +120,20 @@ class Seo extends Admin{
} }
} }
public function editrewrite(){ public function editrewrite() {
if (IS_POST) { if (IS_POST) {
$result = model('Rewrite')->change(); $result = model('Rewrite')->change();
if (false != $result) { if (false != $result) {
return $this->success("更新成功!", url('admin/seo/rewrite')); return $this->success("更新成功!", url('admin/seo/rewrite'));
}else{ } else {
return $this->error(model('Rewrite')->getError()); return $this->error(model('Rewrite')->getError());
} }
}else{ } else {
$id = input('id','','trim,intval'); $id = input('id', '', 'trim,intval');
$info = db('Rewrite')->where(array('id'=>$id))->find(); $info = db('Rewrite')->where(array('id' => $id))->find();
$data = array( $data = array(
'info' => $info, 'info' => $info,
'keyList' => $this->rewrite->keyList 'keyList' => $this->rewrite->keyList,
); );
$this->assign($data); $this->assign($data);
$this->setMeta("编辑路由规则"); $this->setMeta("编辑路由规则");
@@ -141,15 +141,15 @@ class Seo extends Admin{
} }
} }
public function delrewrite(){ public function delrewrite() {
$id = $this->getArrayParam('id'); $id = $this->getArrayParam('id');
if (empty($id)) { if (empty($id)) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
$result = db('Rewrite')->where(array('id'=>array('IN',$id)))->delete(); $result = db('Rewrite')->where(array('id' => array('IN', $id)))->delete();
if ($result) { if ($result) {
return $this->success("删除成功!"); return $this->success("删除成功!");
}else{ } else {
return $this->error("删除失败!"); return $this->error("删除失败!");
} }
} }

View File

@@ -12,9 +12,9 @@ use app\common\controller\Admin;
class Upload extends Admin { class Upload extends Admin {
public function _empty(){ public function _empty() {
$controller = controller('common/Upload'); $controller = controller('common/Upload');
$action = ACTION_NAME; $action = ACTION_NAME;
return $controller->$action(); return $controller->$action();
} }
} }

View File

@@ -10,27 +10,27 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\common\controller\Admin; use app\common\controller\Admin;
class User extends Admin{ class User extends Admin {
/** /**
* 用户管理首页 * 用户管理首页
* @author 麦当苗儿 <zuojiazi@vip.qq.com> * @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/ */
public function index() { public function index() {
$nickname = input('nickname'); $nickname = input('nickname');
$map['status'] = array('egt', 0); $map['status'] = array('egt', 0);
if (is_numeric($nickname)) { if (is_numeric($nickname)) {
$map['uid|nickname'] = array(intval($nickname), array('like', '%' . $nickname . '%'), '_multi' => true); $map['uid|nickname'] = array(intval($nickname), array('like', '%' . $nickname . '%'), '_multi' => true);
} else { } else {
$map['nickname'] = array('like', '%' . (string)$nickname . '%'); $map['nickname'] = array('like', '%' . (string) $nickname . '%');
} }
$order = "uid desc"; $order = "uid desc";
$list = model('User')->where($map)->order($order)->paginate(15); $list = model('User')->where($map)->order($order)->paginate(15);
$data = array( $data = array(
'list' => $list, 'list' => $list,
'page' => $list->render(), 'page' => $list->render(),
); );
$this->assign($data); $this->assign($data);
$this->setMeta('用户信息'); $this->setMeta('用户信息');
@@ -41,27 +41,27 @@ class User extends Admin{
* 添加用户 * 添加用户
* @author colin <molong@tensent.cn> * @author colin <molong@tensent.cn>
*/ */
public function add(){ public function add() {
$model = \think\Loader::model('User'); $model = \think\Loader::model('User');
if(IS_POST){ if (IS_POST) {
$data = $this->request->param(); $data = $this->request->param();
//创建注册用户 //创建注册用户
$uid = $model->register($data['username'], $data['password'], $data['repassword'], $data['email'], false); $uid = $model->register($data['username'], $data['password'], $data['repassword'], $data['email'], false);
if(0 < $uid){ if (0 < $uid) {
$userinfo = array('nickname' => $data['username'], 'status' => 1,'reg_time'=>time(),'last_login_time'=>time(),'last_login_ip'=>get_client_ip(1)); $userinfo = array('nickname' => $data['username'], 'status' => 1, 'reg_time' => time(), 'last_login_time' => time(), 'last_login_ip' => get_client_ip(1));
/*保存信息*/ /*保存信息*/
if(!db('Member')->where(array('uid'=>$uid))->update($userinfo)){ if (!db('Member')->where(array('uid' => $uid))->update($userinfo)) {
return $this->error('用户添加失败!', ''); return $this->error('用户添加失败!', '');
} else { } else {
return $this->success('用户添加成功!', url('admin/user/index')); return $this->success('用户添加成功!', url('admin/user/index'));
} }
}else{ } else {
return $this->error($model->getError()); return $this->error($model->getError());
} }
}else{ } else {
$data = array( $data = array(
'keyList' => $model->addfield 'keyList' => $model->addfield,
); );
$this->assign($data); $this->assign($data);
$this->setMeta("添加用户"); $this->setMeta("添加用户");
@@ -75,22 +75,22 @@ class User extends Admin{
*/ */
public function edit() { public function edit() {
$model = model('User'); $model = model('User');
if(IS_POST){ if (IS_POST) {
$data = $this->request->post(); $data = $this->request->post();
$reuslt = $model->editUser($data, true); $reuslt = $model->editUser($data, true);
if (false !== $reuslt) { if (false !== $reuslt) {
return $this->success('修改成功!', url('admin/user/index')); return $this->success('修改成功!', url('admin/user/index'));
}else{ } else {
return $this->error($model->getError(), ''); return $this->error($model->getError(), '');
} }
}else{ } else {
$info = $this->getUserinfo(); $info = $this->getUserinfo();
$data = array( $data = array(
'info' => $info, 'info' => $info,
'keyList' => $model->editfield 'keyList' => $model->editfield,
); );
$this->assign($data); $this->assign($data);
$this->setMeta("编辑用户"); $this->setMeta("编辑用户");
@@ -102,37 +102,36 @@ class User extends Admin{
* del * del
* @author colin <colin@tensent.cn> * @author colin <colin@tensent.cn>
*/ */
public function del($id){ public function del($id) {
$uid = array('IN',is_array($id) ? implode(',',$id) : $id); $uid = array('IN', is_array($id) ? implode(',', $id) : $id);
//获取用户信息 //获取用户信息
$find = $this->getUserinfo($uid); $find = $this->getUserinfo($uid);
model('User')->where(array('uid'=>$uid))->delete(); model('User')->where(array('uid' => $uid))->delete();
return $this->success('删除用户成功!'); return $this->success('删除用户成功!');
} }
public function auth() {
public function auth(){
$access = model('AuthGroupAccess'); $access = model('AuthGroupAccess');
$group = model('AuthGroup'); $group = model('AuthGroup');
if (IS_POST) { if (IS_POST) {
$uid = input('uid','','trim,intval'); $uid = input('uid', '', 'trim,intval');
$access->where(array('uid'=>$uid))->delete(); $access->where(array('uid' => $uid))->delete();
$group_type = config('user_group_type'); $group_type = config('user_group_type');
foreach ($group_type as $key => $value) { foreach ($group_type as $key => $value) {
$group_id = input($key,'','trim,intval'); $group_id = input($key, '', 'trim,intval');
if ($group_id) { if ($group_id) {
$add = array( $add = array(
'uid' => $uid, 'uid' => $uid,
'group_id' => $group_id, 'group_id' => $group_id,
); );
$access->save($add); $access->save($add);
} }
} }
return $this->success("设置成功!"); return $this->success("设置成功!");
}else{ } else {
$uid = input('id','','trim,intval'); $uid = input('id', '', 'trim,intval');
$row = $group::select(); $row = $group::select();
$auth = $access::where(array('uid'=>$uid))->select(); $auth = $access::where(array('uid' => $uid))->select();
$auth_list = array(); $auth_list = array();
foreach ($auth as $key => $value) { foreach ($auth as $key => $value) {
@@ -142,9 +141,9 @@ class User extends Admin{
$list[$value['module']][] = $value; $list[$value['module']][] = $value;
} }
$data = array( $data = array(
'uid' => $uid, 'uid' => $uid,
'auth_list' => $auth_list, 'auth_list' => $auth_list,
'list' => $list 'list' => $list,
); );
$this->assign($data); $this->assign($data);
$this->setMeta("用户分组"); $this->setMeta("用户分组");
@@ -159,18 +158,18 @@ class User extends Admin{
* @var errormasg 错误提示 * @var errormasg 错误提示
* @author colin <colin@tensent.cn> * @author colin <colin@tensent.cn>
*/ */
private function getUserinfo($uid = null,$pass = null,$errormsg = null){ private function getUserinfo($uid = null, $pass = null, $errormsg = null) {
$user = model('User'); $user = model('User');
$uid = $uid ? $uid : input('id'); $uid = $uid ? $uid : input('id');
//如果无UID则修改当前用户 //如果无UID则修改当前用户
$uid = $uid ? $uid : session('user_auth.uid'); $uid = $uid ? $uid : session('user_auth.uid');
$map['uid'] = $uid; $map['uid'] = $uid;
if($pass != null ){ if ($pass != null) {
unset($map); unset($map);
$map['password'] = $pass; $map['password'] = $pass;
} }
$list = $user::where($map)->field('uid,username,nickname,sex,email,qq,score,signature,status,salt')->find(); $list = $user::where($map)->field('uid,username,nickname,sex,email,qq,score,signature,status,salt')->find();
if(!$list){ if (!$list) {
return $this->error($errormsg ? $errormsg : '不存在此用户!'); return $this->error($errormsg ? $errormsg : '不存在此用户!');
} }
return $list; return $list;
@@ -194,13 +193,13 @@ class User extends Admin{
//密码验证 //密码验证
$User = new UserApi(); $User = new UserApi();
$uid = $User->login(UID, $password, 4); $uid = $User->login(UID, $password, 4);
if ($uid == -2) { if ($uid == -2) {
return $this->error('密码不正确'); return $this->error('密码不正确');
} }
$Member = model('User'); $Member = model('User');
$data = $Member->create(array('nickname' => $nickname)); $data = $Member->create(array('nickname' => $nickname));
if (!$data) { if (!$data) {
return $this->error($Member->getError()); return $this->error($Member->getError());
} }
@@ -208,13 +207,12 @@ class User extends Admin{
$res = $Member->where(array('uid' => $uid))->save($data); $res = $Member->where(array('uid' => $uid))->save($data);
if ($res) { if ($res) {
$user = session('user_auth'); $user = session('user_auth');
$user['username'] = $data['nickname']; $user['username'] = $data['nickname'];
session('user_auth', $user); session('user_auth', $user);
session('user_auth_sign', data_auth_sign($user)); session('user_auth_sign', data_auth_sign($user));
return $this->success('修改昵称成功!'); return $this->success('修改昵称成功!');
} } else {
else {
return $this->error('修改昵称失败!'); return $this->error('修改昵称失败!');
} }
} }
@@ -231,10 +229,10 @@ class User extends Admin{
$res = $user->editpw($data); $res = $user->editpw($data);
if ($res) { if ($res) {
return $this->success('修改密码成功!'); return $this->success('修改密码成功!');
}else { } else {
return $this->error($user->getError()); return $this->error($user->getError());
} }
}else{ } else {
$this->setMeta('修改密码'); $this->setMeta('修改密码');
return $this->fetch(); return $this->fetch();
} }
@@ -245,7 +243,7 @@ class User extends Admin{
* @author 朱亚杰 <zhuyajie@topthink.net> * @author 朱亚杰 <zhuyajie@topthink.net>
*/ */
public function changeStatus($method = null) { public function changeStatus($method = null) {
$id = array_unique((array)input('id', 0)); $id = array_unique((array) input('id', 0));
if (in_array(config('user_administrator'), $id)) { if (in_array(config('user_administrator'), $id)) {
return $this->error("不允许对超级管理员执行该操作!"); return $this->error("不允许对超级管理员执行该操作!");
} }
@@ -255,20 +253,20 @@ class User extends Admin{
} }
$map['uid'] = array('in', $id); $map['uid'] = array('in', $id);
switch (strtolower($method)) { switch (strtolower($method)) {
case 'forbiduser': case 'forbiduser':
$this->forbid('Member', $map); $this->forbid('Member', $map);
break; break;
case 'resumeuser': case 'resumeuser':
$this->resume('Member', $map); $this->resume('Member', $map);
break; break;
case 'deleteuser': case 'deleteuser':
$this->delete('Member', $map); $this->delete('Member', $map);
break; break;
default: default:
return $this->error('参数非法'); return $this->error('参数非法');
} }
} }
} }

View File

@@ -1136,7 +1136,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
switch ($info['type']) { switch ($info['type']) {
case Relation::HAS_MANY: case Relation::HAS_MANY:
return $model->db()->alias('a') return $model->db()->alias('a')
->join($table . ' b', 'a.' . $info['localKey'] . '=b.' . $info['foreignKey']) ->join($table . ' b', 'a.' . $info['localKey'] . '=b.' . $info['foreignKey'], $info['joinType'])
->group('b.' . $info['foreignKey']) ->group('b.' . $info['foreignKey'])
->having('count(' . $id . ')' . $operator . $count); ->having('count(' . $id . ')' . $operator . $count);
case Relation::HAS_MANY_THROUGH: case Relation::HAS_MANY_THROUGH:
@@ -1169,7 +1169,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
} }
return $model->db()->alias('a') return $model->db()->alias('a')
->field('a.*') ->field('a.*')
->join($table . ' b', 'a.' . $info['localKey'] . '=b.' . $info['foreignKey']) ->join($table . ' b', 'a.' . $info['localKey'] . '=b.' . $info['foreignKey'], $info['joinType'])
->where($where); ->where($where);
case Relation::HAS_MANY_THROUGH: case Relation::HAS_MANY_THROUGH:
// TODO // TODO

View File

@@ -700,6 +700,16 @@ abstract class Connection
return $this->linkID->lastInsertId($sequence); return $this->linkID->lastInsertId($sequence);
} }
/**
* 获取返回或者影响的记录数
* @access public
* @return integer
*/
public function getNumRows()
{
return $this->numRows;
}
/** /**
* 获取最近的错误信息 * 获取最近的错误信息
* @access public * @access public

View File

@@ -1883,7 +1883,7 @@ class Query
} }
// 返回结果处理 // 返回结果处理
if ($resultSet) { if ($this->connection->getNumRows()) {
// 数据列表读取后的处理 // 数据列表读取后的处理
if (!empty($this->model)) { if (!empty($this->model)) {
// 生成模型对象 // 生成模型对象
@@ -1898,7 +1898,7 @@ class Query
} }
$resultSet[$key] = $result; $resultSet[$key] = $result;
} }
if (!empty($options['with'])) { if (!empty($options['with']) && $result instanceof Model) {
// 预载入 // 预载入
$resultSet = $result->eagerlyResultSet($resultSet, $options['with'], is_object($resultSet) ? get_class($resultSet) : ''); $resultSet = $result->eagerlyResultSet($resultSet, $options['with'], is_object($resultSet) ? get_class($resultSet) : '');
} }