Collection.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <?php
  2. namespace app\admin\controller\student;
  3. use app\common\controller\Backend;
  4. use app\common\model\Config as ConfigModel;
  5. use app\admin\model\Report;
  6. use app\admin\model\Fault;
  7. use think\exception\DbException;
  8. use think\exception\PDOException;
  9. use think\exception\ValidateException;
  10. use think\response\Json;
  11. use think\Db;
  12. /**
  13. * sim-考试集合管理
  14. *
  15. * @icon fa fa-circle-o
  16. */
  17. class Collection extends Backend
  18. {
  19. /**
  20. * Collection模型对象
  21. * @var \app\admin\model\teacher\Collection
  22. */
  23. protected $model = null;
  24. protected $exam_model = null;
  25. protected $whereExtend = null;
  26. public function _initialize()
  27. {
  28. parent::_initialize();
  29. $this->model = new \app\admin\model\teacher\Collection;
  30. $this->exam_model = new \app\admin\model\teacher\Exams;
  31. $this->assignConfig('sim_sim_type', ConfigModel::getSimTypeList());
  32. $this->assignConfig('sim_question_setting_method', ConfigModel::getSimQuestionList());
  33. $this->whereExtend['exam_collection_type'] = 3;
  34. $this->whereExtend['exam_collection_state'] = 2;
  35. $this->assignConfig('sim_sim_type', ConfigModel::getSimTypeList());
  36. $groupIds = $this->auth->getGroupIds();
  37. //学员查看自己区队的考试集合
  38. if(in_array(8, $groupIds)){
  39. $departid = $this->auth->depart_id;
  40. $this->whereExtend[] = ['exp',Db::raw("FIND_IN_SET($departid,depart_ids)")];
  41. }
  42. }
  43. /**
  44. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  45. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  46. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  47. */
  48. /**
  49. * 查看
  50. *
  51. * @return string|Json
  52. * @throws \think\Exception
  53. * @throws DbException
  54. */
  55. public function index()
  56. {
  57. $isset = $this->model->alias('z')
  58. ->join('real_exam r','z.exam_collection_id=r.exam_collection_id','left')
  59. ->where('z.exam_collection_type=3 and z.exam_collection_state=2 and r.endtime=0 and r.user_id='.$this->auth->id)->find();
  60. // halt($this->model->getLastSql());
  61. if(empty($isset)){
  62. //提示页面,没有开始的考试
  63. return $this->view->fetch('tishi');
  64. }else{
  65. //// $this->redirect('/ZQOtIMLKud.php/student/collection/examing/ids/'.$isset['exam_id'].'?ref=addtabs');
  66. // echo "<script>location.href='/ZQOtIMLKud.php/student/collection/examing/ids/".$isset['exam_id']."';</script>";
  67. // //$this->redirect('/hotelmanage/room/displayindex/ids/1');
  68. // exit();
  69. echo "<script>location.href='/ZQOtIMLKud.php/student/collection/into/ids/".$isset['exam_collection_id']."'</script>";
  70. }
  71. die();
  72. //设置过滤方法
  73. $this->request->filter(['strip_tags', 'trim']);
  74. if (false === $this->request->isAjax()) {
  75. return $this->view->fetch();
  76. }
  77. //如果发送的来源是 Selectpage,则转发到 Selectpage
  78. if ($this->request->request('keyField')) {
  79. return $this->selectpage();
  80. }
  81. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  82. $list = $this->model
  83. ->where($where)->where($this->whereExtend)
  84. ->order($sort, $order)
  85. ->paginate($limit);
  86. foreach ($list as $k => $v){
  87. $exam_isset = $this->exam_model->where(['user_id'=>$this->auth->id,'exam_collection_id'=>$v['exam_collection_id'],'exam_collection_type'=>3,'endtime'=>['>',0]])->find();
  88. if(isset($exam_isset)){
  89. $v->is_user_examed = 1;
  90. }else{
  91. $v->is_user_examed = 0;
  92. }
  93. }
  94. unset($v);
  95. $result = ['total' => $list->total(), 'rows' => $list->items()];
  96. return json($result);
  97. }
  98. //进入考试
  99. public function into($ids = null)
  100. {
  101. $row = $this->model->get($ids);
  102. if(!$row){
  103. $this->error('未找到记录');
  104. }
  105. $info = $this->exam_model->where(['user_id'=>$this->auth->id,'exam_collection_id'=>$ids,'exam_collection_type'=>3,'endtime'=>0])->find();
  106. if(!empty($info)){
  107. $this->exam_model->where('exam_id',$info['exam_id'])->update(['seat_id'=>$this->auth->seat_id,'sim_id'=>$this->auth->sim_id]);
  108. $sim = Db::name('sim')->where('seat_id',$this->auth->seat_id)->find();
  109. $sim_text = '';
  110. // 模拟器状态 0:可用初始化 1:在线 2:模拟器离线 3:网关离线 4:硬件故障异常 5:手动禁用
  111. if($sim['sim_state']==1){
  112. $sim_text = '在线';
  113. }else if($sim['sim_state']==2){
  114. $sim_text = '模拟器离线';
  115. }else if($sim['sim_state']==3){
  116. $sim_text = '网关离线';
  117. }else if($sim['sim_state']==4){
  118. $sim_text = '硬件故障异常';
  119. }else if($sim['sim_state']==5){
  120. $sim_text = '手动禁用';
  121. }
  122. $info['sim_text'] = $sim_text;
  123. }
  124. if(!empty($info['starttime']))
  125. {
  126. echo "<script>location.href='/ZQOtIMLKud.php/student/collection/examing/ids/".$info['exam_id']."'</script>";
  127. die();
  128. }
  129. if ($this->request->isPost()) {
  130. // $exam_collection_id = $this->request->post('exam_collection_id');
  131. // if(empty($info->starttime)){
  132. // $info->start_time = date('Y-m-d H:i:s');
  133. // $info->starttime = time();
  134. // }
  135. // $info->exam_status = 4;
  136. // $info->save();
  137. // $this->success('开始成功','/ZQOtIMLKud.php/student/collection/examing/ids/'.$info['exam_id']);
  138. }
  139. $this->view->assign('info', $info);
  140. $this->view->assign('row', $row);
  141. $this->assignConfig('exam_id', $info['exam_id']);
  142. return $this->view->fetch();
  143. }
  144. public function examing($ids = null)
  145. {
  146. $row = $this->exam_model->get($ids);
  147. if(!$row){
  148. $this->error('未找到记录');
  149. }
  150. if ($this->request->isPost()) {
  151. //先请求接口判断,再进行处理
  152. //计算分数,保存记录
  153. $params = $this->request->post('row/a');
  154. $result = false;
  155. $score = 100;
  156. $fault_one_score = 25;
  157. $fault_two_score = 25;
  158. $fault_three_score = 25;
  159. $xianxian_score = 0;
  160. $yuanyin_socre= 0;
  161. $buwei_score= 0;
  162. $fangfa_score= 0;
  163. $jielun_score = 0;
  164. Db::startTrans();
  165. try {
  166. //更新考试结束时间
  167. $row->end_time = date('Y-m-d H:i:s');
  168. $row->endtime = time();
  169. $row->exam_status = 5;
  170. $row->other_report = $params['other_report'];
  171. $result = $row->save();
  172. $info = $this->exam_model->where(['exam_id'=>$ids])->find();
  173. //计算得分,故障是否有扣分 扣分制
  174. $fault_right_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1,'answer_right'=>['>',0]])->select();
  175. if(!empty($fault_right_list)){
  176. if($fault_right_list[0]['answer_right']==1){
  177. $fault_one_score = 0;
  178. }
  179. if($fault_right_list[1]['answer_right']==1){
  180. $fault_two_score = 0;
  181. }
  182. if($fault_right_list[2]['answer_right']==1){
  183. $fault_three_score = 0;
  184. }
  185. }
  186. $xianxian_score = rand(1,3);
  187. $yuanyin_socre= rand(1,3);
  188. $buwei_score= rand(1,3);
  189. $fangfa_score= rand(1,3);
  190. // if(empty($params['other_jielun'])){
  191. // $jielun_score = rand(1,3);
  192. // }
  193. //是否超时
  194. $overtime_fen = intval((time()-$info['endtime']) / 60);
  195. if($overtime_fen>=10){
  196. $overtime_score = 10;
  197. }else if($overtime_fen>0 && $overtime_fen<10){
  198. $overtime_score = $overtime_fen ;
  199. }else{
  200. $overtime_score =0;
  201. }
  202. $fault_score = $score-$fault_one_score-$fault_two_score-$fault_three_score-$xianxian_score-$yuanyin_socre-$buwei_score-$fangfa_score-$overtime_score;
  203. //更新考试结果表
  204. $params['exam_id'] = $ids;
  205. $params['total'] = $fault_score;//得分;
  206. $params['fault_one_score'] = $fault_one_score;//得分;
  207. $params['fault_two_score'] = $fault_two_score;//得分;
  208. $params['fault_three_score'] = $fault_three_score;//得分;
  209. $params['xianxian_score'] = $xianxian_score;//得分;
  210. $params['yuanyin_socre'] = $yuanyin_socre;//得分;
  211. $params['buwei_score'] = $buwei_score;//得分;
  212. $params['fangfa_score'] = $fangfa_score;//得分;
  213. // $params['jielun_score'] = $jielun_score;//得分;
  214. $params['overtime_score'] = $overtime_score;//得分;
  215. Db::name('real_exam_score')->insert($params);
  216. $this->exam_model->where(['exam_id'=>$ids])->update(['total_score'=>$fault_score]);
  217. Db::commit();
  218. } catch (ValidateException|PDOException|Exception $e) {
  219. Db::rollback();
  220. $this->error($e->getMessage());
  221. }
  222. if ($result === false) {
  223. $this->error(__('No rows were inserted'));
  224. }
  225. $this->success('交卷成功,待老师确认成绩','/ZQOtIMLKud.php/student/exam/index');
  226. }
  227. if(empty($row->starttime)){
  228. $row->start_time = date('Y-m-d H:i:s');
  229. $row->starttime = time();
  230. $row->exam_status = 4;
  231. $row->save();
  232. }
  233. if(empty($row->other_replace)){
  234. $row->other_replace = '[{"fault_id":"","request_status":"0"}]';
  235. }
  236. if(empty($row->other_report)){
  237. $row->other_report = '[{"xx_id":"","yy_id":"","bw_id":"","pc_id":""}]';
  238. }
  239. //还未开始考试
  240. $row->limit_duration = $this->model->where(['exam_collection_id'=>$row['exam_collection_id']])->value('limit_duration');
  241. if(empty($row->starttime)){
  242. $timer = 60*$row->limit_duration;
  243. }else{
  244. $fen = $row->limit_duration - intval((time()-$row->starttime) / 60);
  245. $timer = 60*$fen;
  246. }
  247. $row->replace_list =Db::name('real_exam_comp_request')->where(['exam_id'=>$ids])->select();
  248. $this->assignConfig('ids',$ids);
  249. $this->assignConfig('timer',$timer);
  250. $this->view->assign('row', $row);
  251. $departmentdata = [];
  252. $departmentdata = Fault::where(['replace_part'=>1,'sim_type'=>$row->sim_type])->order('fault_id asc')->select();
  253. //更换件数据
  254. $this->view->assign('departmentdata', $departmentdata);
  255. //故障现象
  256. $xianxiang = Fault::where(['fault_type'=>1,'sim_type'=>$row->sim_type])->select();
  257. $this->view->assign('xianxiang', $xianxiang);
  258. //可能原因
  259. $yuanyin = Fault::where(['fault_type'=>2,'sim_type'=>$row->sim_type])->select();
  260. $this->view->assign('yuanyin', $yuanyin);
  261. //故障部位
  262. $buwei = Fault::where(['fault_type'=>3,'sim_type'=>$row->sim_type])->select();
  263. $this->view->assign('buwei', $buwei);
  264. //排除方法
  265. $paichu = Fault::where(['fault_type'=>4,'sim_type'=>$row->sim_type])->select();
  266. $this->view->assign('paichu', $paichu);
  267. return $this->view->fetch();
  268. }
  269. public function replace($ids = null)
  270. {
  271. if ($this->request->isPost()) {
  272. $params = $this->request->post('other_replace','');
  273. $param = json_decode($params,true);
  274. if(!empty($param)){
  275. foreach ($param as $key=>$item){
  276. $isreplace = Db::name('real_exam_comp_request')->where(['exam_id'=>$ids,'fault_id'=>$item['fault_id']])->find();
  277. if(empty($isreplace)){
  278. $add = [
  279. 'exam_id'=>$ids,
  280. 'fault_id'=>$item['fault_id'],
  281. 'request_status'=>1,
  282. 'fault_name'=>Db::name('fault')->where('fault_id',$item['fault_id'])->value('replace_name'),
  283. 'create_by_user_id'=>$this->auth->id,
  284. 'create_by'=>$this->auth->nickname,
  285. 'createtime'=>time(),
  286. 'updatetime'=>time(),
  287. 'create_time'=>date('Y-m-d H:i:s'),
  288. 'update_time'=>date('Y-m-d H:i:s'),
  289. ];
  290. Db::name('real_exam_comp_request')->insert($add);
  291. $status = 1;
  292. }else{
  293. $status = $isreplace['request_status'];
  294. }
  295. $faultid_arr[] = [
  296. 'fault_id'=>$item['fault_id'],
  297. 'request_status'=>$status,
  298. ];
  299. }
  300. unset($item);
  301. $row = $this->exam_model->get($ids);
  302. $row-> other_replace = json_encode($faultid_arr);
  303. $result = $row->save();
  304. }
  305. $this->success('申请成功,待老师审批');
  306. }
  307. }
  308. public function analysis($ids = null)
  309. {
  310. $row = $this->exam_model->get($ids);
  311. if(!$row){
  312. $this->error('未找到记录');
  313. }
  314. if ($this->request->isPost()) {
  315. $params = $this->request->post('row/a');
  316. //计算总分到学员考试表
  317. $this->success('操作成功','/ZQOtIMLKud.php/student/collection/index');
  318. }
  319. return $this->view->fetch();
  320. }
  321. }