This commit is contained in:
Your Name
2026-11-26 17:17:43 +08:00
parent be79e09c83
commit 301c04ca90
8 changed files with 515 additions and 125 deletions
@@ -9,7 +9,7 @@ use app\adminapi\logic\tcm\PrescriptionLogic;
use app\adminapi\validate\tcm\PrescriptionValidate;
use app\common\service\esign\DoctorEsignIdentityService;
use app\common\service\esign\PrescriptionCaSigningSettings;
use app\common\service\esign\PrescriptionEsignService;
use app\common\service\esign\PrescriptionEsignService;
use app\common\service\esign\PrescriptionReviewEsignService;
/**
@@ -32,11 +32,11 @@ class PrescriptionController extends BaseAdminController
{
$params = (new PrescriptionValidate())->post()->goCheck('add');
$params['creator_id'] = $this->adminId;
$id = PrescriptionLogic::add($params, $this->adminId, $this->adminInfo);
$id = PrescriptionLogic::add($params, $this->adminId, $this->adminInfo);
if ($id === null) {
return $this->fail(PrescriptionLogic::getError());
}
return $this->success('保存成功', ['id' => $id, 'esign' => PrescriptionEsignService::status($id, (int) $this->adminId, $this->adminInfo)]);
return $this->success('保存成功', ['id' => $id, 'esign' => PrescriptionEsignService::status($id, (int) $this->adminId, $this->adminInfo)]);
}
/**
@@ -49,7 +49,7 @@ class PrescriptionController extends BaseAdminController
if (!$result) {
return $this->fail(PrescriptionLogic::getError());
}
return $this->success('编辑成功', ['id' => (int) $params['id'], 'esign' => PrescriptionEsignService::status((int) $params['id'], (int) $this->adminId, $this->adminInfo)]);
return $this->success('编辑成功', ['id' => (int) $params['id'], 'esign' => PrescriptionEsignService::status((int) $params['id'], (int) $this->adminId, $this->adminInfo)]);
}
/**
@@ -157,12 +157,12 @@ class PrescriptionController extends BaseAdminController
$diagnosisId = (int)($this->request->get('diagnosis_id') ?? 0);
if (!$diagnosisId) {
return $this->fail('诊单ID不能为空');
}
$list = PrescriptionLogic::listByDiagnosis($diagnosisId, (int) $this->adminId, $this->adminInfo);
if (PrescriptionLogic::getError() !== '') {
return $this->fail(PrescriptionLogic::getError());
}
return $this->data($list);
}
$list = PrescriptionLogic::listByDiagnosis($diagnosisId, (int) $this->adminId, $this->adminInfo);
if (PrescriptionLogic::getError() !== '') {
return $this->fail(PrescriptionLogic::getError());
}
return $this->data($list);
}
/**
@@ -190,11 +190,11 @@ class PrescriptionController extends BaseAdminController
*/
public function void()
{
if (!$this->request->isPost()) {
return $this->fail('请使用 POST 作废处方');
}
if (!$this->request->isPost()) {
return $this->fail('请使用 POST 作废处方');
}
$id = (int)($this->request->post('id') ?? 0);
if ($id <= 0) {
if ($id <= 0) {
return $this->fail('处方ID不能为空');
}
$pendingOnly = $this->request->post('pending_only', false, null);
@@ -207,11 +207,11 @@ class PrescriptionController extends BaseAdminController
}
return $this->success('作废成功');
}
public function esignConfig()
{
return $this->data(PrescriptionEsignService::capability());
}
public function esignConfig()
{
return $this->data(PrescriptionEsignService::capability());
}
/** @notes 修改处方 CA 签名设置 */
public function esignSetConfig()
@@ -235,37 +235,37 @@ class PrescriptionController extends BaseAdminController
return $this->fail('CA 签名设置暂时无法保存,请稍后重试');
}
}
public function esignStatus()
{
return $this->esignOperation('status', false);
}
public function esignIdentityStatus()
{
return $this->esignOperation('identityStatus', false);
}
public function esignStart()
{
return $this->esignOperation('start', true);
}
public function esignComplete()
{
return $this->esignOperation('complete', true);
}
public function esignStatus()
{
return $this->esignOperation('status', false);
}
public function esignIdentityStatus()
{
return $this->esignOperation('identityStatus', false);
}
public function esignStart()
{
return $this->esignOperation('start', true);
}
public function esignComplete()
{
return $this->esignOperation('complete', true);
}
/** @notes 验证处方签署短信 */
public function esignVerifyWillingness()
{
return $this->esignOperation('verifyWillingness', true);
}
public function esignDownload()
{
return $this->esignOperation('download', false);
}
public function esignDownload()
{
return $this->esignOperation('download', false);
}
public function esignReviewStatus()
{
@@ -309,7 +309,7 @@ class PrescriptionController extends BaseAdminController
? $error->getMessage() : '审核签署暂不可用,请刷新状态后重试');
}
}
/** @notes 查询医师电子签署认证 */
public function esignDoctorStatus()
{
@@ -355,26 +355,35 @@ class PrescriptionController extends BaseAdminController
}
return $this->data($data)->header(['Cache-Control' => 'private, no-store']);
} catch (\Throwable $error) {
return $this->fail($error instanceof \DomainException ? $error->getMessage() : '医师认证暂不可用,请稍后重试');
// 只记录异常类型与位置,不记录手机号、证件号或 e签宝原始响应。
\think\facade\Log::warning('Doctor esign ' . $operation . ' failed', [
'admin_id' => (int) $this->adminId,
'exception' => get_class($error),
'provider_code' => $error instanceof \app\common\service\esign\EsignProviderException
? $error->operation . ':' . $error->providerCode . ':' . ($error->reason ?? '') : '',
'at' => basename($error->getFile()) . ':' . $error->getLine(),
]);
return $this->fail($error instanceof \DomainException || $error instanceof \app\common\service\esign\EsignProviderException
? mb_substr($error->getMessage(), 0, 240) : '医师认证暂不可用,请稍后重试');
}
}
private function esignOperation(string $operation, bool $post)
{
if ($post && !$this->request->isPost()) {
return $this->fail('请使用 POST 请求');
}
$id = (int) ($post ? $this->request->post('id', 0) : $this->request->get('id', 0));
if ($id <= 0) {
return $this->fail('处方ID无效');
}
if ($operation === 'complete') {
// A browser disconnect must not interrupt archival after signing.
ignore_user_abort(true);
set_time_limit(300);
}
try {
$body = $post ? $this->request->post(false) : [];
private function esignOperation(string $operation, bool $post)
{
if ($post && !$this->request->isPost()) {
return $this->fail('请使用 POST 请求');
}
$id = (int) ($post ? $this->request->post('id', 0) : $this->request->get('id', 0));
if ($id <= 0) {
return $this->fail('处方ID无效');
}
if ($operation === 'complete') {
// A browser disconnect must not interrupt archival after signing.
ignore_user_abort(true);
set_time_limit(300);
}
try {
$body = $post ? $this->request->post(false) : [];
if ($operation === 'verifyWillingness') {
$code = $this->request->post('auth_code', '');
if (!is_string($code)) {
@@ -383,29 +392,29 @@ class PrescriptionController extends BaseAdminController
return $this->data(PrescriptionEsignService::verifyWillingness($id, (int) $this->adminId,
$this->adminInfo, $code));
}
if ($operation === 'start') {
$restartIdentity = array_key_exists('restart_identity', $body) ? $body['restart_identity'] : false;
if (!is_bool($restartIdentity)) {
return $this->fail('重新核身标记格式无效');
}
return $this->data(PrescriptionEsignService::start($id, (int) $this->adminId,
$this->adminInfo, $restartIdentity));
}
if ($operation === 'complete') {
$verifyOnly = array_key_exists('verify_only', $body) ? $body['verify_only'] : false;
if (!is_bool($verifyOnly)) {
return $this->fail('验签标记格式无效');
}
$identityNumber = $this->request->post('identity_number', '');
if (!is_string($identityNumber)) {
return $this->fail('身份证号码格式无效');
}
return $this->data(PrescriptionEsignService::complete($id, (int) $this->adminId,
$this->adminInfo, $identityNumber, $verifyOnly));
}
return $this->data(PrescriptionEsignService::{$operation}($id, (int) $this->adminId, $this->adminInfo));
} catch (\Throwable $e) {
return $this->fail($e instanceof \DomainException ? $e->getMessage() : '电子签署暂不可用,请联系管理员');
}
}
if ($operation === 'start') {
$restartIdentity = array_key_exists('restart_identity', $body) ? $body['restart_identity'] : false;
if (!is_bool($restartIdentity)) {
return $this->fail('重新核身标记格式无效');
}
return $this->data(PrescriptionEsignService::start($id, (int) $this->adminId,
$this->adminInfo, $restartIdentity));
}
if ($operation === 'complete') {
$verifyOnly = array_key_exists('verify_only', $body) ? $body['verify_only'] : false;
if (!is_bool($verifyOnly)) {
return $this->fail('验签标记格式无效');
}
$identityNumber = $this->request->post('identity_number', '');
if (!is_string($identityNumber)) {
return $this->fail('身份证号码格式无效');
}
return $this->data(PrescriptionEsignService::complete($id, (int) $this->adminId,
$this->adminInfo, $identityNumber, $verifyOnly));
}
return $this->data(PrescriptionEsignService::{$operation}($id, (int) $this->adminId, $this->adminInfo));
} catch (\Throwable $e) {
return $this->fail($e instanceof \DomainException ? $e->getMessage() : '电子签署暂不可用,请联系管理员');
}
}
}