Paper.php 1.7 KB

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