exportRepository = $exportRepository; } /** * 导出记录 * * @param array $conditions * @return void */ public function index(array $conditions = []) { $limit = $conditions['limit'] ?? 20; $exports = $this->exportRepository->withConditions($conditions)->applyConditions()->paginate($limit); $status = app(Dicts::class)->get('export_status'); $exports->transform(function ($item) use ($classes, $status) { $exists = Storage::disk($item->disk)->exists($item->filename); if ($item->status === 3) { if (!$exists = Storage::disk($item->disk)->exists($item->filename)) { $item->status = 5; } } $url = $item->status === 3 ? Storage::disk($item->disk)->url($item->filename) : ''; $conditions = array_except($item->conditions ?? [], ['page', 'limit', 'orderBy', 'sortedBy']); return [ 'id' => $item->id, 'tag' => $item->tag, 'filename' => basename($url), 'filesize' => human_filesize($item->filesize), 'dateline' => !$item->conditions['starttime'] ? '所有' : $item->conditions['starttime'] . ' 至 ' . $item->conditions['endtime'], 'conditions' => json_encode($conditions, JSON_PRETTY_PRINT), 'status' => $item->status, 'status_name' => $status[$item->status], 'url' => $url, 'created_at' => (string) $item->created_at, 'updated_at' => (string) $item->updated_at, ]; }); return $exports; } /** * 删除 * * @return bool */ public function destroy($ids) { $ids = is_array($ids) ? $ids : [$ids]; $this->exportRepository->destroy($ids); return true; } /** * 导出 */ public static function store($export, $disk, $queue = false) { if (!$queue) { Excel::store($export, $export->filename, $disk); $url = Storage::disk($disk)->url($export->filename); return $url; } Excel::queue($export, $export->filename, $disk); } }