SystemAuth.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | EasyAdmin
  4. // +----------------------------------------------------------------------
  5. // | PHP交流群: 763822524
  6. // +----------------------------------------------------------------------
  7. // | 开源协议 https://mit-license.org
  8. // +----------------------------------------------------------------------
  9. // | github开源项目:https://github.com/zhongshaofa/EasyAdmin
  10. // +----------------------------------------------------------------------
  11. namespace app\common\model;
  12. use app\common\model\TimeModel;
  13. class SystemAuth extends TimeModel
  14. {
  15. protected $deleteTime = 'delete_time';
  16. /**
  17. * 根据角色ID获取授权节点
  18. * @param $authId
  19. * @return array
  20. * @throws \think\db\exception\DataNotFoundException
  21. * @throws \think\db\exception\DbException
  22. * @throws \think\db\exception\ModelNotFoundException
  23. */
  24. public function getAuthorizeNodeListByAdminId($authId)
  25. {
  26. $checkNodeList = (new SystemAuthNode())
  27. ->where('auth_id', $authId)
  28. ->column('node_id');
  29. $systemNode = new SystemNode();
  30. $nodelList = $systemNode
  31. ->where('is_auth', 1)
  32. ->field('id,node,title,type,is_auth')
  33. ->select()
  34. ->toArray();
  35. $newNodeList = [];
  36. foreach ($nodelList as $vo) {
  37. if ($vo['type'] == 1) {
  38. $vo = array_merge($vo, ['field' => 'node', 'spread' => true]);
  39. $vo['checked'] = false;
  40. $vo['title'] = "{$vo['title']}【{$vo['node']}】";
  41. $children = [];
  42. foreach ($nodelList as $v) {
  43. if ($v['type'] == 2 && strpos($v['node'], $vo['node'] . '/') !== false) {
  44. $v = array_merge($v, ['field' => 'node', 'spread' => true]);
  45. $v['checked'] = in_array($v['id'], $checkNodeList) ? true : false;
  46. $v['title'] = "{$v['title']}【{$v['node']}】";
  47. $children[] = $v;
  48. }
  49. }
  50. !empty($children) && $vo['children'] = $children;
  51. $newNodeList[] = $vo;
  52. }
  53. }
  54. return $newNodeList;
  55. }
  56. }