Exam.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace app\admin\controller\student;
  3. use app\admin\model\Fault;
  4. use app\admin\model\Report;
  5. use app\common\controller\Backend;
  6. use app\common\model\Config as ConfigModel;
  7. use think\Db;
  8. use app\admin\model\department\Department;
  9. /**
  10. * sim-考试表/成绩总分
  11. *
  12. * @icon fa fa-circle-o
  13. */
  14. class Exam extends Backend
  15. {
  16. /**
  17. * Exams模型对象
  18. * @var \app\admin\model\teacher\Exams
  19. */
  20. protected $model = null;
  21. protected $whereExtend = null;
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $this->model = new \app\admin\model\teacher\Exams;
  26. $groupIds = $this->auth->getGroupIds();
  27. //学员查看自己的
  28. if(in_array(8, $groupIds)){
  29. $this->whereExtend['user_id'] = $this->auth->id;
  30. }
  31. $this->assignconfig("groupIds", $groupIds[0]);
  32. $this->whereExtend['exam_collection_type'] = 3;
  33. $this->whereExtend['endtime'] = ['>',0];
  34. }
  35. /**
  36. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  37. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  38. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  39. */
  40. public function view($ids = null)
  41. {
  42. $row = Db::name('real_exam_score')->where('exam_id', $ids)->find();
  43. if (!$row) {
  44. $this->error(__('未交卷'));
  45. }
  46. $rows = $this->model->get($ids);
  47. $row['seat_id'] = $rows->seat_id;
  48. $row['user_nickname'] = $rows->user_nickname;
  49. $row['user_username'] = $rows->user_username;
  50. $row['user_depart_id'] = $rows->user_depart_id;
  51. $row['user_depart_name'] = Department::where('id',$rows->user_depart_id)->value('name');
  52. $row['start_time'] = $rows->start_time;
  53. $row['end_time'] = $rows->end_time;
  54. $fault_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  55. $row['fault_name_one'] = Fault::where('fault_id',$fault_list[0]['fault_id'])->value('name');
  56. $row['fault_name_two'] = Fault::where('fault_id',$fault_list[1]['fault_id'])->value('name');
  57. $row['fault_name_three'] = Fault::where('fault_id',$fault_list[2]['fault_id'])->value('name');
  58. $row['fault_score'] = 75-$row['fault_one_score']-$row['fault_two_score']-$row['fault_three_score'];
  59. $report_score = 15-$row['xianxian_score']-$row['yuanyin_socre']-$row['buwei_score']-$row['fangfa_score'];
  60. $row['report_score'] = $report_score>0?$report_score:0;
  61. $row['weixiu_score'] = 10-$row['overtime_score']??0;
  62. $other_jielun = !empty($row['other_jielun']) ? json_decode($row['other_jielun'],true):[];
  63. $this->view->assign('other_jielun', $other_jielun);
  64. $diffInSeconds = $rows['endtime'] - $rows['starttime']; // 两个时间戳之间的差异(秒)
  65. $minutes = floor($diffInSeconds / 60); // 计算分钟数
  66. $seconds = $diffInSeconds % 60; // 计算剩余的秒数
  67. $row['shijian'] = $minutes.'分'.$seconds.'秒';
  68. $this->view->assign('row', $row);
  69. return $this->view->fetch();
  70. }
  71. }