123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace app\common\dao\system\menu;
- use app\common\dao\BaseDao;
- use app\common\model\BaseModel;
- use app\common\model\system\auth\Role;
- /**
- * Class RoleDao
- * @package app\common\dao\system\menu
- * @author zfy
- * @day 2020-04-18
- */
- class RoleDao extends BaseDao
- {
- /**
- * @return BaseModel
- * @author zfy
- * @day 2020-03-30
- */
- protected function getModel(): string
- {
- return Role::class;
- }
- /**
- * @param $merId
- * @param array $where
- * @return BaseModel|Role
- * @author zfy
- * @day 2020-04-18
- */
- public function search($merId, array $where = [])
- {
- $roleModel = Role::getInstance();
- if (isset($where['role_name'])) {
- $roleModel = $roleModel->whereLike('role_name', '%' . $where['role_name'] . '%');
- }
- if (isset($where['status'])) {
- $roleModel = $roleModel->where('status', intval($where['status']));
- }
- return $roleModel->where('mer_id', $merId);
- }
- /**
- * @param int $merId
- * @return array
- * @author zfy
- * @day 2020-04-18
- */
- public function getAllOptions(int $merId)
- {
- return Role::getDB()->where('status', 1)->where('mer_id', $merId)->column('role_name', 'role_id');
- }
- /**
- * @param $merId
- * @param array $ids
- * @return array
- * @author zfy
- * @day 2020-04-18
- */
- public function idsByRules($merId, array $ids)
- {
- $rules = Role::getDB()->where('status', 1)->where('mer_id', $merId)->whereIn($this->getPk(), $ids)->column('rules');
- $data = [];
- foreach ($rules as $rule) {
- $data = array_merge(explode(',', $rule), $data);
- }
- return array_unique($data);
- }
- /**
- * @param int $merId
- * @param int $id
- * @return bool
- * @author zfy
- * @day 2020-04-18
- */
- public function merExists(int $merId, int $id)
- {
- return Role::getDB()->where($this->getPk(), $id)->where('mer_id', $merId)->count() > 0;
- }
- }
|