mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified 完善权限组权限细节编辑
This commit is contained in:
parent
4e9179be81
commit
f898ffb23a
@ -130,11 +130,19 @@ class Auth extends Base {
|
|||||||
/**
|
/**
|
||||||
* 编辑用户
|
* 编辑用户
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws \Exception
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
*/
|
*/
|
||||||
public function edit() {
|
public function edit() {
|
||||||
$postData = $this->request->post();
|
$postData = $this->request->post();
|
||||||
$res = ApiMenu::update($postData);
|
if ($postData['rules']) {
|
||||||
|
$this->editRule();
|
||||||
|
}
|
||||||
|
unset($postData['rules']);
|
||||||
|
$res = ApiAuthGroup::update($postData);
|
||||||
if ($res === false) {
|
if ($res === false) {
|
||||||
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
|
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
|
||||||
} else {
|
} else {
|
||||||
@ -183,4 +191,42 @@ class Auth extends Base {
|
|||||||
return $newList;
|
return $newList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑权限细节
|
||||||
|
* @throws \Exception
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
private function editRule() {
|
||||||
|
$postData = $this->request->post();
|
||||||
|
$needAdd = [];
|
||||||
|
$has = (new ApiAuthRule())->where(['groupId' => $postData['id']])->select();
|
||||||
|
$has = $this->buildArrFromObj($has);
|
||||||
|
$hasRule = array_column($has, 'url');
|
||||||
|
$needDel = array_flip($hasRule);
|
||||||
|
foreach ($postData['rules'] as $key => $value) {
|
||||||
|
if (!empty($value)) {
|
||||||
|
if (!in_array($value, $hasRule)) {
|
||||||
|
$data['url'] = $value;
|
||||||
|
$data['groupId'] = $postData['id'];
|
||||||
|
$needAdd[] = $data;
|
||||||
|
} else {
|
||||||
|
unset($needDel[$value]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count($needAdd)) {
|
||||||
|
(new ApiAuthRule())->saveAll($needAdd);
|
||||||
|
}
|
||||||
|
if (count($needDel)) {
|
||||||
|
$urlArr = array_keys($needDel);
|
||||||
|
ApiAuthRule::destroy([
|
||||||
|
'groupId' => $postData['id'],
|
||||||
|
'url' => ['in', $urlArr]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user