PaperQuestion.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class PaperQuestion extends Model
  5. {
  6. protected $table = 'paper_questions';
  7. protected $primaryKey = 'id';
  8. protected $fillable = [
  9. 'paper_id',
  10. 'question_id',
  11. 'question_bank_id',
  12. 'knowledge_point',
  13. 'question_type', // choice-选择题, fill-填空题, answer-解答题
  14. 'question_text',
  15. 'correct_answer',
  16. 'solution', // 解题思路
  17. 'difficulty',
  18. 'score',
  19. 'estimated_time',
  20. 'question_number',
  21. 'student_answer',
  22. 'is_correct',
  23. 'score_obtained',
  24. 'score_ratio',
  25. 'teacher_comment',
  26. 'graded_at',
  27. 'graded_by',
  28. ];
  29. protected $casts = [
  30. 'paper_id' => 'string',
  31. 'question_id' => 'string',
  32. 'question_bank_id' => 'integer',
  33. 'question_type' => 'string',
  34. 'question_text' => 'string',
  35. 'difficulty' => 'float',
  36. 'score' => 'float',
  37. 'estimated_time' => 'integer',
  38. 'question_number' => 'integer',
  39. 'is_correct' => 'boolean',
  40. 'score_obtained' => 'float',
  41. 'created_at' => 'datetime',
  42. 'updated_at' => 'datetime',
  43. ];
  44. /**
  45. * 获取所属试卷
  46. */
  47. public function paper()
  48. {
  49. return $this->belongsTo(Paper::class, 'paper_id', 'paper_id');
  50. }
  51. /**
  52. * 获取对应的题库题目
  53. */
  54. public function questionBank()
  55. {
  56. return $this->belongsTo(\App\Models\Question::class, 'question_bank_id', 'id');
  57. }
  58. /**
  59. * 按 question_id 查询题目的作用域
  60. */
  61. public function scopeByQuestionId($query, $questionId)
  62. {
  63. return $query->where('question_id', $questionId);
  64. }
  65. /**
  66. * 按 question_bank_id 查询题目的作用域
  67. */
  68. public function scopeByQuestionBankId($query, $questionBankId)
  69. {
  70. return $query->where('question_bank_id', $questionBankId);
  71. }
  72. }