SystemAdminDao.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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. * @param string $field
  30. * @return array
  31. * @throws \think\db\exception\DataNotFoundException
  32. * @throws \think\db\exception\DbException
  33. * @throws \think\db\exception\ModelNotFoundException
  34. */
  35. public function getList(array $where, int $page = 0, int $limit = 0, string $field = '*')
  36. {
  37. return $this->search($where)->field($field)->when($page && $limit, function ($query) use($page, $limit) {
  38. $query->page($page, $limit);
  39. })->select()->toArray();
  40. }
  41. /**
  42. * 用管理员名查找管理员信息
  43. * @param string $account
  44. * @param int $adminType
  45. * @return array|\think\Model|null
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\DbException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. */
  50. public function accountByAdmin(string $account, int $adminType)
  51. {
  52. return $this->search(['account' => $account, 'is_del' => 0, 'status' => 1, 'admin_type' => $adminType])->find();
  53. }
  54. /**
  55. * 用电话查找管理员信息
  56. * @param string $phone
  57. * @param int $adminType
  58. * @return array|\think\Model|null
  59. * @throws \think\db\exception\DataNotFoundException
  60. * @throws \think\db\exception\DbException
  61. * @throws \think\db\exception\ModelNotFoundException
  62. */
  63. public function phoneByAdmin(string $phone, int $adminType = 1)
  64. {
  65. return $this->search(['phone' => $phone, 'is_del' => 0, 'status' => 1, 'admin_type' => $adminType])->find();
  66. }
  67. /**
  68. * 当前账号是否可用
  69. * @param string $account
  70. * @param int $id
  71. * @param int $admin_type
  72. * @return int
  73. * @throws \think\db\exception\DbException
  74. */
  75. public function isAccountUsable(string $account, int $id, int $admin_type = 1)
  76. {
  77. return $this->search(['account' => $account, 'is_del' => 0])->where('admin_type', $admin_type)->where('id', '<>', $id)->count();
  78. }
  79. /**
  80. * 获取adminid
  81. * @param int $level
  82. * @return array
  83. */
  84. public function getAdminIds(int $level)
  85. {
  86. return $this->getModel()->where('level', '>=', $level)->column('id', 'id');
  87. }
  88. /**
  89. * 获取低于等级的管理员名称和id
  90. * @param string $field
  91. * @param int $level
  92. * @return array
  93. * @throws \think\db\exception\DataNotFoundException
  94. * @throws \think\db\exception\DbException
  95. * @throws \think\db\exception\ModelNotFoundException
  96. */
  97. public function getOrdAdmin(string $field = 'real_name,id', int $level = 0)
  98. {
  99. return $this->getModel()->where('level', '>=', $level)->field($field)->select()->toArray();
  100. }
  101. }