Screen.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. $this->whereExtend['user_depart_id'] = ['in', $ids];
  38. }
  39. $departmentdata = [];
  40. // $collectionlist = Db::name('real_exam')->where('exam_collection_type',3)
  41. // ->whereTime('starttime','year')
  42. // ->group('exam_collection_id')
  43. // ->field('exam_collection_id,exam_collection_name')
  44. // ->order('exam_collection_id desc')->select();
  45. // foreach ($collectionlist as $k => $v) {
  46. // $departmentdata[$v['exam_collection_id']] = $v['exam_collection_name'];
  47. // }
  48. $departlist = $this->departmodel->where('level',5)->select();
  49. foreach ($departlist as $k => $v) {
  50. $departmentdata[$v['id']] = $v['name'];
  51. }
  52. unset($v);
  53. $this->view->assign('departmentdata', $departmentdata);
  54. $this->view->assign('ids', $ids);
  55. }
  56. /**
  57. * 数字大屏接口
  58. */
  59. public function index()
  60. {
  61. //区队总数
  62. $where_depart['level'] = 5;
  63. $qudui_total = $this->departmodel->where($where_depart)->count();
  64. $this->assign('qudui_total', $qudui_total);
  65. //学员总数
  66. $where_xy['depart_id'] = ['>',0];
  67. $xy_total = $this->adminmodel->where($where_xy)->count();
  68. $this->assign('xy_total', $xy_total);
  69. //最高分
  70. $max = $this->model->where($this->whereExtend)->order('endtime desc')->max('total_score');
  71. $this->assignconfig('max', $max);
  72. //最低分
  73. $min = $this->model->where($this->whereExtend)->order('endtime desc')->min('total_score');
  74. $this->assignconfig('min',$min);
  75. //平均分
  76. //考试人数
  77. $exam_xueyuan_count = $this->model->where($this->whereExtend)->count();
  78. //考试总分
  79. $exam_xueyuan_total = $this->model->where($this->whereExtend)->sum('total_score');
  80. //考试总分/考试人数
  81. $exam_pjf = $exam_xueyuan_count>0?bcdiv($exam_xueyuan_total, $exam_xueyuan_count):0;
  82. $this->assignconfig('exam_pjf',$exam_pjf);
  83. //平均时长
  84. //考试总时长
  85. $exam_shichang = $this->model->where($this->whereExtend)->sum('exam_duration');
  86. $exam_pjsc = $exam_xueyuan_count>0? bcdiv($exam_shichang, $exam_xueyuan_count):0;
  87. $this->assignconfig('exam_pjsc',bcdiv($exam_pjsc,60));
  88. //学员成绩统计
  89. $xueyuan_chengji_tongji = $this->model->where($this->whereExtend)->where('total_score>0')->order('endtime desc')->limit(50)->select();
  90. $this->assign('xueyuan_chengji_tongji', $xueyuan_chengji_tongji);
  91. //各区队平均分分析
  92. $qudui_list = $this->model->where($this->whereExtend)->group('user_depart_id')->select();
  93. $qudui = [];
  94. foreach ($qudui_list as $k => $v) {
  95. $qudui_list[$k]['user_depart_name'] = $this->departmodel->where('id',$v['user_depart_id'])->value('name');
  96. //每个区队的考试人数
  97. $qudui_exam_count = $this->model->where('user_depart_id',$v['user_depart_id'])->count();
  98. //每个区队的总分
  99. $qudui_exam_total = $this->model->where('user_depart_id',$v['user_depart_id'])->sum('total_score');
  100. //每个区队的平均分
  101. $qudui_list[$k]['user_depart_pjf'] = bcdiv($qudui_exam_total,$qudui_exam_count);
  102. }
  103. unset($v);
  104. $this->assignconfig('qudui_list', $qudui_list);
  105. //区队平均分 年份
  106. $this->assignconfig('qudui_list_year', date('Y'));
  107. //本年度考试成绩平均分统计
  108. $collection_list = $this->model->where('exam_collection_type',3)->whereTime('starttime','year')->group('exam_collection_id')->order('exam_collection_id desc')->limit(6)->select();
  109. foreach($collection_list as $k=>$v){
  110. //每个考试的考试人数
  111. $collection_exam_count = $this->model->where('exam_collection_id',$v['exam_collection_id'])->count();
  112. //每个区队的总分
  113. $collection_exam_total = $this->model->where('exam_collection_id',$v['exam_collection_id'])->sum('total_score');
  114. //每个区队的平均分
  115. $collection_list[$k]['collection_pjf'] = bcdiv($collection_exam_total,$collection_exam_count);
  116. }
  117. $this->assignconfig('collection_list', $collection_list);
  118. //FZD048型侦毒器维修难点统计
  119. $fault_one = $this->faultmodel->where(['sim_type'=>'0001'])->field('fault_id,name')->select();
  120. foreach ($fault_one as $k1 => $val1){
  121. // if(strlen($val1['name'])>15){
  122. // $name = mb_strcut($val1['name'],0,15,'utf8')."...";
  123. // }else{
  124. // $name = $val1['name'];
  125. // }
  126. // $fault_one[$k1]['name'] = $name;
  127. //先查分配次数,在查错误率
  128. $error_total = Db::name('real_exam_fault')->where(['flag'=>1,'fault_id'=>$val1['fault_id'],'answer_right'=>2])->count();
  129. if($error_total==0){
  130. unset($fault_one[$k1]);
  131. continue;
  132. }
  133. $fault_one[$k1]['error_total'] = $error_total;
  134. }
  135. $fault_one = collection($fault_one)->toArray();
  136. if(count($fault_one)==1){
  137. array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);
  138. array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);
  139. array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);
  140. array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);
  141. }else if(count($fault_one)==2){
  142. array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);
  143. array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);
  144. array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);
  145. }else if(count($fault_one)==3){
  146. array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);
  147. array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);
  148. }else if(count($fault_one)==4){
  149. array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);
  150. }
  151. unset($val1);
  152. $vaccineCount = array_column($fault_one, 'error_total');
  153. array_multisort($vaccineCount,SORT_DESC,$fault_one);
  154. $largestFour = array_slice($fault_one, 0, 5); // 获取最大的四个值
  155. $one_static = $largestFour;
  156. $this->assignconfig('one_static', $one_static);
  157. //FZB006型毒剂报警器维修难点统计
  158. $fault_two = $this->faultmodel->where(['sim_type'=>'0002'])->field('fault_id,name')->select();
  159. foreach ($fault_two as $k1 => $val1){
  160. // if(strlen($val1['name'])>15){
  161. // $name = mb_strcut($val1['name'],0,15,'utf8')."...";
  162. // }else{
  163. // $name = $val1['name'];
  164. // }
  165. // $fault_two[$k1]['name'] = $name;
  166. //先查分配次数,在查错误率
  167. $error_total = Db::name('real_exam_fault')->where(['flag'=>1,'fault_id'=>$val1['fault_id'],'answer_right'=>2])->count();
  168. if($error_total==0){
  169. unset($fault_two[$k1]);
  170. continue;
  171. }
  172. $fault_two[$k1]['error_total'] = $error_total;
  173. }
  174. unset($val1);
  175. $fault_two = collection($fault_two)->toArray();
  176. if(count($fault_two)==1){
  177. array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);
  178. array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);
  179. array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);
  180. array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);
  181. }else if(count($fault_two)==2){
  182. array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);
  183. array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);
  184. array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);
  185. }else if(count($fault_two)==3){
  186. array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);
  187. array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);
  188. }else if(count($fault_two)==4){
  189. array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);
  190. }
  191. $vaccineCount = array_column($fault_two, 'error_total');
  192. array_multisort($vaccineCount,SORT_DESC,$fault_two);
  193. $largestFour = array_slice($fault_two, 0, 5); // 获取最大的四个值
  194. $two_static = $largestFour;
  195. $this->assignconfig('two_static', $two_static);
  196. //防化兵用毒剂报警器维修难点统计
  197. $fault_three = $this->faultmodel->where(['sim_type'=>'0003'])->field('fault_id,name')->select();
  198. foreach ($fault_three as $k1 => $val1){
  199. // if(strlen($val1['name'])>15){
  200. // $name = mb_strcut($val1['name'],0,15,'utf8')."...";
  201. // }else{
  202. // $name = $val1['name'];
  203. // }
  204. // $fault_three[$k1]['name'] = $name;
  205. //先查分配次数,在查错误率
  206. $error_total = Db::name('real_exam_fault')->where(['flag'=>1,'fault_id'=>$val1['fault_id'],'answer_right'=>2])->count();
  207. if($error_total==0){
  208. unset($fault_three[$k1]);
  209. continue;
  210. }
  211. $fault_three[$k1]['error_total'] = $error_total;
  212. }
  213. unset($val1);
  214. $fault_three = collection($fault_three)->toArray();
  215. if(count($fault_three)==1){
  216. array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);
  217. array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);
  218. array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);
  219. array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);
  220. }else if(count($fault_three)==2){
  221. array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);
  222. array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);
  223. array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);
  224. }else if(count($fault_three)==3){
  225. array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);
  226. array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);
  227. }else if(count($fault_three)==4){
  228. array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);
  229. }
  230. $vaccineCount = array_column($fault_three, 'error_total');
  231. array_multisort($vaccineCount,SORT_DESC,$fault_three);
  232. $largestFour = array_slice($fault_three, 0, 5); // 获取最大的四个值
  233. $three_static = $largestFour;
  234. $this->assignconfig('three_static', $three_static);
  235. return $this->view->fetch();
  236. }
  237. }