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