123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- namespace app\admin\controller;
- use library\Controller;
- use library\service\AdminService;
- use think\Db;
- class Auth extends Controller
- {
-
- public $table = 'SystemAuth';
-
- public function index()
- {
- $this->title = '系统权限管理';
- $query = $this->_query($this->table)->dateBetween('create_at');
- $query->like('title,desc')->equal('status')->order('sort desc,id desc')->page();
- }
-
- public function apply()
- {
- $map = ['auth' => input('id', '0')];
- $action = strtolower(input('action', ''));
- if ($action === 'get') {
- $checkeds = Db::name('SystemAuthNode')->where($map)->column('node');
- $this->success('获取权限节点成功!', AdminService::instance()->getTree($checkeds));
- } elseif ($action === 'save') {
- list($post, $data) = [$this->request->post(), []];
- foreach (isset($post['nodes']) ? $post['nodes'] : [] as $node) {
- $data[] = ['auth' => $map['auth'], 'node' => $node];
- }
- Db::name('SystemAuthNode')->where($map)->delete();
- Db::name('SystemAuthNode')->insertAll($data);
- AdminService::instance()->apply(true);
- $this->success('权限授权更新成功!', 'javascript:history.back()');
- } else {
- $this->title = '权限配置节点';
- $this->_form($this->table, 'apply');
- }
- }
-
- public function add()
- {
- $this->applyCsrfToken();
- $this->_form($this->table, 'form');
- }
-
- public function edit()
- {
- $this->applyCsrfToken();
- $this->_form($this->table, 'form');
- }
-
- public function refresh()
- {
- try {
- AdminService::instance()->apply(true);
- $this->success('刷新系统授权成功!');
- } catch (\think\exception\HttpResponseException $exception) {
- throw $exception;
- } catch (\Exception $e) {
- $this->error("刷新系统授权失败<br>{$e->getMessage()}");
- }
- }
-
- public function forbid()
- {
- $this->applyCsrfToken();
- $this->_save($this->table, ['status' => '0']);
- }
-
- public function resume()
- {
- $this->applyCsrfToken();
- $this->_save($this->table, ['status' => '1']);
- }
-
- public function remove()
- {
- $this->applyCsrfToken();
- $this->_delete($this->table);
- }
-
- protected function _remove_delete_result($result)
- {
- if ($result) {
- $map = ['auth' => $this->request->post('id')];
- Db::name('SystemAuthNode')->where($map)->delete();
- $this->success("权限删除成功!", '');
- } else {
- $this->error("权限删除失败,请稍候再试!");
- }
- }
- }
|