This commit is contained in:
Your Name
2026-05-18 09:42:11 +08:00
parent 15b4339c90
commit d79db88349
7 changed files with 250 additions and 1 deletions
@@ -436,6 +436,88 @@ class PrescriptionLogic
}
}
/**
* 仅修正处方笺展示用患者姓名与手机号(zyt_tcm_prescription),不改变审核状态与其它字段
*/
public static function patchPatientContact(int $rxId, string $patientName, string $phone, int $adminId, array $adminInfo): bool
{
self::$error = '';
$prescription = Prescription::find($rxId);
if (!$prescription) {
self::setError('处方不存在');
return false;
}
if (!self::canViewPrescription($prescription, $adminId, $adminInfo)) {
self::setError('无权限修改此处方');
return false;
}
$patientName = trim($patientName);
$phone = trim($phone);
if ($patientName === '') {
self::setError('患者姓名不能为空');
return false;
}
if (mb_strlen($patientName) > 50) {
self::setError('患者姓名过长');
return false;
}
if ($phone === '') {
self::setError('手机号不能为空');
return false;
}
if (strlen($phone) > 20) {
self::setError('手机号过长');
return false;
}
$oldName = trim((string) ($prescription->patient_name ?? ''));
$oldPhone = trim((string) ($prescription->phone ?? ''));
if ($oldName === $patientName && $oldPhone === $phone) {
self::setError('信息未变更');
return false;
}
try {
$prescription->save([
'patient_name' => $patientName,
'phone' => $phone,
]);
$latestPo = PrescriptionOrder::where('prescription_id', $rxId)
->whereNull('delete_time')
->order('id', 'desc')
->find();
$logOrderId = $latestPo ? (int) $latestPo->id : 0;
$nameFrom = $oldName === '' ? '—' : $oldName;
$phoneFrom = $oldPhone === '' ? '—' : $oldPhone;
$summary = sprintf(
'处方 #%d:患者姓名「%s」→「%s」,手机「%s」→「%s」',
$rxId,
$nameFrom,
$patientName,
$phoneFrom,
$phone
);
PrescriptionOrderLogic::appendRxPatientPatchLog($logOrderId, $adminId, $adminInfo, $summary);
return true;
} catch (\Throwable $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* 删除处方
*/
@@ -1097,7 +1097,7 @@ class PrescriptionOrderLogic
$phoneFrom,
$phone
);
self::writeLog($prescriptionOrderId, $adminId, $adminInfo, 'patch_rx_patient', $summary);
self::appendRxPatientPatchLog($prescriptionOrderId, $adminId, $adminInfo, $summary);
return true;
} catch (\Exception $e) {
@@ -3248,4 +3248,14 @@ class PrescriptionOrderLogic
// 忽略日志写入错误
}
}
/**
* 处方患者姓名/手机号修正日志(写入 zyt_tcm_prescription_order_log,与 patchPrescriptionPatient 同源)
*
* @param int $prescriptionOrderId 无关联订单时可传 0(若库表禁止则可能静默失败)
*/
public static function appendRxPatientPatchLog(int $prescriptionOrderId, int $adminId, array $adminInfo, string $summary): void
{
self::writeLog($prescriptionOrderId, $adminId, $adminInfo, 'patch_rx_patient', $summary);
}
}