chengwl hace 4 días
padre
commit
db9376346f

+ 8 - 6
app/Console/Commands/MigrateAsteriaCustomers.php

@@ -820,17 +820,19 @@ class MigrateAsteriaCustomers extends Command
         };
     }
 
-    private function mapCustomerSource(mixed $value): ?int
+    /**
+     * Magento 1 stores `source` as a free-text varchar attribute (e.g. "popup"),
+     * so the raw value is kept as-is rather than coerced to a code.
+     */
+    private function mapCustomerSource(mixed $value): ?string
     {
-        if ($value === null || $value === '') {
+        if (! is_scalar($value)) {
             return null;
         }
 
-        if (! is_numeric($value)) {
-            return null;
-        }
+        $value = trim((string) $value);
 
-        return (int) $value;
+        return $value === '' ? null : mb_substr($value, 0, 64);
     }
 
     private function mapDate(mixed $value): ?string

+ 22 - 0
database/migrations/2026_09_03_101500_change_customer_source_to_string_on_customers_table.php

@@ -0,0 +1,22 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    public function up(): void
+    {
+        Schema::table('customers', function (Blueprint $table) {
+            $table->string('customer_source', 64)->nullable()->change();
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::table('customers', function (Blueprint $table) {
+            $table->unsignedInteger('customer_source')->nullable()->change();
+        });
+    }
+};

+ 2 - 2
docs/asteria-migration.md

@@ -53,7 +53,7 @@ php artisan migrate
 | 表 | 幂等列 | 迁移文件 |
 |---|---|---|
 | `products` | `migrated_from_asteria_id`(unique);SKU 仍唯一 | `database/migrations/2026_09_01_151700_add_asteria_migration_column_to_products_table.php` |
-| `customers` | `migrated_from_asteria_id`(unique),另有 `legacy_password`、`customer_source` | `database/migrations/2026_08_20_163200_add_asteria_migration_columns_to_customers_table.php`、`database/migrations/2026_09_02_144100_add_customer_source_to_customers_table.php` |
+| `customers` | `migrated_from_asteria_id`(unique),另有 `legacy_password`、`customer_source` | `database/migrations/2026_08_20_163200_add_asteria_migration_columns_to_customers_table.php`、`database/migrations/2026_09_02_144100_add_customer_source_to_customers_table.php`、`database/migrations/2026_09_03_101500_change_customer_source_to_string_on_customers_table.php` |
 | `orders` | `migrated_from_asteria_id`(unique) | `database/migrations/2026_08_25_143200_add_asteria_migration_column_to_orders_table.php` |
 | `product_reviews` | `migrated_from_asteria_id`(unique) | 评论命令在缺列时会提示,也可交互自动 `ALTER TABLE` |
 
@@ -114,7 +114,7 @@ php artisan customers:migrate-asteria --reset-progress
 - 手机号与现有用户冲突:新用户 `phone` 置空。
 - 地址按 `addresses.additional.asteria_address_id` 去重;街道换行压成 `, `。
 - 订阅:Magento `newsletter_subscriber.subscriber_status = 1` 为已订阅,写入 `customers.subscribed_to_news_letter`,并按邮箱幂等写入 `subscribers_list`。已退订(status=3 等)的**注册用户**会写成未订阅并保留 `subscribers_list` 记录;无账号的游客订阅只导入已订阅邮箱。无 `newsletter_subscriber` 表时跳过,不影响用户导入。重复执行会回填已迁用户的订阅状态。
-- `customer_source`:从 Magento 客户属性 `source` 写入。不迁 `source_url`。已迁用户再跑(`--reset-progress`)会按 Magento 值回填。
+- `customer_source`:从 Magento 客户属性 `source` 写入。该属性在 Magento 1 里是 varchar 自由文本(现网只有 `popup` 一种值,且仅 97 个客户有值),因此原样存字符串,不做数字编码转换;超过 64 字符会截断。不迁 `source_url`。已迁用户再跑(`--reset-progress`)会按 Magento 值回填。
 
 进度缓存:`migrate_asteria_customers_last_id`(30 天)。