更新权限管理模块
This commit is contained in:
@@ -8,7 +8,9 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
namespace app\controller\admin;
|
namespace app\controller\admin;
|
||||||
|
|
||||||
|
use think\facade\Db;
|
||||||
use app\model\AuthGroup;
|
use app\model\AuthGroup;
|
||||||
|
use app\model\AuthGroupAccess;
|
||||||
use app\model\AuthRule;
|
use app\model\AuthRule;
|
||||||
use app\model\Model;
|
use app\model\Model;
|
||||||
|
|
||||||
@@ -151,35 +153,35 @@ class Group extends Base {
|
|||||||
* @title 用户组授权
|
* @title 用户组授权
|
||||||
*/
|
*/
|
||||||
public function auth($id) {
|
public function auth($id) {
|
||||||
if (!$id) {
|
|
||||||
return $this->error("非法操作!");
|
|
||||||
}
|
|
||||||
if ($this->request->isPost()) {
|
if ($this->request->isPost()) {
|
||||||
$rule = $this->request->post('rule/a', array());
|
$rule = $this->request->post('rule', []);
|
||||||
$extend_rule = $this->request->post('extend_rule/a', array());
|
$extend_rule = $this->request->post('extend_rule', []);
|
||||||
$extend_result = $rule_result = false;
|
$extend_result = $rule_result = false;
|
||||||
//扩展权限
|
//扩展权限
|
||||||
$extend_data = array();
|
$extend_data = [];
|
||||||
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::name('AuthExtend')->where(array('group_id' => $id))->delete();
|
||||||
$extend_result = db('AuthExtend')->insertAll($extend_data);
|
$extend_result = Db::name('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 = AuthGroup::update(['rules'=> $rules], ['id' => $id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
|
if (!$id) {
|
||||||
|
return $this->error("非法操作!");
|
||||||
|
}
|
||||||
$group = AuthGroup::find($id);
|
$group = AuthGroup::find($id);
|
||||||
|
|
||||||
$map[] = ['module', '=', $group['module']];
|
$map[] = ['module', '=', $group['module']];
|
||||||
@@ -193,13 +195,12 @@ class Group extends Base {
|
|||||||
//模块
|
//模块
|
||||||
$model = Model::where('status', '>', 0)->field('id,title,name')->select();
|
$model = Model::where('status', '>', 0)->field('id,title,name')->select();
|
||||||
//扩展权限
|
//扩展权限
|
||||||
// $extend_auth = db('AuthExtend')->where(array('group_id' => $id, 'type' => 2))->column('extend_id');
|
$extend_auth = Db::name('AuthExtend')->where(array('group_id' => $id, 'type' => 2))->column('extend_id');
|
||||||
$this->data = array(
|
$this->data = array(
|
||||||
'list' => $list,
|
'list' => $list,
|
||||||
'model' => $model,
|
'model' => $model,
|
||||||
// 'extend_auth' => $extend_auth,
|
'extend_auth' => $extend_auth,
|
||||||
'extend_auth' => [],
|
'auth_list' => $group['rules'],
|
||||||
'auth_list' => explode(',', $group['rules']),
|
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
);
|
);
|
||||||
return $this->fetch();
|
return $this->fetch();
|
||||||
@@ -259,7 +260,7 @@ class Group extends Base {
|
|||||||
if (!$id) {
|
if (!$id) {
|
||||||
return $this->error("非法操作!");
|
return $this->error("非法操作!");
|
||||||
}
|
}
|
||||||
$result = $this->rule->where(array('id' => $id))->delete();
|
$result = AuthRule::find($id)->delete();
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return $this->success("删除成功!");
|
return $this->success("删除成功!");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -24,5 +24,9 @@ class AuthGroup extends Model{
|
|||||||
['name'=>'status', 'title'=>'状态', 'type'=>'select', 'help'=>'', 'option'=> [['key' => 0, 'label' => '禁用'],['key' => 1, 'label' => '启用']]],
|
['name'=>'status', 'title'=>'状态', 'type'=>'select', 'help'=>'', 'option'=> [['key' => 0, 'label' => '禁用'],['key' => 1, 'label' => '启用']]],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected function getRulesAttr($value){
|
||||||
|
return $value ? explode(",", $value) : [];
|
||||||
|
}
|
||||||
|
|
||||||
public static function getAuthModels($uid){}
|
public static function getAuthModels($uid){}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user