importMap.php 4.9 KB

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