mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-05-29 18:09:16 +08:00
[更新]代码优雅处理
This commit is contained in:
parent
e08e427f9d
commit
c958252c02
@ -45,36 +45,48 @@ class Auth extends BasicAdmin {
|
||||
|
||||
/**
|
||||
* 权限授权
|
||||
* @return string|array
|
||||
* @return string
|
||||
*/
|
||||
public function apply() {
|
||||
$auth_id = $this->request->get('id', '0');
|
||||
switch (strtolower($this->request->get('action', '0'))) {
|
||||
case 'getnode':
|
||||
$nodes = NodeService::get();
|
||||
$checked = Db::name('SystemAuthNode')->where('auth', $auth_id)->column('node');
|
||||
foreach ($nodes as $key => &$node) {
|
||||
$node['checked'] = in_array($node['node'], $checked);
|
||||
if (empty($node['is_auth']) && substr_count($node['node'], '/') > 1) {
|
||||
unset($nodes[$key]);
|
||||
}
|
||||
}
|
||||
$this->success('获取节点成功!', '', $this->_filterNodes($this->_filterNodes(ToolsService::arr2tree($nodes, 'node', 'pnode', '_sub_'))));
|
||||
break;
|
||||
case 'save':
|
||||
$data = [];
|
||||
$post = $this->request->post();
|
||||
foreach (isset($post['nodes']) ? $post['nodes'] : [] as $node) {
|
||||
$data[] = ['auth' => $auth_id, 'node' => $node];
|
||||
}
|
||||
Db::name('SystemAuthNode')->where('auth', $auth_id)->delete();
|
||||
Db::name('SystemAuthNode')->insertAll($data);
|
||||
$this->success('节点授权更新成功!', '');
|
||||
break;
|
||||
default :
|
||||
$this->assign('title', '节点授权');
|
||||
return $this->_form($this->table, 'apply');
|
||||
$method = '_apply_' . strtolower($this->request->get('action', '0'));
|
||||
if (method_exists($this, $method)) {
|
||||
return $this->$method($auth_id);
|
||||
}
|
||||
$this->assign('title', '节点授权');
|
||||
return $this->_form($this->table, 'apply');
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取授权节点
|
||||
* @param $auth_id
|
||||
*/
|
||||
protected function _apply_getnode($auth_id) {
|
||||
$nodes = NodeService::get();
|
||||
$checked = Db::name('SystemAuthNode')->where('auth', $auth_id)->column('node');
|
||||
foreach ($nodes as $key => &$node) {
|
||||
$node['checked'] = in_array($node['node'], $checked);
|
||||
if (empty($node['is_auth']) && substr_count($node['node'], '/') > 1) {
|
||||
unset($nodes[$key]);
|
||||
}
|
||||
}
|
||||
$allnode = $this->_apply_filter(ToolsService::arr2tree($nodes, 'node', 'pnode', '_sub_'));
|
||||
$this->success('获取节点成功!', '', $allnode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存授权节点
|
||||
* @param $auth_id
|
||||
*/
|
||||
protected function _apply_save($auth_id) {
|
||||
$data = [];
|
||||
$post = $this->request->post();
|
||||
foreach (isset($post['nodes']) ? $post['nodes'] : [] as $node) {
|
||||
$data[] = ['auth' => $auth_id, 'node' => $node];
|
||||
}
|
||||
Db::name('SystemAuthNode')->where('auth', $auth_id)->delete();
|
||||
Db::name('SystemAuthNode')->insertAll($data);
|
||||
$this->success('节点授权更新成功!', '');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,10 +95,10 @@ class Auth extends BasicAdmin {
|
||||
* @param int $level
|
||||
* @return array
|
||||
*/
|
||||
protected function _filterNodes($nodes, $level = 1) {
|
||||
protected function _apply_filter($nodes, $level = 1) {
|
||||
foreach ($nodes as $key => &$node) {
|
||||
if (!empty($node['_sub_']) && is_array($node['_sub_'])) {
|
||||
$node['_sub_'] = $this->_filterNodes($node['_sub_'], $level + 1);
|
||||
$node['_sub_'] = $this->_apply_filter($node['_sub_'], $level + 1);
|
||||
} elseif ($level < 3) {
|
||||
unset($nodes[$key]);
|
||||
}
|
||||
@ -113,9 +125,9 @@ class Auth extends BasicAdmin {
|
||||
*/
|
||||
public function forbid() {
|
||||
if (DataService::update($this->table)) {
|
||||
$this->success("权限禁用成功!", '');
|
||||
$this->success("权限禁用成功!", '');
|
||||
}
|
||||
$this->error("权限禁用失败,请稍候再试!");
|
||||
$this->error("权限禁用失败, 请稍候再试!");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -123,9 +135,9 @@ class Auth extends BasicAdmin {
|
||||
*/
|
||||
public function resume() {
|
||||
if (DataService::update($this->table)) {
|
||||
$this->success("权限启用成功!", '');
|
||||
$this->success("权限启用成功!", '');
|
||||
}
|
||||
$this->error("权限启用失败,请稍候再试!");
|
||||
$this->error("权限启用失败, 请稍候再试!");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -135,9 +147,9 @@ class Auth extends BasicAdmin {
|
||||
if (DataService::update($this->table)) {
|
||||
$id = $this->request->post('id');
|
||||
Db::name('SystemAuthNode')->where('auth', $id)->delete();
|
||||
$this->success("权限删除成功!", '');
|
||||
$this->success("权限删除成功!", '');
|
||||
}
|
||||
$this->error("权限删除失败,请稍候再试!");
|
||||
$this->error("权限删除失败, 请稍候再试!");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -57,12 +57,9 @@ class Config extends BasicAdmin {
|
||||
* 文件存储配置
|
||||
*/
|
||||
public function file() {
|
||||
$this->assign('alert', [
|
||||
'type' => 'success',
|
||||
'title' => '操作提示',
|
||||
'content' => '文件引擎参数影响全局文件上传功能,请勿随意修改!'
|
||||
]);
|
||||
$this->title = '文件存储配置';
|
||||
$alert = ['type' => 'success', 'title' => '操作提示', 'content' => '文件引擎参数影响全局文件上传功能,请勿随意修改!'];
|
||||
$this->assign('alert', $alert);
|
||||
return $this->index();
|
||||
}
|
||||
|
||||
|
@ -38,14 +38,15 @@ class Log extends BasicAdmin {
|
||||
*/
|
||||
public function index() {
|
||||
$this->title = '系统操作日志';
|
||||
$this->assign('actions', Db::name($this->table)->group('action')->column('action'));
|
||||
$db = Db::name($this->table)->order('id desc');
|
||||
$get = $this->request->get();
|
||||
$actions = Db::name($this->table)->group('action')->column('action');
|
||||
$db = Db::name($this->table)->order('id desc');
|
||||
foreach (['action', 'content', 'username'] as $key) {
|
||||
if (isset($get[$key]) && $get[$key] !== '') {
|
||||
$db->where($key, 'like', "%{$get[$key]}%");
|
||||
}
|
||||
}
|
||||
$this->assign('actions', $actions);
|
||||
return parent::_list($db);
|
||||
}
|
||||
|
||||
@ -58,7 +59,7 @@ class Log extends BasicAdmin {
|
||||
foreach ($data as &$vo) {
|
||||
$result = $ip->btreeSearch($vo['ip']);
|
||||
$vo['isp'] = isset($result['region']) ? $result['region'] : '';
|
||||
$vo['isp'] = str_replace(['|0|0|0|0', '|'], ['', ' '], $vo['isp']);
|
||||
$vo['isp'] = str_replace(['|0|0|0|0', '0', '|'], ['', '', ' '], $vo['isp']);
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,9 +68,9 @@ class Log extends BasicAdmin {
|
||||
*/
|
||||
public function del() {
|
||||
if (DataService::update($this->table)) {
|
||||
$this->success("日志删除成功!", '');
|
||||
$this->success("日志删除成功!", '');
|
||||
}
|
||||
$this->error("日志删除失败,请稍候再试!");
|
||||
$this->error("日志删除失败, 请稍候再试!");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user