Paper.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. ];
  28. protected $casts = [
  29. 'paper_id' => 'string',
  30. 'student_id' => 'string',
  31. 'teacher_id' => 'string',
  32. 'total_questions' => 'integer',
  33. 'total_score' => 'float',
  34. 'status' => 'string',
  35. 'difficulty_category' => 'string',
  36. 'created_at' => 'datetime',
  37. 'updated_at' => 'datetime',
  38. 'completed_at' => 'datetime',
  39. 'exam_pdf_url' => 'string',
  40. 'grading_pdf_url' => 'string',
  41. ];
  42. /**
  43. * 获取试卷的题目列表
  44. */
  45. public function questions()
  46. {
  47. return $this->hasMany(PaperQuestion::class, 'paper_id', 'paper_id');
  48. }
  49. /**
  50. * 获取试卷创建者
  51. */
  52. public function createdByUser()
  53. {
  54. return $this->belongsTo(User::class, 'created_by', 'user_id');
  55. }
  56. /**
  57. * 获取关联的学生
  58. */
  59. public function student()
  60. {
  61. return $this->belongsTo(Student::class, 'student_id', 'student_id');
  62. }
  63. /**
  64. * 获取关联的教师
  65. */
  66. public function teacher()
  67. {
  68. return $this->belongsTo(Teacher::class, 'teacher_id', 'teacher_id');
  69. }
  70. }