Correction.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace addons\exam\controller;
  3. use addons\exam\model\CorrectionQuestionModel;
  4. use app\admin\model\exam\CorrectionTypeModel;
  5. /**
  6. * 纠错接口
  7. */
  8. class Correction extends Base
  9. {
  10. protected $noNeedLogin = [''];
  11. protected $noNeedRight = ['*'];
  12. protected $user;
  13. /**
  14. * 纠错类型
  15. */
  16. public function types()
  17. {
  18. $types = CorrectionTypeModel::all();
  19. $this->success('', ['types' => $types]);
  20. }
  21. /**
  22. * 提交纠错
  23. */
  24. public function submit()
  25. {
  26. $question_id = input('question_id/d');
  27. // $type_ids = input('type_ids/a', []);
  28. $type_names = input('type_names/a', []);
  29. $remark = input('remark/s', '', 'trim,strip_tags,htmlspecialchars,xss_clean');
  30. if (!$question_id) {
  31. $this->error(__('缺少题目ID参数'));
  32. }
  33. // if (!$type_ids) {
  34. // $this->error(__('请选择纠错类型'));
  35. // }
  36. if (!$type_names) {
  37. $this->error(__('请选择纠错类型'));
  38. }
  39. CorrectionQuestionModel::create([
  40. 'user_id' => $this->auth->id,
  41. 'question_id' => $question_id,
  42. 'type_ids' => '',//implode(',', $type_ids),
  43. 'type_names' => implode(',', $type_names),
  44. 'remark' => $remark,
  45. ]);
  46. $this->success('提交成功,感谢您的反馈');
  47. }
  48. /**
  49. * 纠错反馈列表
  50. */
  51. public function lists()
  52. {
  53. $list = CorrectionQuestionModel::with([
  54. 'question' => function ($query) {
  55. $query->with([
  56. 'cates' => function ($query) {
  57. $query->field('id,name');
  58. },
  59. ])->field('id,cate_id,kind,title');
  60. }
  61. ])->where('user_id', $this->auth->id)->order('id', 'desc')->paginate(15, true);
  62. $this->success('', $list);
  63. }
  64. }