Paper.php 2.3 KB

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