You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.1 KiB

<?php
namespace app\auth\model;
use think\facade\Db;
class AuthGroupRule extends Base
{
/*
* 根据角色id获取权限id
*/
public function getIds($id)
{
return $this->where(['role_id' => $id])->column('rule_id');
}
/*
* 保存权限数据
*/
public function saveData($role_id, $data)
{
if (empty($data)) {
$this->where(['role_id' => $role_id])->delete();
return true;
}
Db::startTrans();
try {
$this->where(['role_id' => $role_id])->delete();
$insertData = [];
foreach ($data as $val) {
$insertData[] = ['role_id' => $role_id, 'rule_id' => $val];
}
$this->insertAll($insertData);
Db::commit();
} catch (\Exception $e) {
Db::rollback();
return false;
}
return true;
}
/*
* 判断大量的权限是否被授权过
*/
public function getCountByRuleMany($arr)
{
return $this->where([['rule_id', 'IN', $arr]])->count('role_id');
}
}