AuthRule.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace Ycbl\AdminAuth\Dao;
  3. use Hyperf\Contract\ConfigInterface;
  4. use Psr\Container\ContainerInterface;
  5. use Ycbl\AdminAuth\Model\AuthRule as Model;
  6. class AuthRule
  7. {
  8. /**
  9. * @var Model
  10. */
  11. protected $model;
  12. public function __construct(ContainerInterface $container, ConfigInterface $config)
  13. {
  14. $this->model = $container->get($config->get('admin_auth.auth_rule'));
  15. }
  16. public function getRuleList()
  17. {
  18. return $this->model::query()
  19. ->select(["id", "pid", "path", "auth", "title", "icon", "ismenu", "weigh", "status"])
  20. ->orderBy('weigh', 'DESC')->orderBy('id')
  21. ->get();
  22. }
  23. public function getOneRuleById($id)
  24. {
  25. return $this->model::query()->where('id', $id)->first();
  26. }
  27. public function insertRule($data)
  28. {
  29. return $this->model::query()->insert($data);
  30. }
  31. public function updateRuleById($id, $data)
  32. {
  33. return $this->model::query()->where('id', $id)->update($data);
  34. }
  35. public function deleteRule($ids)
  36. {
  37. return $this->model::query()->whereIn('id',$ids)->delete();
  38. }
  39. public function getAllMenu()
  40. {
  41. $where[] = ['status', '=', '1'];
  42. $where[] = ['ismenu', '=', '1'];
  43. return $this->model::where($where)->get();
  44. }
  45. public function getEnableRulesById($ids)
  46. {
  47. $rules = $this->model::query()
  48. ->select(['id', 'pid', 'path', 'auth', 'icon', 'title', 'ismenu', 'remark'])
  49. ->where('status', '=', '1');
  50. if (!in_array('*', $ids)) {
  51. $rules->whereIn('id', $ids);
  52. }
  53. return $rules->get();
  54. }
  55. }