Paper.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. 'diagnostic_chapter_id', // 摸底的章节ID(章节摸底时记录)
  20. 'total_questions',
  21. 'total_score',
  22. 'status',
  23. 'difficulty_category',
  24. 'completed_at',
  25. 'analysis_id', // AI分析记录ID
  26. 'exam_pdf_url', // 试卷PDF URL
  27. 'grading_pdf_url', // 判卷PDF URL
  28. 'all_pdf_url', // 【新增】统一PDF URL(包含试卷和判卷)
  29. ];
  30. protected $casts = [
  31. 'paper_id' => 'string',
  32. 'student_id' => 'string',
  33. 'teacher_id' => 'string',
  34. 'total_questions' => 'integer',
  35. 'total_score' => 'float',
  36. 'status' => 'string',
  37. 'difficulty_category' => 'string',
  38. 'paper_type' => 'integer',
  39. 'diagnostic_chapter_id' => 'integer',
  40. 'created_at' => 'datetime',
  41. 'updated_at' => 'datetime',
  42. 'completed_at' => 'datetime',
  43. 'exam_pdf_url' => 'string',
  44. 'grading_pdf_url' => 'string',
  45. ];
  46. /**
  47. * 获取试卷的题目列表
  48. */
  49. public function questions()
  50. {
  51. return $this->hasMany(PaperQuestion::class, 'paper_id', 'paper_id');
  52. }
  53. /**
  54. * 获取试卷创建者
  55. */
  56. public function createdByUser()
  57. {
  58. return $this->belongsTo(User::class, 'created_by', 'user_id');
  59. }
  60. /**
  61. * 获取关联的学生
  62. */
  63. public function student()
  64. {
  65. return $this->belongsTo(Student::class, 'student_id', 'student_id');
  66. }
  67. /**
  68. * 获取关联的教师
  69. */
  70. public function teacher()
  71. {
  72. return $this->belongsTo(Teacher::class, 'teacher_id', 'teacher_id');
  73. }
  74. }