管理员列表支持解除电子签署身份,处理同一实名绑定冲突
e签宝 对同一证件只签发一个签署账号,同一实名在另一后台账号认证时会绑定冲突。 - 新增 auth.admin/esignUnbind:清除目标账号在当前 e签宝 应用下的签署账号绑定、 在途认证与快捷签授权;有在途操作时拒绝;不注销 e签宝 账号,已签处方不受影响 - 该接口加入 AuthMiddleware 强制鉴权列表,菜单未登记时也不放行; 迁移 2026_11_27_admin_esign_unbind_menu.sql 登记按钮权限,默认仅超级管理员可用 - 管理员列表显示「签署身份」并提供「解除签署」按钮 - 绑定冲突提示指明占用的后台账号(名称 + ID) - 医师认证失败日志把字段写进消息正文(ThinkPHP 不落盘 context) Co-Authored-By: Claude Opus 5 (1M context) <[EMAIL]>
This commit is contained in:
co-authored by
Claude Opus 5 (1M context)
parent
e4d788ed32
commit
2019f9dca1
@@ -22,6 +22,7 @@ use app\adminapi\logic\LoginLogic;
|
||||
use app\adminapi\validate\auth\editSelfValidate;
|
||||
use app\common\cache\AdminTokenCache;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\service\esign\DoctorEsignIdentityService;
|
||||
|
||||
/**
|
||||
* 管理员控制器
|
||||
@@ -211,4 +212,20 @@ class AdminController extends BaseAdminController
|
||||
return $this->success('解绑成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 解除管理员的电子签署身份(同一实名改绑到其他后台账号时使用)
|
||||
*/
|
||||
public function esignUnbind()
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
return $this->fail('请使用 POST 请求');
|
||||
}
|
||||
try {
|
||||
DoctorEsignIdentityService::unbind((int) $this->request->post('id', 0));
|
||||
} catch (\DomainException $error) {
|
||||
return $this->fail($error->getMessage());
|
||||
}
|
||||
return $this->success('已解除签署身份', [], 1, 1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -356,13 +356,16 @@ class PrescriptionController extends BaseAdminController
|
||||
return $this->data($data)->header(['Cache-Control' => 'private, no-store']);
|
||||
} catch (\Throwable $error) {
|
||||
// 只记录异常类型与位置,不记录手机号、证件号或 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(),
|
||||
]);
|
||||
// ThinkPHP 的 context 只用于占位符替换,不会写入日志,因此字段直接拼进消息。
|
||||
\think\facade\Log::warning(sprintf(
|
||||
'Doctor esign %s failed admin_id=%d exception=%s provider=%s at=%s',
|
||||
$operation,
|
||||
(int) $this->adminId,
|
||||
get_class($error),
|
||||
$error instanceof \app\common\service\esign\EsignProviderException
|
||||
? $error->operation . ':' . $error->providerCode . ':' . ($error->reason ?? '') : '-',
|
||||
basename($error->getFile()) . ':' . $error->getLine()
|
||||
));
|
||||
return $this->fail($error instanceof \DomainException || $error instanceof \app\common\service\esign\EsignProviderException
|
||||
? mb_substr($error->getMessage(), 0, 240) : '医师认证暂不可用,请稍后重试');
|
||||
}
|
||||
|
||||
@@ -355,6 +355,8 @@ class AuthMiddleware
|
||||
'tcm.prescription/void',
|
||||
'tcm.prescription/audit',
|
||||
'tcm.prescription/submitforreview',
|
||||
// 解除他人签署身份:菜单迁移未执行时也不能因“未登记路由”而放行。
|
||||
'auth.admin/esignunbind',
|
||||
], true);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ use app\common\model\dept\Dept;
|
||||
use app\common\model\dept\Jobs;
|
||||
use app\common\model\doctor\Appointment;
|
||||
use app\common\model\tcm\Diagnosis;
|
||||
use app\common\service\esign\DoctorEsignIdentityService;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
@@ -247,6 +248,12 @@ class AdminLists extends BaseAdminDataLists implements ListsExtendInterface, Lis
|
||||
$adminLists[$k]['jobs_name'] = trim($jobsName, '/');
|
||||
}
|
||||
|
||||
// 当前 e签宝 应用下已绑定的签署实名,供管理员解除改绑
|
||||
$signerNames = DoctorEsignIdentityService::signerNames(array_column($adminLists, 'id'));
|
||||
foreach ($adminLists as $k => $v) {
|
||||
$adminLists[$k]['esign_signer_name'] = $signerNames[$v['id']] ?? '';
|
||||
}
|
||||
|
||||
return $adminLists;
|
||||
}
|
||||
|
||||
|
||||
@@ -528,13 +528,56 @@ final class DoctorEsignIdentityService
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Returns doctor_id => signer name for accounts bound under the current eSign application. */
|
||||
public static function signerNames(array $doctorIds): array
|
||||
{
|
||||
$doctorIds = array_values(array_filter(array_map('intval', $doctorIds)));
|
||||
if ($doctorIds === []) {
|
||||
return [];
|
||||
}
|
||||
return Db::name('doctor_esign_account')->where(self::configuredScope())
|
||||
->whereIn('doctor_id', $doctorIds)->column('doctor_name', 'doctor_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员解除某后台账号的签署身份(当前 e签宝 应用),同一实名才能改绑到另一个后台账号。
|
||||
* 已签处方保留原签署证据,不受影响。
|
||||
*/
|
||||
public static function unbind(int $doctorId): void
|
||||
{
|
||||
if ($doctorId <= 0) {
|
||||
throw new DomainException('管理员ID无效');
|
||||
}
|
||||
$scope = ['doctor_id' => $doctorId] + self::configuredScope();
|
||||
Db::transaction(static function () use ($scope): void {
|
||||
$account = Db::name('doctor_esign_account')->where($scope)->lock(true)->find();
|
||||
foreach ([self::IDENTITY_FLOW_TABLE, self::QUICK_FLOW_TABLE] as $table) {
|
||||
if (self::hasLease(Db::name($table)->where($scope)->lock(true)->find())) {
|
||||
throw new DomainException('该账号的签署身份正在处理中,请稍后再试');
|
||||
}
|
||||
}
|
||||
if (!$account) {
|
||||
throw new DomainException('该账号未绑定签署身份');
|
||||
}
|
||||
Db::name('doctor_esign_account')->where($scope)->delete();
|
||||
// 认证与快捷签授权都挂在旧签署账号上,一并清除,避免解绑后继续沿用。
|
||||
Db::name(self::IDENTITY_FLOW_TABLE)->where($scope)->delete();
|
||||
Db::name(self::QUICK_FLOW_TABLE)->where($scope)->delete();
|
||||
});
|
||||
}
|
||||
|
||||
private static function configuredScope(): array
|
||||
{
|
||||
return ['environment' => (string) Config::get('esign.environment', 'sandbox'),
|
||||
'app_id' => (string) Config::get('esign.app_id', '')];
|
||||
}
|
||||
|
||||
private static function scope(int $actor): array
|
||||
{
|
||||
if (!self::enabled()) {
|
||||
throw new DomainException('医师电子签署认证尚未启用');
|
||||
}
|
||||
return ['doctor_id' => $actor, 'environment' => (string) Config::get('esign.environment', 'sandbox'),
|
||||
'app_id' => (string) Config::get('esign.app_id', '')];
|
||||
return ['doctor_id' => $actor] + self::configuredScope();
|
||||
}
|
||||
|
||||
private static function snapshot(array $scope, bool $lock = false, string $flowTable = self::IDENTITY_FLOW_TABLE): array
|
||||
@@ -625,7 +668,14 @@ final class DoctorEsignIdentityService
|
||||
$owner = Db::name('doctor_esign_account')->where('environment', $scope['environment'])
|
||||
->where('app_id', $scope['app_id'])->where('account_id', $newAccountId)->lock(true)->value('doctor_id');
|
||||
if ($owner !== null) {
|
||||
throw new DomainException('签署账号绑定冲突,请联系管理员核实');
|
||||
// e签宝 对同一实名只签发一个签署账号;指明占用方,便于管理员在管理员列表中解除后重试。
|
||||
// 用名称+ID 而非登录账号:账号常为手机号,桌面端会屏蔽含长数字的提示。
|
||||
$holder = (string) Db::name('admin')->where('id', $owner)->value('name');
|
||||
$label = ($holder !== '' ? $holder : '已删除账号') . '(ID ' . (int) $owner . ')';
|
||||
throw new DomainException(sprintf(
|
||||
'该实名的签署账号已绑定后台账号「%s」,请管理员在「管理员」列表解除其签署身份后再确认绑定(刷脸结果 30 分钟内有效)',
|
||||
$label
|
||||
));
|
||||
}
|
||||
Db::name('doctor_esign_account')->insert($scope + [
|
||||
'account_id' => $newAccountId, 'doctor_name' => $snapshot['name'], 'create_time' => time(),
|
||||
|
||||
Reference in New Issue
Block a user