/**
  * 绑定角色与权限的对应关系
  * @param $roleId   角色ID
  * @param $pids 权限ID列表
  * @param $loginUser \liuxy\admin\models\AdminUser
  */
 public static function bind($roleId, $pids, $loginUser)
 {
     self::deteteAll(['role_id' => $roleId]);
     if (!empty($pids)) {
         $pids = explode(',', $pids);
         $pids = array_unique($pids);
         foreach ($pids as $pid) {
             if (!empty($pid)) {
                 $item = new RolePermission();
                 $item->isNewRecord = true;
                 $item->role_id = $roleId;
                 $item->permission_id = $pid;
                 $item->insert_by = $loginUser->username;
                 $item->insert();
                 if ($item->hasErrors()) {
                     Yii::error(VarDumper::dumpAsString($item->getErrors()), __METHOD__);
                 }
                 unset($item);
             }
         }
         /**
          * 清理角色下所对应用户的权限
          */
         foreach (AdminUserRole::find()->where(['role_id' => $roleId])->all() as $userRole) {
             AdminUser::clearPermission($userRole['user_id']);
         }
     }
 }
 /**
  * 清理用户缓存
  * @param $permissionId
  */
 public static function clearUserPermission($permissionId)
 {
     $roles = [];
     foreach (RolePermission::find()->where(['permission_id' => $permissionId])->all() as $rolePerm) {
         $roles[] = $rolePerm['role_id'];
     }
     foreach (AdminUserRole::find()->where(['role_id' => $roles])->all() as $userRole) {
         AdminUser::clearPermission($userRole['user_id']);
     }
 }