81 lines
2.5 KiB
PHP
Executable File
81 lines
2.5 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\adminapi\controller\tcm;
|
|
|
|
use app\adminapi\controller\BaseAdminController;
|
|
use app\adminapi\logic\tcm\PrescriptionLibraryLogic;
|
|
use app\adminapi\validate\tcm\PrescriptionLibraryValidate;
|
|
|
|
/**
|
|
* 处方库控制器
|
|
*/
|
|
class PrescriptionLibraryController extends BaseAdminController
|
|
{
|
|
/**
|
|
* @notes 处方库列表
|
|
*/
|
|
public function lists()
|
|
{
|
|
return $this->dataLists(new \app\adminapi\lists\tcm\PrescriptionLibraryLists());
|
|
}
|
|
|
|
/**
|
|
* @notes 添加处方库
|
|
*/
|
|
public function add()
|
|
{
|
|
$params = (new PrescriptionLibraryValidate())->post()->goCheck('add');
|
|
$params['creator_id'] = $this->adminId;
|
|
$params['creator_name'] = $this->adminInfo['name'] ?? '';
|
|
$id = PrescriptionLibraryLogic::add($params);
|
|
if ($id === null) {
|
|
return $this->fail(PrescriptionLibraryLogic::getError());
|
|
}
|
|
return $this->success('保存成功', ['id' => $id]);
|
|
}
|
|
|
|
/**
|
|
* @notes 编辑处方库
|
|
*/
|
|
public function edit()
|
|
{
|
|
$params = (new PrescriptionLibraryValidate())->post()->goCheck('edit');
|
|
$canAll = PrescriptionLibraryLogic::canManageAllPrescriptions($this->adminId, $this->adminInfo);
|
|
$result = PrescriptionLibraryLogic::edit($params, $this->adminId, $canAll);
|
|
if (!$result) {
|
|
return $this->fail(PrescriptionLibraryLogic::getError());
|
|
}
|
|
return $this->success('编辑成功');
|
|
}
|
|
|
|
/**
|
|
* @notes 删除处方库
|
|
*/
|
|
public function delete()
|
|
{
|
|
$params = (new PrescriptionLibraryValidate())->post()->goCheck('delete');
|
|
$canAll = PrescriptionLibraryLogic::canManageAllPrescriptions($this->adminId, $this->adminInfo);
|
|
$result = PrescriptionLibraryLogic::delete((int) $params['id'], $this->adminId, $canAll);
|
|
if (!$result) {
|
|
return $this->fail(PrescriptionLibraryLogic::getError());
|
|
}
|
|
return $this->success('删除成功');
|
|
}
|
|
|
|
/**
|
|
* @notes 处方库详情
|
|
*/
|
|
public function detail()
|
|
{
|
|
$params = (new PrescriptionLibraryValidate())->get()->goCheck('detail');
|
|
$canAll = PrescriptionLibraryLogic::canManageAllPrescriptions($this->adminId, $this->adminInfo);
|
|
$detail = PrescriptionLibraryLogic::detail((int) $params['id'], $this->adminId, $canAll);
|
|
if (!$detail) {
|
|
return $this->fail('处方不存在或无权限查看');
|
|
}
|
|
return $this->data($detail);
|
|
}
|
|
}
|