| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 | <?phpnamespace App\Console\Commands;use App\Model\BaseArea;use App\Model\BaseAreaNew;use Faker\Provider\Base;use Illuminate\Console\Command;use Overtrue\Pinyin\Pinyin;class importMap extends Command{    /**     * The name and signature of the console command.     *     * @var string     */    protected $signature = 'import:map';    /**     * The console command description.     *     * @var string     */    protected $description = 'Command description';    /**     * Create a new command instance.     *     * @return void     */    public function __construct()    {        parent::__construct();    }    /**     * Execute the console command.     *     * @return mixed     */    public function handle()    {    //    $data = json_decode(file_get_contents(public_path('docs/maps.txt')),true);        $total = [];//        foreach ($data['plist']['dict']['key'] as $value){//            $prefix = substr($value,0,6);//            $name = str_replace($prefix,'',$value);//            $total[substr($prefix,0,2)] = ['pid'=>$prefix,'name'=>$name];//        }//////////////     foreach ($data['plist']['dict']['dict'] as $datum){//             foreach ($datum['key'] as $vv){//                     $g2_prefix = substr($vv,0,6);//                     $g2_prefix_half = substr($vv,0,2);//                     $name = str_replace($g2_prefix,'',$vv);//                     $total[substr($g2_prefix,0,4)] = ['pid'=>$g2_prefix,'name'=>$name];//         }//     }//////        foreach ($data['plist']['dict']['dict'] as $datum){//            foreach ($datum['array'] as $vv){//                foreach ($vv['string'] as $vvv){////                    $g2_prefix = substr($vvv,0,6);//                    $g2_prefix_half = substr($vvv,0,2);//                    $g2_prefix_3 = substr($vvv,0,4);//                    $name = str_replace($g2_prefix,'',$vvv);//                    $total[substr($g2_prefix,0,5)] = ['pid'=>$g2_prefix,'name'=>$name];////                }//            }//        }////////////////        $res = BaseAreaNew::find($g2_prefix);//        if ($res)//            continue;//        $id = BaseAreaNew::insert([//            'name'=>$name,//            'pid'=>$total[$g2_prefix_3]['pid'],//            'id'=>$g2_prefix,//            'short_name'=>$name,//            'grade'=>3,//            'city_code'=>0,//            'zip_code'=>0,//            'merger_name'=>$total[$g2_prefix_half]['name'].','.$total[$g2_prefix_3]['name'].','.$name,//            'lng'=>0,//            'lat'=>0,//            'pinyin'=>'',//        ]);//////     $dd = scandir(public_path('docs/town'));////     $arr = array_map(function ($v){//         return str_replace('.json','',$v);//     },$dd);//     unset($dd);//     $ds = BaseAreaNew::whereIn('id',$arr)->get(['id','name','merger_name']);//////     foreach ($ds as $d){//         $dds = json_decode(file_get_contents(public_path('docs/town/'.$d->id.'.json')),true);//         foreach ($dds as $k =>$v){////             $res = BaseAreaNew::find($k);//        if ($res)//            continue;//        $id = BaseAreaNew::insert([//            'name'=>$v,//            'pid'=>$d->id,//            'id'=>$k,//            'short_name'=>$v,//            'grade'=>4,//            'city_code'=>0,//            'zip_code'=>0,//            'merger_name'=>$d->merger_name.','.$v,//            'lng'=>0,//            'lat'=>0,//            'pinyin'=>'',//        ]);////        echo "{$v}:{$k} ³É¹¦µ¼ÈëÁË£¡\r\n";////         }        $i = 0;        $maps =  BaseArea::where('relation','')->get(['pid','id']);        foreach ($maps as $map) {            $i++;            echo "Deal:{$i}\r\n";            $relation = ["1"];            $pid = $map->pid;            if ($pid == 1)                $map->update(['relation' => implode(',',$relation)]);            $relation[] = $map->id;            while ($pid!=1){                $area = BaseArea::find($pid);                if ($area){                    $relation[] = $pid;                    $pid = $area->pid;                }            }            $str = implode(',',$relation);            $map->update(['relation' => $str]);            echo "{$str}\r\n";        }    }}
 |