更新
This commit is contained in:
@@ -13,6 +13,7 @@ use app\common\model\tcm\Prescription;
|
||||
use app\common\model\tcm\PrescriptionOrder;
|
||||
use app\common\model\tcm\PrescriptionOrderLog;
|
||||
use app\common\model\tcm\PrescriptionOrderPayOrder;
|
||||
use app\common\model\doctor\Appointment;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\service\ExpressTrackService;
|
||||
use app\common\service\gancao\GancaoScmRecipelService;
|
||||
@@ -706,9 +707,176 @@ class PrescriptionOrderLogic
|
||||
}
|
||||
$arr['diagnosis_creator_dept_path'] = $deptPath;
|
||||
|
||||
// 挂号预约摘要:优先处方 appointment_id;否则按诊单 id 匹配预约表 patient_id(诊单)
|
||||
$arr['linked_appointment'] = null;
|
||||
$rxApptId = 0;
|
||||
if (isset($arr['prescription']) && is_array($arr['prescription'])) {
|
||||
$rxApptId = (int) ($arr['prescription']['appointment_id'] ?? 0);
|
||||
}
|
||||
$resolvedApptId = $rxApptId;
|
||||
if ($resolvedApptId <= 0 && $diagIdForMeta > 0) {
|
||||
$apFallback = Appointment::where('patient_id', $diagIdForMeta)->order('id', 'desc')->find();
|
||||
if ($apFallback !== null) {
|
||||
$resolvedApptId = (int) $apFallback->id;
|
||||
}
|
||||
}
|
||||
if ($resolvedApptId > 0) {
|
||||
$brief = self::buildAppointmentBrief($resolvedApptId);
|
||||
if ($brief !== null) {
|
||||
$brief['resolved_from'] = $rxApptId === $resolvedApptId ? 'prescription' : 'diagnosis';
|
||||
$arr['linked_appointment'] = $brief;
|
||||
}
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务订单详情场景:仅更新关联处方的患者姓名与手机号(不重置消费者处方审核、不改变其它处方字段)
|
||||
*/
|
||||
public static function patchPrescriptionPatient(
|
||||
int $prescriptionOrderId,
|
||||
string $patientName,
|
||||
string $phone,
|
||||
int $adminId,
|
||||
array $adminInfo
|
||||
): bool {
|
||||
self::$error = '';
|
||||
$order = PrescriptionOrder::where('id', $prescriptionOrderId)->whereNull('delete_time')->find();
|
||||
if (!$order) {
|
||||
self::setError('订单不存在');
|
||||
|
||||
return false;
|
||||
}
|
||||
if (!self::canAccessOrder($order, $adminId, $adminInfo)) {
|
||||
self::setError('无权限操作');
|
||||
|
||||
return false;
|
||||
}
|
||||
$rxId = (int) ($order->prescription_id ?? 0);
|
||||
if ($rxId <= 0) {
|
||||
self::setError('该订单未关联处方');
|
||||
|
||||
return false;
|
||||
}
|
||||
$rx = Prescription::where('id', $rxId)->whereNull('delete_time')->find();
|
||||
if (!$rx) {
|
||||
self::setError('处方不存在');
|
||||
|
||||
return false;
|
||||
}
|
||||
if (!PrescriptionLogic::canViewPrescription($rx, $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) ($rx->patient_name ?? ''));
|
||||
$oldPhone = trim((string) ($rx->phone ?? ''));
|
||||
|
||||
try {
|
||||
$rx->save([
|
||||
'patient_name' => $patientName,
|
||||
'phone' => $phone,
|
||||
]);
|
||||
|
||||
$nameFrom = $oldName === '' ? '—' : $oldName;
|
||||
$phoneFrom = $oldPhone === '' ? '—' : $oldPhone;
|
||||
$summary = sprintf(
|
||||
'关联处方 #%d:患者姓名「%s」→「%s」,手机「%s」→「%s」',
|
||||
$rxId,
|
||||
$nameFrom,
|
||||
$patientName,
|
||||
$phoneFrom,
|
||||
$phone
|
||||
);
|
||||
self::writeLog($prescriptionOrderId, $adminId, $adminInfo, 'patch_rx_patient', $summary);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 挂号预约简要信息(业务订单详情展示)
|
||||
*
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
private static function buildAppointmentBrief(int $appointmentId): ?array
|
||||
{
|
||||
if ($appointmentId <= 0) {
|
||||
return null;
|
||||
}
|
||||
$ap = Appointment::find($appointmentId);
|
||||
if ($ap === null) {
|
||||
return null;
|
||||
}
|
||||
$row = $ap->toArray();
|
||||
$doctorName = '';
|
||||
$did = (int) ($row['doctor_id'] ?? 0);
|
||||
if ($did > 0) {
|
||||
$doctorName = (string) (Admin::where('id', $did)->value('name') ?? '');
|
||||
}
|
||||
$statusMap = [
|
||||
1 => '已预约',
|
||||
2 => '已取消',
|
||||
3 => '已完成',
|
||||
4 => '已过号',
|
||||
];
|
||||
$typeMap = [
|
||||
'video' => '视频问诊',
|
||||
'text' => '图文问诊',
|
||||
'phone' => '电话问诊',
|
||||
];
|
||||
$periodRaw = (string) ($row['period'] ?? '');
|
||||
$period = $periodRaw === 'afternoon' ? '下午' : ($periodRaw === 'morning' ? '上午' : $periodRaw);
|
||||
$timePart = (string) ($row['appointment_time'] ?? '');
|
||||
if (strlen($timePart) > 5) {
|
||||
$timePart = substr($timePart, 0, 5);
|
||||
}
|
||||
$status = (int) ($row['status'] ?? 0);
|
||||
$atype = (string) ($row['appointment_type'] ?? '');
|
||||
|
||||
return [
|
||||
'id' => $appointmentId,
|
||||
'appointment_date' => (string) ($row['appointment_date'] ?? ''),
|
||||
'period' => $period,
|
||||
'appointment_time' => $timePart,
|
||||
'appointment_type' => $atype,
|
||||
'appointment_type_desc' => $typeMap[$atype] ?? '未知',
|
||||
'status' => $status,
|
||||
'status_desc' => $statusMap[$status] ?? '未知',
|
||||
'doctor_name' => $doctorName,
|
||||
'channel_source' => (string) ($row['channel_source'] ?? ''),
|
||||
'remark' => (string) ($row['remark'] ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 物流轨迹(顺丰/京东等,优先快递100;未配置密钥时返回官网链接)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user