修复若干bug

This commit is contained in:
2026-03-10 22:24:06 +08:00
parent 7cdb591f69
commit 98156991c1
16 changed files with 1021 additions and 892 deletions
+22 -11
View File
@@ -43,7 +43,9 @@ class RoleController extends BaseController
public function getRoleById(int $id)
{
$role = AdminUserGroup::where('id', $id)
->where('tid', $this->getTenantId())
->where(function ($query) {
$query->where('tid', $this->getTenantId())->whereOr('tid', 0);
})
->where('delete_time', null)
->find();
if (!$role) {
@@ -143,9 +145,11 @@ class RoleController extends BaseController
'rights|权限' => 'array'
]);
// 查找角色(验证tid
// 查找角色(验证tidtid为0的系统角色也可编辑
$role = AdminUserGroup::where('id', $id)
->where('tid', $this->getTenantId())
->where(function ($query) {
$query->where('tid', $this->getTenantId())->whereOr('tid', 0);
})
->where('delete_time', null)
->find();
if (!$role) {
@@ -155,10 +159,12 @@ class RoleController extends BaseController
]);
}
// 检查角色名称是否已被其他角色使用
// 检查角色名称是否已被其他角色使用tid为0或当前用户tid的角色)
$exists = AdminUserGroup::where('name', $data['name'])
->where('id', '<>', $id)
->where('tid', $this->getTenantId())
->where(function ($query) {
$query->where('tid', $this->getTenantId())->whereOr('tid', 0);
})
->where('delete_time', null)
->find();
if ($exists) {
@@ -169,18 +175,23 @@ class RoleController extends BaseController
}
// 更新数据
$role->name = $data['name'];
$role->status = $data['status'] ?? 1;
$role->rights = !empty($data['rights']) ? json_encode($data['rights']) : null;
$role->update_time = date('Y-m-d H:i:s');
$role->save();
$updateData = [
'name' => $data['name'],
'status' => $data['status'] ?? 1,
'rights' => !empty($data['rights']) ? json_encode($data['rights']) : null,
'update_time' => date('Y-m-d H:i:s')
];
AdminUserGroup::where('id', $id)->update($updateData);
// 重新查询获取最新数据
$updatedRole = AdminUserGroup::where('id', $id)->find();
// 记录操作日志
$this->logSuccess('角色管理', '更新角色', ['id' => $id]);
return json([
'code' => 200,
'msg' => '更新成功',
'data' => $role->toArray()
'data' => $updatedRole->toArray()
]);
} catch (ValidateException $e) {
// 记录失败日志