Task.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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)->field('id,name,ext_id')->select();
  19. $arr = array();
  20. foreach ($list as $i=>$item) {
  21. $arr[$i]['label'] = $item->name;
  22. $arr[$i]['id'] = $item->ext_id;
  23. $list1 =$reg::where('parent_id', '=', $item->id)->field('id,name,ext_id')->select();
  24. foreach ($list1 as $j => $item1) {
  25. $arr[$i]['children'][$j]['label'] = $item1->name;
  26. $arr[$i]['children'][$j]['id'] = $item1->ext_id;
  27. $list2 =$reg::where('parent_id', '=', $item1->id)->field('id,name,ext_id')->select();
  28. foreach ($list2 as $s => $item2) {
  29. $arr[$i]['children'][$j]['children'][$s]['label'] = $item2->name;
  30. $arr[$i]['children'][$j]['children'][$s]['id'] = $item2->ext_id;
  31. $list3 =$reg::where('parent_id', '=', $item2->id)->field('id,name,ext_id')->select();
  32. foreach ($list3 as $d => $item3) {
  33. if(!empty($item3)){
  34. $arr[$i]['children'][$j]['children'][$s]['children'][$d]['label'] = $item3->name;
  35. $arr[$i]['children'][$j]['children'][$s]['children'][$d]['id'] = $item3->ext_id;
  36. }
  37. }
  38. }
  39. }
  40. }
  41. file_put_contents('./11.txt', json_encode($arr, JSON_UNESCAPED_UNICODE));
  42. $output->info("Ok Successed!");
  43. }
  44. }