SystemAuth.php 1.9 KB

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