1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
 
namespace app\branch\model\auth;
 
use app\common\model\branch\UserRole as UserRoleModel;
 
 
/**
 * 角色模型
 */
class UserRole extends UserRoleModel
{
 
    public function getUserRole($where)
    {
        return $this->where($where)->column('role_id');
 
    }
 
    /**
     * 获取指定管理员的所有角色id
     * @param $branch_user_id
     * @return array
     */
    public static function getRoleIds($branch_user_id)
    {
        return (new self)->where('branch_user_id', '=', $branch_user_id)->column('role_id');
    }
 
    /**
     * 获取角色下的用户
     */
    public static  function getUserRoleCount($role_id){
        $model = new static();
        return $model->alias('userRole')
            ->join('branch_user', 'userRole.branch_user_id = branch_user.branch_user_id', 'left')
            ->where('userRole.role_id', '=', $role_id)
            ->where('branch_user.is_delete', '=', 0)
            ->count();
    }
}