SystemRoleService.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\extra\service\system;
  3. use app\extra\basic\Service;
  4. use app\extra\dao\system\SystemRoleDao;
  5. class SystemRoleService extends Service
  6. {
  7. /**
  8. * 设置模型
  9. * @return string
  10. */
  11. public function __construct()
  12. {
  13. $this->dao = new SystemRoleDao();
  14. }
  15. /**
  16. * 列表
  17. * @param array $param
  18. */
  19. public function getList(array $param = [])
  20. {
  21. [$page,$limit] = $this->getPageValue();
  22. $list = $this->dao->getList($this->searchFilter($param),'*',$page,$limit,'id desc');
  23. $count = $this->dao->count($this->searchFilter($param));
  24. return compact('list','count');
  25. }
  26. protected function searchFilter(array $param = []): array
  27. {
  28. $filter = [];
  29. !empty($param['status']) && $filter[] = ["status", '=', $param['status']];
  30. // !empty($param['is_del']) && $filter[] = ["is_del", '=', $param['is_del']];
  31. return $filter;
  32. }
  33. /**
  34. * 获取添加身份规格
  35. */
  36. public function getMenus($roles = [], int $type = 1, int $is_show = 1): array
  37. {
  38. $field = ['title', 'pid', 'id'];
  39. // $where = ['is_del' => 0, 'type' => $type];
  40. // if ($is_show) $where['sta'] = 1;
  41. $where = [];
  42. $menuService = new MenuService();
  43. // if (!$roles) {
  44. $menus = $menuService->getMenusRoule($where, $field);
  45. // } else {
  46. // $roles = is_string($roles) ? explode(',', $roles) : $roles;
  47. // $ids = $this->dao->getRoleIds($roles);
  48. // $menus = $menuService->getMenusRoule(['rule' => $ids] + $where, $field);
  49. // }
  50. return $this->tidyMenuTier(false, $menus);
  51. }
  52. /**
  53. * 组合菜单数据
  54. * @param bool $adminFilter
  55. * @param $menusList
  56. * @param int $pid
  57. * @param array $navList
  58. * @return array
  59. */
  60. public function tidyMenuTier(bool $adminFilter = false, $menusList = [], int $pid = 0, array $navList = []): array
  61. {
  62. foreach ($menusList as $k => $menu) {
  63. $menu = $menu->getData();
  64. if ($menu['pid'] == $pid) {
  65. unset($menusList[$k]);
  66. $menu['children'] = $this->tidyMenuTier($adminFilter, $menusList, $menu['id']);
  67. if ($pid == 0 && !count($menu['children'])) continue;
  68. if ($menu['children']) $menu['expand'] = true;
  69. $navList[] = $menu;
  70. }
  71. }
  72. return $navList;
  73. }
  74. }