generated from liutk/owl-admin-base
amis地区数据
parent
a1de082c21
commit
00bea7cb32
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
class AmisRegionSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Seed the application's database.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
// Amis 省市区转换
|
||||||
|
// https://github.com/baidu/amis/blob/master/packages/amis-ui/src/components/CityDB.ts
|
||||||
|
|
||||||
|
// 省份
|
||||||
|
$province = [];
|
||||||
|
// 城市
|
||||||
|
$city = [];
|
||||||
|
// 地区
|
||||||
|
$district = [];
|
||||||
|
|
||||||
|
// 省市区数据
|
||||||
|
$region = file_get_contents(database_path('data/region.json'));
|
||||||
|
|
||||||
|
foreach (json_decode($region, true) as $code => $name) {
|
||||||
|
if ($code % 10000 === 0) {
|
||||||
|
$province[] = ['code' => $code, 'name' => $name];
|
||||||
|
} elseif ($code % 100 === 0) {
|
||||||
|
$provinceCode = $code - ($code % 10000);
|
||||||
|
$city[$provinceCode][] = ['code' => $code, 'name' => $name];
|
||||||
|
} else {
|
||||||
|
$provinceCode = $code - ($code % 10000);
|
||||||
|
$cityCode = $code - ($code % 100);
|
||||||
|
$district[$provinceCode][$cityCode][] = ['code' => $code, 'name' => $name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = json_encode(compact('province', 'city', 'district'), JSON_UNESCAPED_UNICODE);
|
||||||
|
|
||||||
|
Storage::disk('public')->put('region.json', $data);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue