MenuService.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\extra\service\system;
  3. use app\extra\basic\Service;
  4. use app\extra\dao\system\SystemMenuDao;
  5. use app\model\inmei\InmeiMenu;
  6. use app\model\system\SystemMenu;
  7. class MenuService extends Service
  8. {
  9. /**
  10. * 设置模型
  11. * @return string
  12. */
  13. public function __construct()
  14. {
  15. $this->dao = new SystemMenuDao();
  16. }
  17. /**
  18. * @param int $super
  19. * @param int $hide
  20. * @param int $type
  21. * @return array
  22. */
  23. public function getMenuList(int $roles = 0,int $hide = 0,int $type = 1): array
  24. {
  25. $model = new SystemMenu();
  26. try {
  27. if($roles>-1){
  28. $systemRoleService = new SystemRoleService();
  29. $rules = $systemRoleService->getColumn(['id'=>$roles],'rules');
  30. $rulesStr = array_unique(explode(',', implode(',', $rules)));
  31. $data = $model->where("status",1)->whereIn('id',$rulesStr)->where("from",$type)->order("sort","asc")->select();
  32. }else{
  33. $data = $model->where("status",1)->where("from",$type)->order("sort","asc")->select();
  34. }
  35. } catch (\Throwable $throwable) {
  36. return [];
  37. }
  38. return $data->isEmpty()?[]:$data->toArray();
  39. }
  40. }