76 lines
1.8 KiB
PHP
76 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace plugin\admin\app\controller;
|
|
|
|
use plugin\admin\app\model\OpmMwDepartment;
|
|
use plugin\admin\app\model\OpmMwHospital;
|
|
use plugin\admin\app\repository\DepartmentRepository;
|
|
use plugin\admin\app\service\DepartmentService;
|
|
use support\Request;
|
|
use support\Response;
|
|
|
|
/**
|
|
* 科室管理
|
|
*/
|
|
class DepartmentController extends Crud
|
|
{
|
|
use WithDataPermission;
|
|
|
|
/**
|
|
* @var OpmMwDepartment
|
|
*/
|
|
protected $model = null;
|
|
|
|
private DepartmentService $service;
|
|
private DepartmentRepository $repository;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->model = new OpmMwDepartment;
|
|
$this->service = new DepartmentService();
|
|
$this->repository = DepartmentRepository::new();
|
|
}
|
|
|
|
public function index(): Response
|
|
{
|
|
return raw_view('department/index');
|
|
}
|
|
|
|
public function insert(Request $request): Response
|
|
{
|
|
if ($request->method() === 'POST') {
|
|
return parent::insert($request);
|
|
}
|
|
return raw_view('department/insert');
|
|
}
|
|
|
|
public function update(Request $request): Response
|
|
{
|
|
if ($request->method() === 'POST') {
|
|
return parent::update($request);
|
|
}
|
|
return raw_view('department/update');
|
|
}
|
|
|
|
protected function afterQuery($items)
|
|
{
|
|
foreach ($items as &$item) {
|
|
$hospital = OpmMwHospital::find($item->organ_id);
|
|
$item->hospital_name = $hospital->organ_name ?? '未知';
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
/**
|
|
* 获取指定医院下科室选项
|
|
*/
|
|
public function options(Request $request): Response
|
|
{
|
|
$hospitalId = (int)$request->get('hospital_id', 0);
|
|
if ($hospitalId <= 0) {
|
|
return $this->json(1, '缺少医院ID参数');
|
|
}
|
|
return $this->json(0, 'ok', $this->service->getDepartmentOptions($hospitalId));
|
|
}
|
|
}
|