refactor: 数据迁移程序
This commit is contained in:
@@ -51,7 +51,7 @@ class DataMigration extends Command
|
|||||||
// $this->migrateProductRelated();
|
// $this->migrateProductRelated();
|
||||||
|
|
||||||
// 迁移产品购买链接
|
// 迁移产品购买链接
|
||||||
$this->migrateProductPurchaseLinks();
|
// $this->migrateProductPurchaseLinks();
|
||||||
|
|
||||||
// 迁移文章
|
// 迁移文章
|
||||||
// $this->migrateArticle([
|
// $this->migrateArticle([
|
||||||
@@ -174,18 +174,25 @@ class DataMigration extends Command
|
|||||||
->select()
|
->select()
|
||||||
->toArray();
|
->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) {
|
foreach ($category as $val) {
|
||||||
$key = sprintf("%s_%s", $val['id'], $val['country_code']);
|
$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 = [
|
$item = [
|
||||||
'id' => $val['id'],
|
'id' => $val['id'],
|
||||||
'language_id' => $val['country_code'] == 'ZH' ? 1 : 2,
|
'language_id' => $val['country_code'] == 'ZH' ? 1 : 2,
|
||||||
'unique_id' => uniqid('PRO_CATE_'),
|
'unique_id' => uniqid('PRO_CATE_'),
|
||||||
'pid' => $val['pid'],
|
'pid' => $val['pid'],
|
||||||
'name' => $val['name'],
|
'name' => $val['name'],
|
||||||
|
'path' => implode(',', $path),
|
||||||
'icon' => $val['icon'],
|
'icon' => $val['icon'],
|
||||||
'desc' => $val['description'],
|
'desc' => $val['description'],
|
||||||
'related_tco_category' => isset($map[$key]) ? implode(',', $map[$key]) : '',
|
'related_tco_category' => isset($map[$key]) ? implode(',', $map[$key]) : '',
|
||||||
@@ -195,7 +202,7 @@ class DataMigration extends Command
|
|||||||
];
|
];
|
||||||
Db::name('product_category')->insert($item);
|
Db::name('product_category')->insert($item);
|
||||||
if (isset($val['children'])) {
|
if (isset($val['children'])) {
|
||||||
$this->handlerProductCategory($val['children'], $map);
|
$this->handlerProductCategory($val['children'], $map, $path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user