ExaminationWrongBank.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\model\topic;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. /**
  15. * 错题库 Model
  16. * Class ExaminationWrongBank
  17. */
  18. class ExaminationWrongBank extends ModelBasic
  19. {
  20. use ModelTrait;
  21. /**加入错题库
  22. * @param $examination_id
  23. * @param $type
  24. * @param $uid
  25. * @return bool
  26. * @throws \think\db\exception\DataNotFoundException
  27. * @throws \think\db\exception\ModelNotFoundException
  28. * @throws \think\exception\DbException
  29. */
  30. public static function addWrongBank($examination_id, $test_id, $type, $uid)
  31. {
  32. $data = ExaminationTestRecord::where(['e_id' => $examination_id, 'type' => $type, 'is_correct' => 1])->select();
  33. $data = count($data) > 0 ? $data->toArray() : [];
  34. if (!count($data)) return true;
  35. $item['uid'] = $uid;
  36. foreach ($data as $key => $value) {
  37. $item['questions_id'] = $value['questions_id'];
  38. $item['user_answer'] = $value['user_answer'];
  39. $item['answer'] = $value['answer'];
  40. $item['test_id'] = $test_id;
  41. $item['add_time'] = time();
  42. if (self::be(['uid' => $item['uid'], 'test_id' => $test_id, 'questions_id' => $item['questions_id']])) continue;
  43. self::set($item);
  44. }
  45. return true;
  46. }
  47. /**错题列表
  48. * @param $uid
  49. * @param $is_master
  50. * @param int $page
  51. * @param int $limit
  52. * @return mixed
  53. */
  54. public static function userWrongBankList($uid, $page = 1, $limit = 10, $is_master)
  55. {
  56. $model = self::alias('w');
  57. if ($is_master != '') $model = $model->where('w.is_master', $is_master);
  58. $list = $model->join('Questions q', 'w.questions_id=q.id')
  59. ->join('TestPaper t', 'w.test_id=t.id')
  60. ->where(['w.uid' => $uid, 'q.is_del' => 0, 't.is_del' => 0, 'w.is_del' => 0, 't.is_show' => 1, 't.status' => 1])
  61. ->field('w.*,q.option,q.stem,q.image,q.answer,q.difficulty,q.analysis,q.relation,q.question_type,q.is_img,t.title')
  62. ->order('w.add_time desc,w.id desc')->page((int)$page, (int)$limit)->select();
  63. return $list;
  64. }
  65. /**错题ID集合
  66. * @param $uid
  67. * @param $is_master
  68. * @return array
  69. */
  70. public static function getUserWrongBankIDList($uid, $is_master, $id, $order)
  71. {
  72. $model = self::alias('w');
  73. if ($is_master != '') $model = $model->where('w.is_master', $is_master);
  74. $model = $model->join('Questions q', 'w.questions_id=q.id')
  75. ->join('TestPaper t', 'w.test_id=t.id')
  76. ->where(['w.uid' => $uid, 'q.is_del' => 0, 't.is_del' => 0, 'w.is_del' => 0, 't.is_show' => 1, 't.status' => 1]);
  77. if ($order) {
  78. $model = $model->order('w.id desc')->where('w.id', '<', $id)->limit(10);
  79. } else {
  80. $model = $model->order('w.id asc')->where('w.id', '>', $id)->limit(10);
  81. }
  82. $list = $model->column('w.id');
  83. return $list;
  84. }
  85. /**删除错题
  86. * @param $id
  87. */
  88. public static function delUserWrongBank($id)
  89. {
  90. return self::where(['id' => $id, 'is_del' => 0])->update(['is_del' => 1]);
  91. }
  92. /**获取错题库试题
  93. * @param $uid
  94. * @param $is_master
  95. * @return false|\PDOStatement|string|\think\Collection
  96. * @throws \think\db\exception\DataNotFoundException
  97. * @throws \think\db\exception\ModelNotFoundException
  98. * @throws \think\exception\DbException
  99. */
  100. public static function getUserWrongBankListAll($uid, $is_master)
  101. {
  102. $list = self::alias('w')->join('Questions q', 'w.questions_id=q.id')
  103. ->where(['w.uid' => $uid, 'w.is_master' => $is_master, 'q.is_del' => 0, 'w.is_del' => 0])
  104. ->field('w.*,q.option,q.stem,q.image,q.answer,q.difficulty,q.analysis,q.relation,q.is_img')
  105. ->order('w.add_time desc')->select();
  106. return $list;
  107. }
  108. /**单个错题
  109. * @param $uid
  110. * @param $id
  111. * @return false|\PDOStatement|string|\think\Collection
  112. * @throws \think\db\exception\DataNotFoundException
  113. * @throws \think\db\exception\ModelNotFoundException
  114. * @throws \think\exception\DbException
  115. */
  116. public static function getUserWrongBankListOne($uid, $id)
  117. {
  118. return self::alias('w')->join('Questions q', 'w.questions_id=q.id')
  119. ->where(['w.uid' => $uid, 'w.id' => $id, 'q.is_del' => 0, 'w.is_del' => 0])
  120. ->field('w.*,q.option,q.stem,q.image,q.answer,q.difficulty,q.analysis,q.relation,q.question_type,q.is_img')
  121. ->order('w.add_time desc')->find();
  122. }
  123. /**错题掌握修改
  124. * @param $data
  125. * @param $uid
  126. * @return bool
  127. * @throws \think\db\exception\DataNotFoundException
  128. * @throws \think\db\exception\ModelNotFoundException
  129. * @throws \think\exception\DbException
  130. */
  131. public static function userSubmitWrongBank($data, $uid)
  132. {
  133. $wrong = self::where(['id' => $data['wrong_id'], 'questions_id' => $data['questions_id'], 'uid' => $uid])->find();
  134. if (!$wrong) return false;
  135. $dat['is_master'] = $data['is_master'];
  136. $res = self::edit($dat, $data['wrong_id']);
  137. return $res;
  138. }
  139. }