QuestionWrongModel.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\admin\model\exam;
  3. use addons\exam\model\BaseModel;
  4. class QuestionWrongModel extends BaseModel
  5. {
  6. // 表名
  7. protected $name = 'exam_question_wrong';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append
  16. = [
  17. 'user_answer',
  18. ];
  19. protected $type
  20. = [
  21. 'user_answer' => 'array',
  22. ];
  23. // public function getUserAnswerAttr($value, $data)
  24. // {
  25. // return json_decode($data['user_answer'], true);
  26. // }
  27. public function question()
  28. {
  29. return $this->belongsTo(\addons\exam\model\QuestionModel::class, 'question_id', 'id', [], 'LEFT')->setEagerlyType(0);
  30. }
  31. public static function add($user_id, $question_id)
  32. {
  33. return self::create([
  34. 'user_id' => $user_id,
  35. 'question_id' => $question_id,
  36. ]);
  37. }
  38. }