Paper.php 2.2 KB

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