From d94792b998cb7935b1409d11f45b7343cf7fb739 Mon Sep 17 00:00:00 2001 From: jsasg <735273025@qq.com> Date: Mon, 19 May 2025 14:35:56 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=95=B0=E6=8D=AE=E8=BF=81?= =?UTF-8?q?=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/command/DataMigration.php | 49 +++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/app/command/DataMigration.php b/app/command/DataMigration.php index 648ff1d3..8705efc4 100644 --- a/app/command/DataMigration.php +++ b/app/command/DataMigration.php @@ -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;