| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace app\admin\command;
- use think\console\Command;
- use think\console\Input;
- use app\admin\model\Importregion;
- 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 execute1(Input $input, Output $output)
- {
- $reg = new Region();
- $list = $reg::where('level', '=', 1)->column('id,name');
- $arr = array();
- $i = 0;
- foreach ($list as $key => $item) {
- $arr[$i]['label'] = $item;
- $arr[$i]['id'] = $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]['id'] = $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]['id'] = $key2;
- $list3 =$reg::where('parent_id', '=', $key2)->column('id,name');
- $d = 0;
- foreach ($list3 as $key3 => $item3) {
- if(!empty($item3)){
- $arr[$i]['children'][$j]['children'][$s]['children'][$d]['label'] = $item3;
- $arr[$i]['children'][$j]['children'][$s]['children'][$d]['id'] = $key3;
- $d += 1;
- }
-
- }
- $s +=1;
- }
- $j +=1;
- }
- $i +=1;
- }
- file_put_contents('./11.txt', json_encode($arr, JSON_UNESCAPED_UNICODE));
- $output->info("Ok Successed!");
- }
-
- //地区导出格式
- public function execute(Input $input, Output $output){
- $reg = new Region();
- $imreg= new Importregion();
- $list = $reg::where('ext_id', '>', 0)->chunk(1000, function($users) use($reg, $imreg) {
- foreach ($users as $user) {
- switch ($user->level) {
- case 2:
- $one = $reg::where('id', $user->parent_id)->find();
- $imreg::insert(['name'=> $one->name.'-'.$user->name, 'com_id'=>$one->id.'-'.$user->id, 'level'=>2]);
- break;
- case 3:
- $two = $reg::where('id', $user->parent_id)->find();
- $one = $reg::where('id', $two->parent_id)->find();
- $imreg::insert(['name'=> $one->name.'-'.$two->name.'-'.$user->name, 'com_id'=>$one->id.'-'.$two->id.'-'.$user->id, 'level'=>3]);
- break;
- case 4:
- $san = $reg::where('id', $user->parent_id)->find();
- $two = $reg::where('id', $san->parent_id)->find();
- $one = $reg::where('id', $two->parent_id)->find();
- $imreg::insert(['name'=> $one->name.'-'.$two->name.'-'.$san->name.'-'.$user->name, 'com_id'=>$one->id.'-'.$two->id.'-'.$san->id.'-'.$user->id, 'level'=>4]);
- break;
- // 更多的 case 语句
- default:
- $imreg::insert([ 'name'=> $user->name, 'com_id'=>$user->id, 'level'=>1]);
- }
- //
- };
- });
- }
- }
|