RoleDao.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\common\dao\system\menu;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\BaseModel;
  5. use app\common\model\system\auth\Role;
  6. /**
  7. * Class RoleDao
  8. * @package app\common\dao\system\menu
  9. * @author zfy
  10. * @day 2020-04-18
  11. */
  12. class RoleDao extends BaseDao
  13. {
  14. /**
  15. * @return BaseModel
  16. * @author zfy
  17. * @day 2020-03-30
  18. */
  19. protected function getModel(): string
  20. {
  21. return Role::class;
  22. }
  23. /**
  24. * @param $merId
  25. * @param array $where
  26. * @return BaseModel|Role
  27. * @author zfy
  28. * @day 2020-04-18
  29. */
  30. public function search($merId, array $where = [])
  31. {
  32. $roleModel = Role::getInstance();
  33. if (isset($where['role_name'])) {
  34. $roleModel = $roleModel->whereLike('role_name', '%' . $where['role_name'] . '%');
  35. }
  36. if (isset($where['status'])) {
  37. $roleModel = $roleModel->where('status', intval($where['status']));
  38. }
  39. return $roleModel->where('mer_id', $merId);
  40. }
  41. /**
  42. * @param int $merId
  43. * @return array
  44. * @author zfy
  45. * @day 2020-04-18
  46. */
  47. public function getAllOptions(int $merId)
  48. {
  49. return Role::getDB()->where('status', 1)->where('mer_id', $merId)->column('role_name', 'role_id');
  50. }
  51. /**
  52. * @param $merId
  53. * @param array $ids
  54. * @return array
  55. * @author zfy
  56. * @day 2020-04-18
  57. */
  58. public function idsByRules($merId, array $ids)
  59. {
  60. $rules = Role::getDB()->where('status', 1)->where('mer_id', $merId)->whereIn($this->getPk(), $ids)->column('rules');
  61. $data = [];
  62. foreach ($rules as $rule) {
  63. $data = array_merge(explode(',', $rule), $data);
  64. }
  65. return array_unique($data);
  66. }
  67. /**
  68. * @param int $merId
  69. * @param int $id
  70. * @return bool
  71. * @author zfy
  72. * @day 2020-04-18
  73. */
  74. public function merExists(int $merId, int $id)
  75. {
  76. return Role::getDB()->where($this->getPk(), $id)->where('mer_id', $merId)->count() > 0;
  77. }
  78. }