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