ReportTeacherWeeklyPdfCommand.php 1.0 KB

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. class ReportTeacherWeeklyPdfCommand extends Command
  5. {
  6. protected $signature = 'report:teacher-weekly-pdf
  7. {--days=7 : 近几个自然日(本周期 = 含今日 0 点至今;上周期 = 紧邻的前若干个完整自然日;时区见 app.timezone)}';
  8. protected $description = '生成老师组卷与学情分析周报 PDF(文件名带日期与时间戳 teacher-weekly-stats-Y-m-d_His.pdf)';
  9. public function handle(): int
  10. {
  11. $script = base_path('scripts/report_teacher_weekly_stats_pdf.php');
  12. if (! is_file($script)) {
  13. $this->error('找不到脚本:'.$script);
  14. return self::FAILURE;
  15. }
  16. $days = max(1, min(366, (int) $this->option('days')));
  17. putenv('TEACHER_WEEKLY_REPORT_DAYS='.(string) $days);
  18. passthru(escapeshellarg(PHP_BINARY).' '.escapeshellarg($script), $code);
  19. return $code === 0 ? self::SUCCESS : self::FAILURE;
  20. }
  21. }