From 145045b34bf1bd7bc71ce4dc687dd1f1c24e0db1 Mon Sep 17 00:00:00 2001 From: haomingming Date: Fri, 26 Dec 2025 14:10:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=AE=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/PatientOrderService.php | 34 ++++++++-------------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/app/Services/PatientOrderService.php b/app/Services/PatientOrderService.php index 437071c..3264eee 100644 --- a/app/Services/PatientOrderService.php +++ b/app/Services/PatientOrderService.php @@ -1998,26 +1998,11 @@ class PatientOrderService extends BaseService $params['is_delete'] = 0; $order_prescription = OrderPrescription::getWithPage($params, ['*'], $page, $per_page); - // 创建新的数据副本,初始化为空,保留分页信息 - $order_prescription_new = []; - if (!empty($order_prescription)) { - // 复制分页信息等非data字段 - foreach ($order_prescription as $key => $value) { - if ($key !== 'data') { - $order_prescription_new[$key] = $value; - } - } - $order_prescription_new['data'] = []; - } - if (!empty($order_prescription['data'])) { - foreach ($order_prescription['data'] as $item) { - // 复制原始item数据 - $new_item = $item; - + foreach ($order_prescription['data'] as &$item) { //处理抄方情况 $params = array(); - $params['order_inquiry_id'] = $new_item['order_inquiry_id']; + $params['order_inquiry_id'] = $item['order_inquiry_id']; $OrderInquiry = OrderInquiry::getOne($params); if (!empty($OrderInquiry)) { //为抄方订单 @@ -2028,22 +2013,23 @@ class PatientOrderService extends BaseService $fields = ['doctor_id','user_name','doctor_title']; $UserDoctor = UserDoctor::getOne($params, $fields); if (!empty($UserDoctor)) { - $new_item['UserDoctor'] = $UserDoctor; + // 使用 setRelation 方法覆盖已加载的关联数据 + $item->setRelation('UserDoctor', $UserDoctor); } } } - if (!empty($new_item['UserDoctor'])) { - $new_item['UserDoctor']['doctor_title'] = DoctorTitleCode::getMessage($new_item['UserDoctor']['doctor_title']); + // 获取 UserDoctor 关联对象并修改 doctor_title + $userDoctor = $item->getRelation('UserDoctor'); + if (!empty($userDoctor)) { + // 修改模型属性 + $userDoctor->doctor_title = DoctorTitleCode::getMessage($userDoctor->doctor_title); } - - // 将处理后的数据添加到新数组中 - $order_prescription_new['data'][] = $new_item; } } - return success($order_prescription_new); + return success($order_prescription); } catch (\Throwable $e) { Log::getInstance("PatientOrderService-getPatientPrescriptionOrderList")->error("获取处方订单列表异常", [ 'message' => $e->getMessage(),