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