importMap.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Model\BaseArea;
  4. use App\Model\BaseAreaNew;
  5. use Faker\Provider\Base;
  6. use Illuminate\Console\Command;
  7. use Overtrue\Pinyin\Pinyin;
  8. class importMap extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'import:map';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = 'Command description';
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. // $data = json_decode(file_get_contents(public_path('docs/maps.txt')),true);
  39. $total = [];
  40. // foreach ($data['plist']['dict']['key'] as $value){
  41. // $prefix = substr($value,0,6);
  42. // $name = str_replace($prefix,'',$value);
  43. // $total[substr($prefix,0,2)] = ['pid'=>$prefix,'name'=>$name];
  44. // }
  45. //
  46. //
  47. //
  48. //
  49. //
  50. //
  51. // foreach ($data['plist']['dict']['dict'] as $datum){
  52. // foreach ($datum['key'] as $vv){
  53. // $g2_prefix = substr($vv,0,6);
  54. // $g2_prefix_half = substr($vv,0,2);
  55. // $name = str_replace($g2_prefix,'',$vv);
  56. // $total[substr($g2_prefix,0,4)] = ['pid'=>$g2_prefix,'name'=>$name];
  57. // }
  58. // }
  59. //
  60. //
  61. // foreach ($data['plist']['dict']['dict'] as $datum){
  62. // foreach ($datum['array'] as $vv){
  63. // foreach ($vv['string'] as $vvv){
  64. //
  65. // $g2_prefix = substr($vvv,0,6);
  66. // $g2_prefix_half = substr($vvv,0,2);
  67. // $g2_prefix_3 = substr($vvv,0,4);
  68. // $name = str_replace($g2_prefix,'',$vvv);
  69. // $total[substr($g2_prefix,0,5)] = ['pid'=>$g2_prefix,'name'=>$name];
  70. //
  71. // }
  72. // }
  73. // }
  74. //
  75. //
  76. //
  77. //
  78. //
  79. //
  80. //
  81. // $res = BaseAreaNew::find($g2_prefix);
  82. // if ($res)
  83. // continue;
  84. // $id = BaseAreaNew::insert([
  85. // 'name'=>$name,
  86. // 'pid'=>$total[$g2_prefix_3]['pid'],
  87. // 'id'=>$g2_prefix,
  88. // 'short_name'=>$name,
  89. // 'grade'=>3,
  90. // 'city_code'=>0,
  91. // 'zip_code'=>0,
  92. // 'merger_name'=>$total[$g2_prefix_half]['name'].','.$total[$g2_prefix_3]['name'].','.$name,
  93. // 'lng'=>0,
  94. // 'lat'=>0,
  95. // 'pinyin'=>'',
  96. // ]);
  97. //
  98. //
  99. // $dd = scandir(public_path('docs/town'));
  100. //
  101. // $arr = array_map(function ($v){
  102. // return str_replace('.json','',$v);
  103. // },$dd);
  104. // unset($dd);
  105. // $ds = BaseAreaNew::whereIn('id',$arr)->get(['id','name','merger_name']);
  106. //
  107. //
  108. // foreach ($ds as $d){
  109. // $dds = json_decode(file_get_contents(public_path('docs/town/'.$d->id.'.json')),true);
  110. // foreach ($dds as $k =>$v){
  111. //
  112. // $res = BaseAreaNew::find($k);
  113. // if ($res)
  114. // continue;
  115. // $id = BaseAreaNew::insert([
  116. // 'name'=>$v,
  117. // 'pid'=>$d->id,
  118. // 'id'=>$k,
  119. // 'short_name'=>$v,
  120. // 'grade'=>4,
  121. // 'city_code'=>0,
  122. // 'zip_code'=>0,
  123. // 'merger_name'=>$d->merger_name.','.$v,
  124. // 'lng'=>0,
  125. // 'lat'=>0,
  126. // 'pinyin'=>'',
  127. // ]);
  128. //
  129. // echo "{$v}:{$k} ³É¹¦µ¼ÈëÁË£¡\r\n";
  130. //
  131. // }
  132. $i = 0;
  133. $maps = BaseArea::where('relation','')->get(['pid','id']);
  134. foreach ($maps as $map) {
  135. $i++;
  136. echo "Deal:{$i}\r\n";
  137. $relation = ["1"];
  138. $pid = $map->pid;
  139. if ($pid == 1)
  140. $map->update(['relation' => implode(',',$relation)]);
  141. $relation[] = $map->id;
  142. while ($pid!=1){
  143. $area = BaseArea::find($pid);
  144. if ($area){
  145. $relation[] = $pid;
  146. $pid = $area->pid;
  147. }
  148. }
  149. $str = implode(',',$relation);
  150. $map->update(['relation' => $str]);
  151. echo "{$str}\r\n";
  152. }
  153. }
  154. }