download = $download; $this->postRepository = $postRepository; } /** * Execute the console command. * * @return mixed */ public function handle() { $this->line("开始检索生成中下载"); $fileDir = 'export/'; $path = public_path($fileDir); if(!file_exists($path)){ @mkdir($path, 775); } $download = $this->download->where('download_status', 0)->orderBy('id', 'desc')->first(); if($download->download_type == 'post'){ $filePath = $fileDir .'内容-'.Carbon::now()->format('Y-m-d') .'_' .uniqid() .'.csv'; }elseif($download->download_type == 'post_waste'){ $filePath = $fileDir .'回收站内容-'.Carbon::now()->format('Y-m-d') .'_' .uniqid() .'.csv'; }else{ exit; } try { $this->postRepository->download($filePath, $download->download_type, json_decode($download->params, true)); $download->url = $filePath; $download->download_status = 1; $download->save(); } catch (\Exception $e) { $download->download_status = 2; $download->url = $e->getMessage(); $download->save(); } } }