123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- <?php
- namespace app\admin\controller;
- use think\admin\Controller;
- use think\admin\service\AdminService;
- class Auth extends Controller
- {
-
- private $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 add()
- {
- $this->_applyFormToken();
- $this->_form($this->table, 'form');
- }
-
- public function edit()
- {
- $this->_applyFormToken();
- $this->_form($this->table, 'form');
- }
-
- public function state()
- {
- $this->_applyFormToken();
- $this->_save($this->table, $this->_vali([
- 'status.in:0,1' => '状态值范围异常!',
- 'status.require' => '状态值不能为空!',
- ]));
- }
-
- public function apply()
- {
- $map = $this->_vali(['auth.require#id' => '权限ID不能为空!']);
- if (input('action') === 'get') {
- if ($this->app->isDebug()) AdminService::instance()->clearCache();
- $checkeds = $this->app->db->name('SystemAuthNode')->where($map)->column('node');
- $this->success('获取权限节点成功!', AdminService::instance()->getTree($checkeds));
- } elseif (input('action') === 'save') {
- [$post, $data] = [$this->request->post(), []];
- foreach ($post['nodes'] ?? [] as $node) {
- $data[] = ['auth' => $map['auth'], 'node' => $node];
- }
- $this->app->db->name('SystemAuthNode')->where($map)->delete();
- $this->app->db->name('SystemAuthNode')->insertAll($data);
- sysoplog('系统权限管理', "配置系统权限[{$map['auth']}]授权成功");
- $this->success('权限授权修改成功!', 'javascript:history.back()');
- } else {
- $this->title = '权限配置节点';
- $this->_form($this->table, 'apply');
- }
- }
-
- public function remove()
- {
- $this->_applyFormToken();
- $this->_delete($this->table);
- }
-
- protected function _add_form_result(bool $result)
- {
- if ($result) {
- $id = $this->app->db->name($this->table)->getLastInsID();
- sysoplog('系统权限管理', "添加系统权限[{$id}]成功");
- }
- }
-
- protected function _edit_form_result(bool $result)
- {
- if ($result) {
- $id = input('id') ?: 0;
- sysoplog('系统权限管理', "修改系统权限[{$id}]成功");
- }
- }
-
- protected function _state_save_result(bool $result)
- {
- if ($result) {
- [$id, $state] = [input('id'), input('status')];
- sysoplog('系统权限管理', ($state ? '激活' : '禁用') . "系统权限[{$id}]成功");
- }
- }
-
- protected function _remove_delete_result(bool $result)
- {
- if ($result) {
- $map = $this->_vali(['auth.require#id' => '权限ID不能为空!']);
- $this->app->db->name('SystemAuthNode')->where($map)->delete();
- sysoplog('系统权限管理', "删除系统权限[{$map['auth']}]及授权配置");
- $this->success("权限删除成功!");
- } else {
- $this->error("权限删除失败,请稍候再试!");
- }
- }
- }
|