Task.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\admin\command;
  3. use think\console\Command;
  4. use think\console\Input;
  5. use app\admin\model\Importregion;
  6. use think\console\Output;
  7. use think\Exception;
  8. use app\common\model\Region;
  9. class Task extends Command
  10. {
  11. protected function configure()
  12. {
  13. $this->setName('task')->setDescription('Compress js and css file');
  14. }
  15. protected function execute1(Input $input, Output $output)
  16. {
  17. $reg = new Region();
  18. $list = $reg::where('level', '=', 1)->column('id,name');
  19. $arr = array();
  20. $i = 0;
  21. foreach ($list as $key => $item) {
  22. $arr[$i]['label'] = $item;
  23. $arr[$i]['id'] = $key;
  24. $list1 =$reg::where('parent_id', '=', $key)->column('id,name');
  25. $j = 0;
  26. foreach ($list1 as $key1 => $item1) {
  27. $arr[$i]['children'][$j]['label'] = $item1;
  28. $arr[$i]['children'][$j]['id'] = $key1;
  29. $list2 =$reg::where('parent_id', '=', $key1)->column('id,name');
  30. $s = 0;
  31. foreach ($list2 as $key2 => $item2) {
  32. $arr[$i]['children'][$j]['children'][$s]['label'] = $item2;
  33. $arr[$i]['children'][$j]['children'][$s]['id'] = $key2;
  34. $list3 =$reg::where('parent_id', '=', $key2)->column('id,name');
  35. $d = 0;
  36. foreach ($list3 as $key3 => $item3) {
  37. if(!empty($item3)){
  38. $arr[$i]['children'][$j]['children'][$s]['children'][$d]['label'] = $item3;
  39. $arr[$i]['children'][$j]['children'][$s]['children'][$d]['id'] = $key3;
  40. $d += 1;
  41. }
  42. }
  43. $s +=1;
  44. }
  45. $j +=1;
  46. }
  47. $i +=1;
  48. }
  49. file_put_contents('./11.txt', json_encode($arr, JSON_UNESCAPED_UNICODE));
  50. $output->info("Ok Successed!");
  51. }
  52. //地区导出格式
  53. public function execute(Input $input, Output $output){
  54. $reg = new Region();
  55. $imreg= new Importregion();
  56. $list = $reg::where('ext_id', '>', 0)->chunk(1000, function($users) use($reg, $imreg) {
  57. foreach ($users as $user) {
  58. switch ($user->level) {
  59. case 2:
  60. $one = $reg::where('id', $user->parent_id)->find();
  61. $imreg::insert(['name'=> $one->name.'-'.$user->name, 'com_id'=>$one->id.'-'.$user->id, 'level'=>2]);
  62. break;
  63. case 3:
  64. $two = $reg::where('id', $user->parent_id)->find();
  65. $one = $reg::where('id', $two->parent_id)->find();
  66. $imreg::insert(['name'=> $one->name.'-'.$two->name.'-'.$user->name, 'com_id'=>$one->id.'-'.$two->id.'-'.$user->id, 'level'=>3]);
  67. break;
  68. case 4:
  69. $san = $reg::where('id', $user->parent_id)->find();
  70. $two = $reg::where('id', $san->parent_id)->find();
  71. $one = $reg::where('id', $two->parent_id)->find();
  72. $imreg::insert(['name'=> $one->name.'-'.$two->name.'-'.$san->name.'-'.$user->name, 'com_id'=>$one->id.'-'.$two->id.'-'.$san->id.'-'.$user->id, 'level'=>4]);
  73. break;
  74. // 更多的 case 语句
  75. default:
  76. $imreg::insert([ 'name'=> $user->name, 'com_id'=>$user->id, 'level'=>1]);
  77. }
  78. //
  79. };
  80. });
  81. }
  82. }