73 lines
1.7 KiB
PHP
73 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace plugin\admin\app\controller;
|
|
|
|
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
|
|
* @throws Throwable
|
|
*/
|
|
public function index(): Response
|
|
{
|
|
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
|
|
]);
|
|
}
|
|
}
|