RoleDao.php 2.1 KB

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