TeacherWeeklyStatsReport.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Filament\Pages;
  3. use Filament\Actions\Action;
  4. use Filament\Notifications\Notification;
  5. use Filament\Pages\Page;
  6. use Illuminate\Support\Facades\Artisan;
  7. use Livewire\Attributes\Computed;
  8. use UnitEnum;
  9. class TeacherWeeklyStatsReport extends Page
  10. {
  11. protected static ?string $title = '老师周报统计';
  12. protected static ?string $navigationLabel = '老师周报统计';
  13. protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-document-chart-bar';
  14. protected static string|UnitEnum|null $navigationGroup = '其他';
  15. protected static ?int $navigationSort = 95;
  16. protected string $view = 'filament.pages.teacher-weekly-stats-report';
  17. #[Computed(cache: false)]
  18. public function hasLatestPdf(): bool
  19. {
  20. return is_file($this->latestPdfPath());
  21. }
  22. #[Computed(cache: false)]
  23. public function latestPdfMtime(): ?string
  24. {
  25. $p = $this->latestPdfPath();
  26. return is_file($p) ? date('Y-m-d H:i:s', filemtime($p)) : null;
  27. }
  28. #[Computed(cache: false)]
  29. public function pdfOpenUrl(): string
  30. {
  31. return route('filament.admin.reports.teacher-weekly-stats.open');
  32. }
  33. protected function latestPdfPath(): string
  34. {
  35. return storage_path('app/reports/teacher-weekly-stats-latest.pdf');
  36. }
  37. protected function getHeaderActions(): array
  38. {
  39. return [
  40. Action::make('regenerate')
  41. ->label('生成 / 刷新周报 PDF')
  42. ->icon('heroicon-o-arrow-path')
  43. ->action(function (): void {
  44. $code = Artisan::call('report:teacher-weekly-pdf');
  45. if ($code !== 0) {
  46. Notification::make()
  47. ->title('生成失败')
  48. ->danger()
  49. ->body('请查看日志或终端输出')
  50. ->send();
  51. return;
  52. }
  53. $this->dispatch('$refresh');
  54. Notification::make()
  55. ->title('周报已生成')
  56. ->success()
  57. ->send();
  58. }),
  59. ];
  60. }
  61. }