Paper.php 2.3 KB

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