优化tenant模式

This commit is contained in:
2026-03-09 18:27:05 +08:00
parent bf0daf987b
commit e09b4c639c
14 changed files with 167 additions and 73 deletions
+62 -1
View File
@@ -7,6 +7,7 @@ namespace app\admin\controller;
use app\admin\BaseController;
use think\response\Json;
use app\model\AdminModules;
use app\model\AdminUserGroup;
class ModulesController extends BaseController
{
@@ -43,13 +44,73 @@ class ModulesController extends BaseController
}
}
/**
* 获取租户模块列表
* @return Json
*/
public function getTenantList()
{
try {
$userInfo = $this->getAdminUserInfo();
$groupId = $userInfo['group_id'] ?? null;
$menuIds = [];
if ($groupId) {
$userGroup = AdminUserGroup::where('id', $groupId)->find();
if ($userGroup && $userGroup->rights) {
$rights = $userGroup->rights;
$decoded = json_decode($rights, true);
$menuIds = is_array($decoded) ? $decoded : [];
}
}
if (empty($menuIds)) {
return json([
'code' => 200,
'msg' => '获取成功',
'data' => [
'list' => [],
'total' => 0
]
]);
}
$modules = AdminModules::where('delete_time', null)
->whereIn('mid', $menuIds)
->order('sort', 'asc')
->order('id', 'asc')
->select()
->toArray();
$this->logSuccess('模块管理', '获取模块列表', ['count' => count($modules)]);
return json([
'code' => 200,
'msg' => '获取成功',
'data' => [
'list' => $modules,
'total' => count($modules)
]
]);
} catch (\Exception $e) {
$this->logFail('模块管理', '获取模块列表', $e->getMessage());
return json([
'code' => 500,
'msg' => '获取失败:' . $e->getMessage(),
'data' => []
]);
}
}
/**
* 获取模块详情
* @return Json
*/
public function getDetail(int $id)
public function getDetail($id)
{
try {
$id = (int) $id;
$module = AdminModules::where('id', $id)
->where('delete_time', null)
->find();