Paper.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. 'all_pdf_url' => 'string',
  48. ];
  49. /**
  50. * 获取试卷的题目列表
  51. */
  52. public function questions()
  53. {
  54. return $this->hasMany(PaperQuestion::class, 'paper_id', 'paper_id');
  55. }
  56. /**
  57. * 获取试卷创建者
  58. */
  59. public function createdByUser()
  60. {
  61. return $this->belongsTo(User::class, 'created_by', 'user_id');
  62. }
  63. /**
  64. * 获取关联的学生
  65. */
  66. public function student()
  67. {
  68. return $this->belongsTo(Student::class, 'student_id', 'student_id');
  69. }
  70. /**
  71. * 获取关联的教师
  72. */
  73. public function teacher()
  74. {
  75. return $this->belongsTo(Teacher::class, 'teacher_id', 'teacher_id');
  76. }
  77. }