SystemAdminDao.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\dao\system\admin;
  12. use app\dao\BaseDao;
  13. use app\model\system\admin\SystemAdmin;
  14. /**
  15. * Class SystemAdminDao
  16. * @package app\dao\system\admin
  17. */
  18. class SystemAdminDao extends BaseDao
  19. {
  20. protected function setModel(): string
  21. {
  22. return SystemAdmin::class;
  23. }
  24. /**
  25. * 获取管理员列表
  26. * @param array $where
  27. * @param int $page
  28. * @param int $limit
  29. * @return mixed
  30. */
  31. public function getList(array $where, int $page, int $limit)
  32. {
  33. return $this->search($where)->page($page, $limit)->select()->toArray();
  34. }
  35. /**
  36. * 用管理员名查找管理员信息
  37. * @param string $account
  38. * @return array|\think\Model|null
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\DbException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. */
  43. public function accountByAdmin(string $account)
  44. {
  45. return $this->search(['account' => $account, 'is_del' => 0])->find();
  46. }
  47. /**
  48. * 当前账号是否可用
  49. * @param string $account
  50. * @param int $id
  51. * @return int
  52. */
  53. public function isAccountUsable(string $account, int $id)
  54. {
  55. return $this->search(['account' => $account, 'is_del' => 0])->where('id', '<>', $id)->count();
  56. }
  57. /**
  58. * 获取adminid
  59. * @param int $level
  60. * @return array
  61. */
  62. public function getAdminIds(int $level)
  63. {
  64. return $this->getModel()->where('level', '>=', $level)->column('id', 'id');
  65. }
  66. /**
  67. * 获取低于等级的管理员名称和id
  68. * @param string $field
  69. * @param int $level
  70. * @return array
  71. * @throws \think\db\exception\DataNotFoundException
  72. * @throws \think\db\exception\DbException
  73. * @throws \think\db\exception\ModelNotFoundException
  74. */
  75. public function getOrdAdmin(string $field = 'real_name,id', int $level = 0)
  76. {
  77. return $this->getModel()->where('level', '>=', $level)->field($field)->select()->toArray();
  78. }
  79. /**
  80. * 条件获取管理员数据
  81. * @param $where
  82. * @return mixed
  83. */
  84. public function getInfo($where)
  85. {
  86. return $this->getModel()->where($where)->find();
  87. }
  88. /**
  89. * 检测是否有管理员使用该角色
  90. * @param int $id
  91. * @return bool
  92. */
  93. public function checkRoleUse(int $id): bool
  94. {
  95. return (bool)$this->getModel()->where('is_del', 0)->whereFindInSet('roles', $id)->count();
  96. }
  97. }