Task.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. 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. }