<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCitiesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('cities', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('province_id')->index()->comment('省份');
            $table->string('name',50)->unique()->comment('名称');
            $table->timestamps();

            //外键
//            $table->foreign('province_id')->references('id')->on('provinces');      //省份
        });
        $Shanxi=['西安','宝鸡','咸阳','铜川','渭南','延安','榆林','汉中','安康','商洛'];
        $Gansu=['兰州','嘉峪关','金昌','白银','天水','武威','张掖','平凉','酒泉','庆阳','定西','陇南','临夏','合作'];
        $Ningxia=['银川','石嘴山','吴忠','固原','中卫'];
        $Qinghai=['西宁','平安县','门源县','同仁县','共和县','玛訫县','玉树县','格尔木'];
        $Xinjiang=['乌鲁木齐','克拉玛依','吐鲁番','哈密','昌吉州','博乐市','库尔勒','阿克苏市','阿图什市','喀什市','和田市','伊宁市','塔城市','阿尔泰市'];
        $Jiangsu=['南京','常熟','无锡','徐州','常州','苏州','南通','连云港','淮安','盐城','扬州','镇江','泰州','宿迁'];
        $ZheJiang=['杭州','宁波','温州','嘉兴','湖州','绍兴','金华','衢州','舟山','台州','丽水'];
        $Anhui=['合肥','芜湖','蚌埠','淮南','马鞍山','淮北','铜陵','安庆','黄山','滁州','阜阳','宿州','巢湖','六安','亳州','池州','宣城'];
        $Jiangxi=['南昌','景德镇','萍乡','九江','新余','鹰潭','赣州','吉安','宜春','抚州','上饶'];
        $Fujian=['福州','厦门','莆田','三明','泉州','漳州','南平','龙岩','宁德'];
        $Chongqing=['重庆','万州','涪陵','黔江','綦江','潼南','酉阳','巫溪'];
        $Sichuan=['自贡','攀枝花','泸州','德阳','绵阳','广元','遂宁','内江','乐山','南充','眉山','宜宾','广安','达州','雅安','巴中','资阳','马尔康','西昌','成都'];
        $Yunnan=['昆明','曲靖','玉溪','保山','昭通','丽江','普洱','临沧','楚雄','蒙自','文山','景洪','大理','芒市','泸水','香格里拉'];
        $Guizhou=['贵阳','六盘水','遵义','安顺','铜仁','兴义','毕节','凯里','都匀'];
        $Xizang=['拉萨','昌都','山南','日喀则','那曲','普兰','林芝'];
        $Heilongjiang=['哈尔滨','齐齐哈尔','鸡西','鹤岗','双鸭山','大庆','伊春','佳木斯','七台河','牡丹江','黑河','绥化','呼玛县'];
        $Jilin=['长春','吉林','四平','辽源','通化','白山','松原','白城','延吉'];
        $Liaoning=['沈阳','大连','鞍山','抚顺','本溪','丹东','锦州','营口','阜新','辽阳','盘锦','铁岭','朝阳','葫芦岛'];
        $Shandong=['青岛','济南','济宁','威海','临清','淄博','德州','莱芜','莱阳','潍坊','高密','文登','济阳','烟台','聊城','兖州','菏泽','东营','日照','临沂'];
        $Beijing=['北京'];
        $Tianjin=['天津'];
        $Guangxi=['柳州','南宁','桂林','梧州','北海','防城港','钦州','贵港','玉林','百色','贺州','河池','来宾','崇左'];
        $Guangdong=['广州','深圳','韶关','珠海','汕头','佛山','江门','湛江','茂名','肇庆','惠州','梅州','汕头/汕尾','阳江','清远','东莞','中山','潮州','揭阳'];
        $Hebei=['石家庄','唐山','秦皇岛','邯郸','邢台','保定','张家口','承德','沧州','廊坊','衡水'];
        $ShanXi=['太原','大同','阳泉','长治','晋城','朔州','晋中','运城','忻州','临汾','吕梁'];
        $Neimenggu=['呼和浩特','包头','乌海','赤峰','通辽','鄂尔多斯','呼伦贝尔','巴彦淖尔','乌兰察布','乌兰浩特','锡林浩特','阿拉善'];
        $Hubei=['武汉','黄石','十堰','宜昌','襄樊','鄂州','荆门','孝感','荆州','黄冈','咸宁','随州','恩施'];
        $Hunan=['长沙','株洲','湘潭','衡阳','邵阳','岳阳','常德','张家界','益阳','郴州','永州','怀化','娄底','吉首'];
        $Henan=['郑州','开封','洛阳','平顶山','安阳','鹤壁','新乡','焦作','濮阳','许昌','漯河','三门峡','商丘','周口','驻马店','南阳','信阳','济源'];
        $Hainan=['海口','三亚'];
        $ShangHai=['上海'];
        $provinces=['陕西','甘肃','宁夏','青海','新疆','江苏','浙江','安徽','江西','福建','重庆','四川','云南',
            '贵州','西藏','黑龙江','吉林','辽宁','山东','北京','天津','广西','广东','河北','山西','内蒙古',
            '湖北','湖南','河南','海南','香港','澳门','台湾','上海'];
        for ($i=0;$i<count($provinces);$i++){
            if ($provinces[$i]=="陕西"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Shanxi);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Shanxi[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="甘肃"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Gansu);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Gansu[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="宁夏"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Ningxia);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Ningxia[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="青海"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Qinghai);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Qinghai[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="新疆"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Xinjiang);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Xinjiang[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="江苏"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Jiangsu);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Jiangsu[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="浙江"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($ZheJiang);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$ZheJiang[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="安徽"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Anhui);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Anhui[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="江西"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Jiangxi);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Jiangxi[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="福建"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Fujian);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Fujian[$j],
                    ]);
                }
            }
           if ($provinces[$i]=="重庆"){
               $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Chongqing);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Chongqing[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="四川"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Sichuan);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Sichuan[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="云南"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Yunnan);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Yunnan[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="贵州"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Guizhou);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Guizhou[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="西藏"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Xizang);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Xizang[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="黑龙江"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Heilongjiang);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Heilongjiang[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="吉林"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Jilin);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Jilin[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="辽宁"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Liaoning);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Liaoning[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="山东"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Shandong);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Shandong[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="北京"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Beijing);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Beijing[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="天津"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Tianjin);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Tianjin[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="广西"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Guangxi);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Guangxi[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="广东"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Guangdong);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Guangdong[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="河北"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Hebei);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Hebei[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="山西"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($ShanXi);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$ShanXi[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="内蒙古"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Neimenggu);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Neimenggu[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="湖北"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Hubei);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Hubei[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="湖南"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Hunan);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Hunan[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="河南"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Henan);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Henan[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="海南"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($Hainan);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$Hainan[$j],
                    ]);
                }
            }
            if ($provinces[$i]=="上海"){
                $province=\App\Province::where('name','=',$provinces[$i])->first();
                for ($j=0;$j<count($ShangHai);$j++){
                    \App\City::create([
                        'province_id'=>$province->id,
                        'name'=>$ShangHai[$j],
                    ]);
                }
            }
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('cities');
    }
}
