refactor: 数据迁移程序

This commit is contained in:
2025-05-14 16:25:55 +08:00
parent d80a2abe14
commit cf2db45c6c

View File

@@ -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);
}
}
}