diff --git a/admin/src/api/tcm.ts b/admin/src/api/tcm.ts index a8231c40..34204da8 100644 --- a/admin/src/api/tcm.ts +++ b/admin/src/api/tcm.ts @@ -319,6 +319,11 @@ export function prescriptionEdit(params: any) { return request.post({ url: '/tcm.prescription/edit', params }) } +/** 仅修正处方笺患者姓名与手机号(不改审核状态),写入业务订单日志表 */ +export function prescriptionPatchPatient(params: { id: number; patient_name: string; phone: string }) { + return request.post({ url: '/tcm.prescription/patchPatient', params }) +} + // 删除处方 export function prescriptionDelete(params: { id: number }) { return request.post({ url: '/tcm.prescription/delete', params }) diff --git a/admin/src/views/consumer/prescription/index.vue b/admin/src/views/consumer/prescription/index.vue index 81a9c14f..da4aa206 100644 --- a/admin/src/views/consumer/prescription/index.vue +++ b/admin/src/views/consumer/prescription/index.vue @@ -216,6 +216,15 @@ 查看 + + 改姓名手机 + + + + + + #{{ patchPatientForm.id || '—' }} + + + + + + + + + + 仅更新处方表 patient_name、phone,不改变审核状态;记录写入业务订单操作日志(有关联订单时可在此订单日志中查看)。 + + + 取消 + + 保存 + + + + () +const patchPatientForm = reactive({ + id: 0, + patient_name: '', + phone: '' +}) +const patchPatientRules: FormRules = { + patient_name: [{ required: true, message: '请输入患者姓名', trigger: 'blur' }], + phone: [{ required: true, message: '请输入手机号', trigger: 'blur' }] +} + +function openPatchPatientDialog(row: Record) { + patchPatientForm.id = Number(row.id) || 0 + patchPatientForm.patient_name = String(row.patient_name ?? '').trim() + patchPatientForm.phone = String(row.phone ?? '').trim() + patchPatientVisible.value = true +} + +function resetPatchPatientForm() { + patchPatientForm.id = 0 + patchPatientForm.patient_name = '' + patchPatientForm.phone = '' + patchPatientFormRef.value?.clearValidate() +} + +async function submitPatchPatient() { + const form = patchPatientFormRef.value + if (!form) return + try { + await form.validate() + } catch { + return + } + patchPatientSubmitLoading.value = true + try { + await prescriptionPatchPatient({ + id: patchPatientForm.id, + patient_name: patchPatientForm.patient_name.trim(), + phone: patchPatientForm.phone.trim() + }) + feedback.msgSuccess('已保存') + patchPatientVisible.value = false + getLists() + } catch (e: unknown) { + const msg = e && typeof e === 'object' && 'msg' in e ? String((e as { msg?: string }).msg) : '' + feedback.msgError(msg || '保存失败') + } finally { + patchPatientSubmitLoading.value = false + } +} + /** 从消费者处方创建订单 */ const createOrderVisible = ref(false) /** 创建订单分步向导:0 患者与收货 / 1 服务与支付单 / 2 金额与确认 */ diff --git a/server/app/adminapi/controller/tcm/PrescriptionController.php b/server/app/adminapi/controller/tcm/PrescriptionController.php index dfca9595..b8846c8c 100644 --- a/server/app/adminapi/controller/tcm/PrescriptionController.php +++ b/server/app/adminapi/controller/tcm/PrescriptionController.php @@ -48,6 +48,26 @@ class PrescriptionController extends BaseAdminController return $this->success('编辑成功'); } + /** + * @notes 修正处方患者姓名手机号 + */ + public function patchPatient() + { + $params = (new PrescriptionValidate())->post()->goCheck('patchPatient'); + $ok = PrescriptionLogic::patchPatientContact( + (int) $params['id'], + (string) $params['patient_name'], + (string) $params['phone'], + (int) $this->adminId, + $this->adminInfo + ); + if (!$ok) { + return $this->fail(PrescriptionLogic::getError()); + } + + return $this->success('已更新'); + } + /** * @notes 删除处方 */ diff --git a/server/app/adminapi/logic/tcm/PrescriptionLogic.php b/server/app/adminapi/logic/tcm/PrescriptionLogic.php index 78b1c708..c89a4729 100644 --- a/server/app/adminapi/logic/tcm/PrescriptionLogic.php +++ b/server/app/adminapi/logic/tcm/PrescriptionLogic.php @@ -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; + } + } + /** * 删除处方 */ diff --git a/server/app/adminapi/logic/tcm/PrescriptionOrderLogic.php b/server/app/adminapi/logic/tcm/PrescriptionOrderLogic.php index b23e518e..efca6310 100644 --- a/server/app/adminapi/logic/tcm/PrescriptionOrderLogic.php +++ b/server/app/adminapi/logic/tcm/PrescriptionOrderLogic.php @@ -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); + } } diff --git a/server/app/adminapi/validate/tcm/PrescriptionValidate.php b/server/app/adminapi/validate/tcm/PrescriptionValidate.php index e7642750..8f0ef7eb 100644 --- a/server/app/adminapi/validate/tcm/PrescriptionValidate.php +++ b/server/app/adminapi/validate/tcm/PrescriptionValidate.php @@ -14,6 +14,7 @@ class PrescriptionValidate extends BaseValidate 'appointment_id' => 'number', 'dosage_bag_count' => 'integer|between:1,5', 'patient_name' => 'require', + 'phone' => 'require|max:20', 'clinical_diagnosis' => 'require', 'herbs' => 'require|array', 'action' => 'require|in:approve,reject', @@ -24,6 +25,8 @@ class PrescriptionValidate extends BaseValidate 'dosage_bag_count.integer' => '用量袋数必须为整数', 'dosage_bag_count.between' => '用量袋数必须在1到5袋之间', 'patient_name.require' => '患者姓名不能为空', + 'phone.require' => '手机号不能为空', + 'phone.max' => '手机号过长', 'clinical_diagnosis.require' => '临床诊断不能为空', 'herbs.require' => '请添加中药', ]; @@ -63,6 +66,11 @@ class PrescriptionValidate extends BaseValidate return $this->only(['id']); } + public function scenePatchPatient() + { + return $this->only(['id', 'patient_name', 'phone']); + } + public function sceneAudit() { return $this->only(['id', 'action', 'remark']); diff --git a/server/sql/1.9.20260516/add_prescription_patch_patient_contact_menu.sql b/server/sql/1.9.20260516/add_prescription_patch_patient_contact_menu.sql new file mode 100644 index 00000000..bd255dd4 --- /dev/null +++ b/server/sql/1.9.20260516/add_prescription_patch_patient_contact_menu.sql @@ -0,0 +1,24 @@ +-- 消费者处方列表:修正处方笺姓名 / 手机号(接口 tcm.prescription/patchPatient) +-- 执行前确认表前缀为 zyt_;若已有相同 perms 则跳过。 + +SET @cf_rx_menu_id := ( + SELECT id FROM zyt_system_menu + WHERE type = 'C' + AND ( + component = 'consumer/prescription/index' + OR component LIKE '%consumer/prescription/index%' + ) + LIMIT 1 +); + +INSERT INTO zyt_system_menu ( + pid, type, name, icon, sort, perms, paths, component, + selected, params, is_cache, is_show, is_disable, create_time, update_time +) +SELECT + @cf_rx_menu_id, 'A', '修正处方患者姓名手机', '', 53, + 'tcm.prescription/patchPatient', '', '', + '', '', 0, 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP() +FROM DUAL +WHERE @cf_rx_menu_id IS NOT NULL + AND NOT EXISTS (SELECT 1 FROM zyt_system_menu WHERE perms = 'tcm.prescription/patchPatient');
+ 仅更新处方表 patient_name、phone,不改变审核状态;记录写入业务订单操作日志(有关联订单时可在此订单日志中查看)。 +