| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- namespace app\admin\controller;
- use app\admin\service\AuthService;
- use app\common\model\AuthGroupAccessModel;
- use app\common\model\AuthGroupModel;
- use app\common\model\AuthRuleModel;
- use app\Request;
- use think\App;
- use app\BaseController;
- use think\facade\View;
- // 部门管理
- class Auth extends BaseController
- {
- private $service;
- public function __construct(App $app)
- {
- $this->service = new AuthService();
- parent::__construct($app);
- }
- public function index()
- {
- View::assign([
- 'list' => $this->service->authGroupModel->findByPaginate($this->request->param()),
- ]);
- return view();
- }
- // public function add() {
- // if ($this->request->isAjax()) {
- // $params = $this->request->param();
- // $res = $this->service->authGroupModel->save([
- // 'name' => format_string($params['name'] ?? null),
- // 'rules' => format_string($params['rule_ids'] ?? null),
- // 'describe' => format_string($params['describe'] ?? null),
- // ]);
- // return $this->ok($res);
- // }
- // return view();
- // }
- //
- // public function edit() {
- // $params = $this->request->param();
- // $id = $params['id'];
- // $group = $this->service->authGroupModel->findById($id);
- // if ($this->request->isAjax()) {
- // $res = $this->service->authGroupModel->where('id', $params['id'])->save([
- // 'name' => format_string($params['name'] ?? null),
- // 'rules' => format_string($params['rule_ids'] ?? null),
- // 'describe' => format_string($params['describe'] ?? null),
- // 'update_time' => time()
- // ]);
- // return $this->ok($res);
- // }
- // View::assign([
- // 'group' => $group,
- // ]);
- // return view();
- // }
- /**
- * @param null $admin_id
- * @return \think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function findAuthRuleByAdminId($admin_id = null) {
- $all_rules = $this->service->authRuleModel->findByIds(["*"]);
- $format_rules = array_map(function ($data) {
- return [
- 'id' => $data['id'],
- 'title' => $data['name'],
- 'pid' => $data['pid'],
- 'field' => $data['name'],
- 'spread' => true,
- 'checked' => false
- ];
- }, $all_rules);
- if(!isset($admin_id))
- return $this->ok(recursion($format_rules));
- $rules = $this->service->loadRuleByAdminId($admin_id);
- $in_rule_ids = array_map(function ($data) {
- return $data['id'];
- }, $rules);
- foreach ($format_rules as &$item) $item['checked'] = in_array($item['id'], $in_rule_ids);
- return $this->ok(recursion($format_rules));
- }
- /**
- * @param null $group_id
- * @return \think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function findAuthRuleByGroupId($group_id = null) {
- $format_rules = array_map(function ($data) {
- return [
- 'id' => $data['id'],
- 'title' => $data['name'],
- 'pid' => $data['pid'],
- 'field' => $data['name'],
- 'spread' => true,
- 'checked' => false
- ];
- }, $this->service->authRuleModel->findByIds(["*"]));
- if(!isset($group_id))
- return $this->ok(recursion($format_rules));
- $rules = $this->service->loadRuleByGroupId($group_id);
- $in_rule_ids = array_map(function ($data) {
- return $data['id'];
- }, $rules);
- foreach ($format_rules as &$item) $item['checked'] = in_array($item['id'], $in_rule_ids);
- return $this->ok(recursion($format_rules));
- }
- }
|