RoleDao.php 2.6 KB

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