seven vor 1 Monat
Ursprung
Commit
aa164373cb

+ 3 - 4
app/Services/SyncFootballDataService.php

@@ -53,11 +53,10 @@ public static function syncCountry()
 
         // 先将所有国家/地区设为无效
         Country::query()->update(['status' => Country::STATUS_NO]);
-        
         foreach ($response as $item) {
             // 使用 firstOrCreate 简化代码
             $country = Country::firstOrCreate(
-                ['code' => $item['code']],
+                ['name' => $item['name']],
                 [
                     'name' => $item['name'],
                     'code' => $item['code'],
@@ -69,13 +68,13 @@ public static function syncCountry()
             // 如果已存在,更新状态和其他字段
             if (!$country->wasRecentlyCreated) {
                 $country->update([
-                    'name' => $item['name'],
+                    'code' => $item['code'],
                     'flag' => $item['flag'],
                     'status' => Country::STATUS_YES
                 ]);
             }
         }
-
+        
         return $result;
     }
 }

+ 3 - 3
database/migrations/2026_03_04_111111_create_countries_table.php

@@ -14,9 +14,9 @@ public function up(): void
     {
         Schema::create('countries', function (Blueprint $table) {
             $table->id();
-            $table->string('name', 100)->comment('国家/地区名称');
-            $table->string('code', 2)->unique()->comment('国家/地区代码(2位字母)');
-            $table->string('flag', 255)->comment('国旗图标URL');
+            $table->string('name', 100)->unique()->comment('国家/地区名称');
+            $table->string('code', 25)->nullable()->comment('国家/地区代码');
+            $table->string('flag', 255)->nullable()->comment('国旗图标URL');
             $table->integer('status')->nullable()->default(1)->comment('状态: 1-正常, 0-禁用');
             $table->timestamps();
             $table->comment('国家/地区表');