From 2a9c3332f74b7888433f77293588b1bf629066ef Mon Sep 17 00:00:00 2001 From: jsasg <735273025@qq.com> Date: Fri, 8 Aug 2025 09:18:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BA=A7=E5=93=81?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E5=88=86=E7=B1=BB=E6=A0=91=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/v1/ProductTcoCategory.php | 9 +++++---- app/common.php | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/admin/controller/v1/ProductTcoCategory.php b/app/admin/controller/v1/ProductTcoCategory.php index d54f4fbc..aa272616 100644 --- a/app/admin/controller/v1/ProductTcoCategory.php +++ b/app/admin/controller/v1/ProductTcoCategory.php @@ -16,8 +16,9 @@ class ProductTcoCategory $param = request()->param(['name']); $categorys = ProductTcoCategoryModel::field([ - 'tco_id' => 'id', - 'tco_pid' => 'pid', + 'id', + 'tco_id', + 'tco_pid', 'name', ]) ->withSearch(['name'], [ @@ -25,10 +26,10 @@ class ProductTcoCategory ]) ->language(request()->lang_id) ->enabled() - ->order(['id' => 'asc']) + ->order(['tco_id' => 'asc']) ->select() ->toArray(); - return success('获取成功', array_to_tree($categorys, 0, 'pid', false)); + return success('获取成功', array_to_tree($categorys, 0, 'tco_pid', false, true, 'tco_id')); } } diff --git a/app/common.php b/app/common.php index f15ba098..e711188e 100644 --- a/app/common.php +++ b/app/common.php @@ -80,7 +80,7 @@ if (!function_exists('array_to_tree')) { * @param bool $keep_pid 是否保留pid * @return array */ - function array_to_tree(array $data, int $pid, string $with = 'pid', int|bool $level = 1, bool $keep_pid = true) + function array_to_tree(array $data, int $pid, string $with = 'pid', int|bool $level = 1, bool $keep_pid = true, $with_ref = 'id') { $ret = []; foreach ($data as $item) { @@ -93,7 +93,7 @@ if (!function_exists('array_to_tree')) { if ($keep_pid === false) { unset($item[$with]); } - $children = array_to_tree($data, $item['id'], $with, $lv, $keep_pid); + $children = array_to_tree($data, $item[$with_ref], $with, $lv, $keep_pid, $with_ref); if ($children) { $item['children'] = $children; }