setTimezone('Asia/Shanghai'); $end = $now->copy()->startOfDay()->setTime(8, 0); if ($now->lt($end)) $end->subDay(); if ($end->copy()->subDay()->toDateString() >= $startDate) $reports->snapshot($end->utc()); $attention = false; MailDailyReport::where('report_date', '>=', $startDate)->whereIn('status', ['pending', 'queued', 'sending']) ->orderBy('id')->limit(10)->get()->each(function ($report) use ($reports, &$attention) { $reports->send($report); $report->refresh(); $attention = $attention || in_array($report->status, ['failed', 'unknown', 'uncertain'], true) || $report->error_code !== null; $this->line(json_encode(['id' => $report->id, 'report_date' => $report->report_date, 'status' => $report->status, 'error_code' => $report->error_code], JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR)); }); return $attention ? self::FAILURE : self::SUCCESS; } catch (\Throwable $e) { $this->error('mail_report_failed_closed: ' . get_class($e)); return self::FAILURE; } } }