Screen.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Config;
  5. use think\Db;
  6. use think\db\Connection;
  7. use think\Request;
  8. /**
  9. * 数字大屏接口
  10. *
  11. * @icon fa fa-dashboard
  12. */
  13. class Screen extends Backend
  14. {
  15. protected $model = null;
  16. protected $departmodel = null;
  17. protected $adminmodel = null;
  18. protected $faultmodel = null;
  19. protected $layout = 'screen';
  20. protected $noNeedRight = ['index'];
  21. protected $whereExtend = null;
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $groupIds = $this->auth->getGroupIds();
  26. $this->model = new \app\admin\model\teacher\Exams;
  27. $this->departmodel = new \app\admin\model\department\Department;
  28. $this->adminmodel = new \app\admin\model\Admin;
  29. $this->faultmodel = new \app\admin\model\Fault;
  30. //已交卷
  31. $this->whereExtend['endtime'] = ['>', 0];
  32. //考试
  33. $this->whereExtend['exam_collection_type'] = 3;
  34. $ids = $this->request->get('ids', '');
  35. if(!empty($ids)){
  36. $this->whereExtend['exam_collection_id'] = ['in', $ids];
  37. }
  38. $departmentdata = [];
  39. $collectionlist = Db::name('real_exam')->where('exam_collection_type',3)
  40. ->whereTime('starttime','year')
  41. ->group('exam_collection_id')
  42. ->field('exam_collection_id,exam_collection_name')
  43. ->order('exam_collection_id desc')->select();
  44. foreach ($collectionlist as $k => $v) {
  45. $departmentdata[$v['exam_collection_id']] = $v['exam_collection_name'];
  46. }
  47. $this->view->assign('departmentdata', $departmentdata);
  48. $this->view->assign('ids', $ids);
  49. }
  50. /**
  51. * 数字大屏接口
  52. */
  53. public function index()
  54. {
  55. //区队总数
  56. $where_depart['level'] = 5;
  57. $qudui_total = $this->departmodel->where($where_depart)->count();
  58. $this->assign('qudui_total', $qudui_total);
  59. //学员总数
  60. $where_xy['depart_id'] = ['>',0];
  61. $xy_total = $this->adminmodel->where($where_xy)->count();
  62. $this->assign('xy_total', $xy_total);
  63. //最高分
  64. $max = $this->model->where($this->whereExtend)->order('endtime desc')->max('total_score');
  65. $this->assignconfig('max', $max);
  66. //最低分
  67. $min = $this->model->where($this->whereExtend)->order('endtime desc')->min('total_score');
  68. $this->assignconfig('min',$min);
  69. //平均分
  70. //考试人数
  71. $exam_xueyuan_count = $this->model->where($this->whereExtend)->count();
  72. //考试总分
  73. $exam_xueyuan_total = $this->model->where($this->whereExtend)->sum('total_score');
  74. //考试总分/考试人数
  75. $exam_pjf = $exam_xueyuan_count>0?bcdiv($exam_xueyuan_total, $exam_xueyuan_count):0;
  76. $this->assignconfig('exam_pjf',$exam_pjf);
  77. //平均时长
  78. //考试总时长
  79. $exam_shichang = $this->model->where($this->whereExtend)->sum('exam_duration');
  80. $exam_pjsc = $exam_xueyuan_count>0? bcdiv($exam_shichang, $exam_xueyuan_count):0;
  81. $this->assignconfig('exam_pjsc',bcdiv($exam_pjsc,60));
  82. //学员成绩统计
  83. $xueyuan_chengji_tongji = $this->model->where($this->whereExtend)->where('total_score>0')->order('endtime desc')->limit(50)->select();
  84. $this->assign('xueyuan_chengji_tongji', $xueyuan_chengji_tongji);
  85. //各区队平均分分析
  86. $qudui_list = $this->model->where($this->whereExtend)->group('user_depart_id')->select();
  87. $qudui = [];
  88. foreach ($qudui_list as $k => $v) {
  89. $qudui_list[$k]['user_depart_name'] = $this->departmodel->where('id',$v['user_depart_id'])->value('name');
  90. //每个区队的考试人数
  91. $qudui_exam_count = $this->model->where('user_depart_id',$v['user_depart_id'])->count();
  92. //每个区队的总分
  93. $qudui_exam_total = $this->model->where('user_depart_id',$v['user_depart_id'])->sum('total_score');
  94. //每个区队的平均分
  95. $qudui_list[$k]['user_depart_pjf'] = bcdiv($qudui_exam_total,$qudui_exam_count);
  96. }
  97. unset($v);
  98. $this->assignconfig('qudui_list', $qudui_list);
  99. //区队平均分 年份
  100. $this->assignconfig('qudui_list_year', date('Y'));
  101. //本年度考试成绩平均分统计
  102. $collection_list = $this->model->where('exam_collection_type',3)->whereTime('starttime','year')->group('exam_collection_id')->order('exam_collection_id desc')->limit(6)->select();
  103. foreach($collection_list as $k=>$v){
  104. //每个考试的考试人数
  105. $collection_exam_count = $this->model->where('exam_collection_id',$v['exam_collection_id'])->count();
  106. //每个区队的总分
  107. $collection_exam_total = $this->model->where('exam_collection_id',$v['exam_collection_id'])->sum('total_score');
  108. //每个区队的平均分
  109. $collection_list[$k]['collection_pjf'] = bcdiv($collection_exam_total,$collection_exam_count);
  110. }
  111. $this->assignconfig('collection_list', $collection_list);
  112. //FZD048型侦毒器维修难点统计
  113. $fault_one = $this->faultmodel->where(['sim_type'=>'0001'])->field('fault_id,name')->select();
  114. foreach ($fault_one as $k1 => $val1){
  115. // if(strlen($val1['name'])>15){
  116. // $name = mb_strcut($val1['name'],0,15,'utf8')."...";
  117. // }else{
  118. // $name = $val1['name'];
  119. // }
  120. // $fault_one[$k1]['name'] = $name;
  121. //先查分配次数,在查错误率
  122. $error_total = Db::name('real_exam_fault')->where(['flag'=>1,'fault_id'=>$val1['fault_id'],'answer_right'=>2])->count();
  123. $fault_one[$k1]['error_total'] = $error_total;
  124. }
  125. unset($val1);
  126. $vaccineCount = array_column($fault_one, 'error_total');
  127. array_multisort($vaccineCount,SORT_DESC,$fault_one);
  128. $largestFour = array_slice($fault_one, 0, 5); // 获取最大的四个值
  129. $one_static = $largestFour;
  130. $this->assignconfig('one_static', $one_static);
  131. //FZB006型毒剂报警器维修难点统计
  132. $fault_two = $this->faultmodel->where(['sim_type'=>'0002'])->field('fault_id,name')->select();
  133. foreach ($fault_two as $k1 => $val1){
  134. // if(strlen($val1['name'])>15){
  135. // $name = mb_strcut($val1['name'],0,15,'utf8')."...";
  136. // }else{
  137. // $name = $val1['name'];
  138. // }
  139. // $fault_two[$k1]['name'] = $name;
  140. //先查分配次数,在查错误率
  141. $error_total = Db::name('real_exam_fault')->where(['flag'=>1,'fault_id'=>$val1['fault_id'],'answer_right'=>2])->count();
  142. $fault_two[$k1]['error_total'] = $error_total;
  143. }
  144. unset($val1);
  145. $vaccineCount = array_column($fault_two, 'error_total');
  146. array_multisort($vaccineCount,SORT_DESC,$fault_two);
  147. $largestFour = array_slice($fault_two, 0, 5); // 获取最大的四个值
  148. $two_static = $largestFour;
  149. $this->assignconfig('two_static', $two_static);
  150. //防化兵用毒剂报警器维修难点统计
  151. $fault_three = $this->faultmodel->where(['sim_type'=>'0003'])->field('fault_id,name')->select();
  152. foreach ($fault_three as $k1 => $val1){
  153. // if(strlen($val1['name'])>15){
  154. // $name = mb_strcut($val1['name'],0,15,'utf8')."...";
  155. // }else{
  156. // $name = $val1['name'];
  157. // }
  158. // $fault_three[$k1]['name'] = $name;
  159. //先查分配次数,在查错误率
  160. $error_total = Db::name('real_exam_fault')->where(['flag'=>1,'fault_id'=>$val1['fault_id'],'answer_right'=>2])->count();
  161. $fault_three[$k1]['error_total'] = $error_total;
  162. }
  163. unset($val1);
  164. $vaccineCount = array_column($fault_three, 'error_total');
  165. array_multisort($vaccineCount,SORT_DESC,$fault_three);
  166. $largestFour = array_slice($fault_three, 0, 5); // 获取最大的四个值
  167. $three_static = $largestFour;
  168. $this->assignconfig('three_static', $three_static);
  169. return $this->view->fetch();
  170. }
  171. }