StudentReport.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. class StudentReport extends Model
  7. {
  8. use HasFactory;
  9. protected $table = 'student_reports';
  10. protected $fillable = [
  11. 'student_id',
  12. 'report_type',
  13. 'pdf_url',
  14. 'file_name',
  15. 'file_size',
  16. 'generation_status',
  17. 'exam_id',
  18. 'report_title',
  19. 'report_data',
  20. 'generated_at',
  21. 'expires_at',
  22. 'notes',
  23. ];
  24. protected $casts = [
  25. 'report_data' => 'array',
  26. 'generated_at' => 'datetime',
  27. 'expires_at' => 'datetime',
  28. 'created_at' => 'datetime',
  29. 'updated_at' => 'datetime',
  30. ];
  31. /**
  32. * 获取报告所属学生
  33. */
  34. public function student(): BelongsTo
  35. {
  36. return $this->belongsTo(Student::class, 'student_id', 'student_id');
  37. }
  38. /**
  39. * 报告类型常量
  40. */
  41. const REPORT_TYPE_MASTERY_ANALYSIS = 'mastery_analysis';
  42. const REPORT_TYPE_EXAM_REPORT = 'exam_report';
  43. const REPORT_TYPE_LEARNING_PROGRESS = 'learning_progress';
  44. /**
  45. * 生成状态常量
  46. */
  47. const STATUS_PENDING = 'pending';
  48. const STATUS_COMPLETED = 'completed';
  49. const STATUS_FAILED = 'failed';
  50. /**
  51. * 作用域:仅获取已完成的报告
  52. */
  53. public function scopeCompleted($query)
  54. {
  55. return $query->where('generation_status', self::STATUS_COMPLETED);
  56. }
  57. /**
  58. * 作用域:按报告类型筛选
  59. */
  60. public function scopeOfType($query, string $type)
  61. {
  62. return $query->where('report_type', $type);
  63. }
  64. }