Task.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\admin\command;
  3. use think\console\Command;
  4. use think\console\Input;
  5. use think\console\input\Option;
  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 execute(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. // $reg::chunk(100, function($rows) use($arr, $i) {
  22. // foreach ($rows as $row) {
  23. // $arr[$i]['label'] = $row->name;
  24. // $arr[$i]['value'] = $row->id;
  25. // dump($row);die;
  26. // }
  27. // return false;
  28. // });
  29. foreach ($list as $key => $item) {
  30. $arr[$i]['label'] = $item;
  31. $arr[$i]['value'] = $key;
  32. $list1 =$reg::where('parent_id', '=', $key)->column('id,name');
  33. $j = 0;
  34. foreach ($list1 as $key1 => $item1) {
  35. $arr[$i]['children'][$j]['label'] = $item1;
  36. $arr[$i]['children'][$j]['value'] = $key1;
  37. $list2 =$reg::where('parent_id', '=', $key1)->column('id,name');
  38. $s = 0;
  39. foreach ($list2 as $key2 => $item2) {
  40. $arr[$i]['children'][$j]['children'][$s]['label'] = $item2;
  41. $arr[$i]['children'][$j]['children'][$s]['value'] = $key2;
  42. $list3 =$reg::where('parent_id', '=', $key2)->column('id,name');
  43. $d = 0;
  44. foreach ($list3 as $key3 => $item3) {
  45. $arr[$i]['children'][$j]['children'][$s]['children'][$d]['label'] = $item3;
  46. $arr[$i]['children'][$j]['children'][$s]['children'][$d]['value'] = $key3;
  47. $d += 1;
  48. }
  49. $s +=1;
  50. }
  51. $j +=1;
  52. }
  53. $i +=1;
  54. }
  55. file_put_contents('./11.txt', json_encode($arr, JSON_UNESCAPED_UNICODE));
  56. $output->info("Ok Successed!");
  57. }
  58. }