This commit is contained in:
zimoyin
2026-04-03 11:32:19 +08:00
parent 4c841b9dbf
commit 1a84e92384
30 changed files with 403 additions and 1030 deletions
+53 -9
View File
@@ -2,20 +2,16 @@
namespace plugin\admin\app\controller;
use Doctrine\Inflector\InflectorFactory;
use Illuminate\Database\Schema\Blueprint;
use plugin\admin\app\common\Layui;
use plugin\admin\app\common\Util;
use plugin\admin\app\model\Role;
use plugin\admin\app\model\Rule;
use plugin\admin\app\model\Option;
use support\exception\BusinessException;
use support\Request;
use plugin\admin\app\model\OpmMwDepartment;
use plugin\admin\app\model\OpmMwHospital;
use app\utils\Logger;
use support\Response;
use Throwable;
class TestController extends Crud
{
/**
* 浏览
* @return Response
@@ -25,4 +21,52 @@ class TestController extends Crud
{
return raw_view('test/index');
}
/**
* 获取医院科室树形结构
* @return Response
*/
public function tree(): Response
{
// 1. 查询所有医院
$hospitals = OpmMwHospital::where('is_true', 1) // 只查有效医院
->withDataPermission()
->orderBy('id')
->get();
// 2. 组装树结构
$treeData = [];
foreach ($hospitals as $hospital) {
// 医院节点
$hospitalNode = [
'id' => $hospital->id,
'title' => $hospital->organ_name, // 医院名称
'children' => []
];
// 3. 查询该医院下的所有科室
$departments = OpmMwDepartment::where('organ_id', $hospital->id)
->withDataPermission()
->orderBy('sort_id')
->get();
// 4. 组装科室节点
foreach ($departments as $dept) {
$hospitalNode['children'][] = [
'id' => $dept->id,
'title' => $dept->dept_name // 科室名称
];
}
$treeData[] = $hospitalNode;
}
// 5. 返回 Layui 树需要的格式
return json([
'code' => 0,
'msg' => 'success',
'data' => $treeData
]);
}
}