refactor: 数据迁移
This commit is contained in:
@@ -47,6 +47,12 @@ class DataMigration extends Command
|
||||
// 迁移产品
|
||||
// $this->migrateProduct();
|
||||
|
||||
// $files = $this->getLocalImages('/var/www/html/orico-official-website/public/migrate_temp_images');
|
||||
// print_r($files);
|
||||
// foreach ($files as $file) {
|
||||
// unlink($file);
|
||||
// }
|
||||
|
||||
// 迁移产品关联产品数据
|
||||
// $this->migrateProductRelated();
|
||||
|
||||
@@ -128,6 +134,31 @@ class DataMigration extends Command
|
||||
}
|
||||
}
|
||||
|
||||
// 获取本地图片
|
||||
private function getLocalImages($path)
|
||||
{
|
||||
$files = [];
|
||||
$dir = dir($path);
|
||||
while (false !== ($entry = $dir->read())) {
|
||||
if ($entry == '.' || $entry == '..') {
|
||||
continue;
|
||||
}
|
||||
$file = $path . '/' . $entry;
|
||||
if (is_dir($file)) {
|
||||
$files = array_merge($files, $this->getLocalImages($file));
|
||||
} else {
|
||||
$info = stat($file);
|
||||
if ($info['size'] == 0) {
|
||||
$files[] = $file;
|
||||
}
|
||||
// if (!is_valid_image($file)) {
|
||||
// $files[] = $file;
|
||||
// }
|
||||
}
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
// 迁移tco产品分类
|
||||
private function productTcoCategory()
|
||||
{
|
||||
@@ -266,7 +297,7 @@ class DataMigration extends Command
|
||||
|
||||
$products = $old_db->name('product')
|
||||
->where('country_code', 'in', ['ZH', 'US'])
|
||||
->where('id', '>', 0)
|
||||
->where('id', '>', 15789)
|
||||
->order(['id' => 'asc'])
|
||||
->cursor();
|
||||
|
||||
@@ -416,6 +447,7 @@ class DataMigration extends Command
|
||||
if ($k == 'Color') $k = '颜色';
|
||||
$attr_value = '/static/common/images/colors/' . $at . '.png';
|
||||
}
|
||||
$images[$pkey]['color'] = $at;
|
||||
$images[$pkey]['attrs'][] = [
|
||||
'attr_id' => $attrs_map[$v['country_code']][$k],
|
||||
'attr_value' => $attr_value,
|
||||
@@ -458,7 +490,7 @@ class DataMigration extends Command
|
||||
|
||||
$two_images = $old_db->name('product_two_img')
|
||||
->where('product_id', '=', $v['id'])
|
||||
->where('country_code', '=', $v['country_code'])
|
||||
// ->where('country_code', '=', $v['country_code'])
|
||||
->where('stat', '=', 0)
|
||||
->order(['id' => 'asc'])
|
||||
->select();
|
||||
@@ -494,6 +526,19 @@ class DataMigration extends Command
|
||||
$temp_images = [];
|
||||
foreach ($skus as $idx => $sku) {
|
||||
$skus[$idx]['product_id'] = $id;
|
||||
foreach ($images as $im) {
|
||||
if (isset($im['color'])) {
|
||||
if (md5($im['color']) == $sku['pkey']) {
|
||||
$skus[$idx]['sku'] = $im['sku']??null;
|
||||
$skus[$idx]['photo_album'] = $im['photo_album']??null;
|
||||
if (!empty($im['attrs'])) {
|
||||
$skus[$idx]['attrs'] = $im['attrs'];
|
||||
}
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($images[$sku['pkey']])) {
|
||||
$skus[$idx]['sku'] = $images[$sku['pkey']]['sku']??null;
|
||||
$skus[$idx]['photo_album'] = $images[$sku['pkey']]['photo_album']??null;
|
||||
|
||||
Reference in New Issue
Block a user