Exam.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. $row['weixiu_score'] = 10-$row['overtime_score']??0;
  60. $other_jielun = !empty($row['other_jielun']) ? json_decode($row['other_jielun'],true):[];
  61. $koufen = 0;
  62. foreach ($other_jielun as $key => $value) {
  63. if(!empty($value['cx_score'])){
  64. $koufen = $koufen+abs($value['cx_score']);
  65. }
  66. }
  67. $report_score = 15-$koufen;
  68. $row['report_score'] = $report_score>0?$report_score:0;
  69. $total = $row['fault_score']+$row['report_score']+$row['weixiu_score'];
  70. Db::name('real_exam_score')->where('exam_id', $ids)->update(['total'=>$total]);
  71. Db::name('real_exam')->where('exam_id', $ids)->update(['total_score'=>$total]);
  72. $row['total'] = $total;
  73. $this->view->assign('other_jielun', $other_jielun);
  74. $diffInSeconds = $rows['endtime'] - $rows['starttime']; // 两个时间戳之间的差异(秒)
  75. $minutes = floor($diffInSeconds / 60); // 计算分钟数
  76. $seconds = $diffInSeconds % 60; // 计算剩余的秒数
  77. $row['shijian'] = $minutes.'分'.$seconds.'秒';
  78. $this->view->assign('row', $row);
  79. return $this->view->fetch();
  80. }
  81. }