| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace app\admin\command;
- use think\console\Command;
- use think\console\Input;
- use think\console\input\Option;
- use think\console\Output;
- use think\Exception;
- use app\common\model\Region;
- class Task extends Command
- {
-
- protected function configure()
- {
- $this->setName('task')->setDescription('Compress js and css file');
- }
- protected function execute(Input $input, Output $output)
- {
- $reg = new Region();
- $list = $reg::where('level', '=', 1)->column('id,name');
- $arr = array();
- $i = 0;
- // $reg::chunk(100, function($rows) use($arr, $i) {
- // foreach ($rows as $row) {
-
- // $arr[$i]['label'] = $row->name;
- // $arr[$i]['value'] = $row->id;
- // dump($row);die;
- // }
- // return false;
- // });
-
- foreach ($list as $key => $item) {
-
- $arr[$i]['label'] = $item;
- $arr[$i]['value'] = $key;
- $list1 =$reg::where('parent_id', '=', $key)->column('id,name');
- $j = 0;
- foreach ($list1 as $key1 => $item1) {
- $arr[$i]['children'][$j]['label'] = $item1;
- $arr[$i]['children'][$j]['value'] = $key1;
- $list2 =$reg::where('parent_id', '=', $key1)->column('id,name');
- $s = 0;
-
- foreach ($list2 as $key2 => $item2) {
- $arr[$i]['children'][$j]['children'][$s]['label'] = $item2;
- $arr[$i]['children'][$j]['children'][$s]['value'] = $key2;
- $list3 =$reg::where('parent_id', '=', $key2)->column('id,name');
- $d = 0;
- foreach ($list3 as $key3 => $item3) {
- $arr[$i]['children'][$j]['children'][$s]['children'][$d]['label'] = $item3;
- $arr[$i]['children'][$j]['children'][$s]['children'][$d]['value'] = $key3;
- $d += 1;
- }
- $s +=1;
- }
- $j +=1;
- }
- $i +=1;
- }
- file_put_contents('./11.txt', json_encode($arr, JSON_UNESCAPED_UNICODE));
- $output->info("Ok Successed!");
- }
- }
|