From a37175b54e1c0592deb6d05a06f63c2f02487b2b Mon Sep 17 00:00:00 2001 From: "zhangf@suq.cn" Date: Tue, 9 Dec 2025 18:29:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(distillation):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=AF=BB=E5=8F=96=E9=80=BB=E8=BE=91=E5=B9=B6?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=BD=A2=E5=BC=8F?= =?UTF-8?q?=E7=9A=84=E7=BF=BB=E8=AF=91=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改变量名 `$user_group` 为 `$distillationWords` 以提高可读性 - 移除不存在数据时返回空数组的逻辑,改为抛出异常 - 将关联的 `trans` 数据转换为逗号分隔的字符串格式 `trans_str` - 在返回结果中移除原始的 `trans` 字段 - 确保返回的数据结构一致性和清晰度 --- app/service/DistillationWordService.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/service/DistillationWordService.php b/app/service/DistillationWordService.php index dc5ae44..19b7e54 100644 --- a/app/service/DistillationWordService.php +++ b/app/service/DistillationWordService.php @@ -138,11 +138,14 @@ class DistillationWordService extends BaseService */ public function readData(mixed $id): array { - $user_group = $this->dao->get(['id' => $id], ['*'], ['trans', 'expand']); - if (empty($user_group)) { + $distillationWords = $this->dao->get(['id' => $id], ['*'], ['trans']); + if (empty($distillationWords)) { throw new ApiException('数据不存在'); } - return $user_group->toArray(); + $data = $distillationWords->toArray(); + $data['trans_str'] = implode(',', array_column($data['trans'], 'name')); + unset($data['trans']); + return $data; } /**