Paper.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Paper extends Model
  5. {
  6. protected $table = 'papers';
  7. protected $primaryKey = 'paper_id';
  8. public $incrementing = false;
  9. protected $keyType = 'string';
  10. public $timestamps = true;
  11. const CREATED_AT = 'created_at';
  12. const UPDATED_AT = 'updated_at';
  13. protected $fillable = [
  14. 'paper_id',
  15. 'student_id',
  16. 'teacher_id',
  17. 'paper_name',
  18. 'paper_type',
  19. 'total_questions',
  20. 'total_score',
  21. 'status',
  22. 'difficulty_category',
  23. 'completed_at',
  24. 'analysis_id', // AI分析记录ID
  25. 'exam_pdf_url', // 试卷PDF URL
  26. 'grading_pdf_url', // 判卷PDF URL
  27. 'all_pdf_url', // 【新增】统一PDF URL(包含试卷和判卷)
  28. ];
  29. protected $casts = [
  30. 'paper_id' => 'string',
  31. 'student_id' => 'string',
  32. 'teacher_id' => 'string',
  33. 'total_questions' => 'integer',
  34. 'total_score' => 'float',
  35. 'status' => 'string',
  36. 'difficulty_category' => 'string',
  37. 'created_at' => 'datetime',
  38. 'updated_at' => 'datetime',
  39. 'completed_at' => 'datetime',
  40. 'exam_pdf_url' => 'string',
  41. 'grading_pdf_url' => 'string',
  42. ];
  43. /**
  44. * 获取试卷的题目列表
  45. */
  46. public function questions()
  47. {
  48. return $this->hasMany(PaperQuestion::class, 'paper_id', 'paper_id');
  49. }
  50. /**
  51. * 获取试卷创建者
  52. */
  53. public function createdByUser()
  54. {
  55. return $this->belongsTo(User::class, 'created_by', 'user_id');
  56. }
  57. /**
  58. * 获取关联的学生
  59. */
  60. public function student()
  61. {
  62. return $this->belongsTo(Student::class, 'student_id', 'student_id');
  63. }
  64. /**
  65. * 获取关联的教师
  66. */
  67. public function teacher()
  68. {
  69. return $this->belongsTo(Teacher::class, 'teacher_id', 'teacher_id');
  70. }
  71. }