From cf2db45c6cd229858666a5e6986ff62a69cc7086 Mon Sep 17 00:00:00 2001 From: jsasg <735273025@qq.com> Date: Wed, 14 May 2025 16:25:55 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=95=B0=E6=8D=AE=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/command/DataMigration.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/command/DataMigration.php b/app/command/DataMigration.php index 3fb44b47..648ff1d3 100644 --- a/app/command/DataMigration.php +++ b/app/command/DataMigration.php @@ -51,7 +51,7 @@ class DataMigration extends Command // $this->migrateProductRelated(); // 迁移产品购买链接 - $this->migrateProductPurchaseLinks(); + // $this->migrateProductPurchaseLinks(); // 迁移文章 // $this->migrateArticle([ @@ -174,18 +174,25 @@ class DataMigration extends Command ->select() ->toArray(); + $tree = array_to_tree($category, 0, 'pid', 1); // 处理数据 - $this->handlerProductCategory(array_to_tree($category, 0, 'pid', 1), $tco_category_map); + $this->handlerProductCategory($tree, $tco_category_map); } - private function handlerProductCategory($category, $map) { + private function handlerProductCategory($category, $map, $path = []) { foreach ($category as $val) { $key = sprintf("%s_%s", $val['id'], $val['country_code']); + if ($val['pid'] == 0) { + $path = []; + } else { + if (!in_array($val['pid'], $path)) $path[] = $val['pid']; + } $item = [ 'id' => $val['id'], 'language_id' => $val['country_code'] == 'ZH' ? 1 : 2, 'unique_id' => uniqid('PRO_CATE_'), 'pid' => $val['pid'], 'name' => $val['name'], + 'path' => implode(',', $path), 'icon' => $val['icon'], 'desc' => $val['description'], 'related_tco_category' => isset($map[$key]) ? implode(',', $map[$key]) : '', @@ -195,7 +202,7 @@ class DataMigration extends Command ]; Db::name('product_category')->insert($item); if (isset($val['children'])) { - $this->handlerProductCategory($val['children'], $map); + $this->handlerProductCategory($val['children'], $map, $path); } } }