Paper.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. 'question_count',
  20. 'total_score',
  21. 'status',
  22. 'difficulty_category',
  23. 'analysis_summary',
  24. 'feedback',
  25. 'completed_at',
  26. 'analysis_id', // AI分析记录ID
  27. ];
  28. protected $casts = [
  29. 'created_at' => 'datetime',
  30. 'updated_at' => 'datetime',
  31. 'completed_at' => 'datetime',
  32. 'total_score' => 'float',
  33. 'question_count' => 'integer',
  34. ];
  35. /**
  36. * 获取试卷的题目列表
  37. */
  38. public function questions()
  39. {
  40. return $this->hasMany(PaperQuestion::class, 'paper_id', 'paper_id');
  41. }
  42. /**
  43. * 获取关联的学生
  44. */
  45. public function student()
  46. {
  47. return $this->belongsTo(Student::class, 'student_id', 'student_id');
  48. }
  49. /**
  50. * 获取关联的教师
  51. */
  52. public function teacher()
  53. {
  54. return $this->belongsTo(Teacher::class, 'teacher_id', 'teacher_id');
  55. }
  56. }