| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 | <?phpnamespace app\admin\controller;use app\common\controller\Backend;use think\Config;use think\Db;use think\db\Connection;use think\Request;/** * 数字大屏接口 * * @icon fa fa-dashboard */class Screen extends Backend{    protected $model = null;    protected $departmodel = null;    protected $adminmodel = null;    protected $faultmodel = null;    protected $layout = 'screen';    protected $noNeedRight = ['index'];    protected $whereExtend = null;    public function _initialize()    {        parent::_initialize();        $groupIds = $this->auth->getGroupIds();        $this->model = new \app\admin\model\teacher\Exams;        $this->departmodel = new \app\admin\model\department\Department;        $this->adminmodel = new \app\admin\model\Admin;        $this->faultmodel = new \app\admin\model\Fault;        //已交卷        $this->whereExtend['endtime'] = ['>', 0];        //考试        $this->whereExtend['exam_collection_type'] = 3;        $ids = $this->request->get('ids', '');        if(!empty($ids)){//            $this->whereExtend['exam_collection_id'] = ['in', $ids];            $this->whereExtend['user_depart_id'] = ['in', $ids];        }        $departmentdata = [];//        $collectionlist = Db::name('real_exam')->where('exam_collection_type',3)//            ->whereTime('starttime','year')//            ->group('exam_collection_id')//            ->field('exam_collection_id,exam_collection_name')//            ->order('exam_collection_id desc')->select();//        foreach ($collectionlist as $k => $v) {//            $departmentdata[$v['exam_collection_id']] = $v['exam_collection_name'];//        }        $departlist =  $this->departmodel->where('level',5)->select();        foreach ($departlist as $k => $v) {            $departmentdata[$v['id']] = $v['name'];        }        unset($v);        $this->view->assign('departmentdata', $departmentdata);        $this->view->assign('ids', $ids);    }    /**     * 数字大屏接口     */    public function index()    {        //区队总数        $where_depart['level'] = 5;        $qudui_total = $this->departmodel->where($where_depart)->count();        $this->assign('qudui_total', $qudui_total);        //学员总数        $where_xy['depart_id'] = ['>',0];        $xy_total = $this->adminmodel->where($where_xy)->count();        $this->assign('xy_total', $xy_total);        //最高分        $max = $this->model->where($this->whereExtend)->order('endtime desc')->max('total_score');        $this->assignconfig('max', $max);        //最低分        $min = $this->model->where($this->whereExtend)->order('endtime desc')->min('total_score');        $this->assignconfig('min',$min);        //平均分        //考试人数        $exam_xueyuan_count = $this->model->where($this->whereExtend)->count();        //考试总分        $exam_xueyuan_total = $this->model->where($this->whereExtend)->sum('total_score');        //考试总分/考试人数        $exam_pjf = $exam_xueyuan_count>0?bcdiv($exam_xueyuan_total, $exam_xueyuan_count):0;        $this->assignconfig('exam_pjf',$exam_pjf);        //平均时长        //考试总时长        $exam_shichang = $this->model->where($this->whereExtend)->sum('exam_duration');        $exam_pjsc = $exam_xueyuan_count>0? bcdiv($exam_shichang, $exam_xueyuan_count):0;        $this->assignconfig('exam_pjsc',bcdiv($exam_pjsc,60));        //学员成绩统计        $xueyuan_chengji_tongji = $this->model->where($this->whereExtend)->where('total_score>0')->order('endtime desc')->limit(50)->select();        $this->assign('xueyuan_chengji_tongji', $xueyuan_chengji_tongji);        //各区队平均分分析        $qudui_list = $this->model->where($this->whereExtend)->group('user_depart_id')->select();        $qudui = [];        foreach ($qudui_list as $k => $v) {            $qudui_list[$k]['user_depart_name'] = $this->departmodel->where('id',$v['user_depart_id'])->value('name');            //每个区队的考试人数            $qudui_exam_count = $this->model->where('user_depart_id',$v['user_depart_id'])->count();            //每个区队的总分            $qudui_exam_total = $this->model->where('user_depart_id',$v['user_depart_id'])->sum('total_score');            //每个区队的平均分            $qudui_list[$k]['user_depart_pjf'] = bcdiv($qudui_exam_total,$qudui_exam_count);        }        unset($v);        $this->assignconfig('qudui_list', $qudui_list);        //区队平均分 年份        $this->assignconfig('qudui_list_year', date('Y'));        //本年度考试成绩平均分统计        $collection_list = $this->model->where('exam_collection_type',3)->whereTime('starttime','year')->group('exam_collection_id')->order('exam_collection_id desc')->limit(6)->select();        foreach($collection_list as $k=>$v){            //每个考试的考试人数            $collection_exam_count = $this->model->where('exam_collection_id',$v['exam_collection_id'])->count();            //每个区队的总分            $collection_exam_total = $this->model->where('exam_collection_id',$v['exam_collection_id'])->sum('total_score');            //每个区队的平均分            $collection_list[$k]['collection_pjf'] = bcdiv($collection_exam_total,$collection_exam_count);        }        $this->assignconfig('collection_list', $collection_list);        //FZD048型侦毒器维修难点统计        $fault_one = $this->faultmodel->where(['sim_type'=>'0001'])->field('fault_id,name')->select();        foreach ($fault_one as $k1 => $val1){//            if(strlen($val1['name'])>15){//                $name =  mb_strcut($val1['name'],0,15,'utf8')."...";//            }else{//                $name = $val1['name'];//            }//            $fault_one[$k1]['name'] = $name;            //先查分配次数,在查错误率            $error_total = Db::name('real_exam_fault')->where(['flag'=>1,'fault_id'=>$val1['fault_id'],'answer_right'=>2])->count();            if($error_total==0){                unset($fault_one[$k1]);                continue;            }            $fault_one[$k1]['error_total'] = $error_total;        }        $fault_one = collection($fault_one)->toArray();        if(count($fault_one)==1){            array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);            array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);            array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);            array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);        }else if(count($fault_one)==2){            array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);            array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);            array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);        }else if(count($fault_one)==3){            array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);            array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);        }else if(count($fault_one)==4){            array_push($fault_one,['fault_id'=>'','name'=>'','error_total'=>0]);        }        unset($val1);        $vaccineCount = array_column($fault_one, 'error_total');        array_multisort($vaccineCount,SORT_DESC,$fault_one);        $largestFour = array_slice($fault_one, 0, 5); // 获取最大的四个值        $one_static = $largestFour;        $this->assignconfig('one_static', $one_static);        //FZB006型毒剂报警器维修难点统计        $fault_two = $this->faultmodel->where(['sim_type'=>'0002'])->field('fault_id,name')->select();        foreach ($fault_two as $k1 => $val1){//            if(strlen($val1['name'])>15){//                $name =  mb_strcut($val1['name'],0,15,'utf8')."...";//            }else{//                $name = $val1['name'];//            }//            $fault_two[$k1]['name'] = $name;            //先查分配次数,在查错误率            $error_total = Db::name('real_exam_fault')->where(['flag'=>1,'fault_id'=>$val1['fault_id'],'answer_right'=>2])->count();            if($error_total==0){                unset($fault_two[$k1]);                continue;            }            $fault_two[$k1]['error_total'] = $error_total;        }        unset($val1);        $fault_two = collection($fault_two)->toArray();        if(count($fault_two)==1){            array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);            array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);            array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);            array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);        }else if(count($fault_two)==2){            array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);            array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);            array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);        }else if(count($fault_two)==3){            array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);            array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);        }else if(count($fault_two)==4){            array_push($fault_two,['fault_id'=>'','name'=>'','error_total'=>0]);        }        $vaccineCount = array_column($fault_two, 'error_total');        array_multisort($vaccineCount,SORT_DESC,$fault_two);        $largestFour = array_slice($fault_two, 0, 5); // 获取最大的四个值        $two_static = $largestFour;        $this->assignconfig('two_static', $two_static);        //防化兵用毒剂报警器维修难点统计        $fault_three = $this->faultmodel->where(['sim_type'=>'0003'])->field('fault_id,name')->select();        foreach ($fault_three as $k1 => $val1){//            if(strlen($val1['name'])>15){//                $name =  mb_strcut($val1['name'],0,15,'utf8')."...";//            }else{//                $name = $val1['name'];//            }//            $fault_three[$k1]['name'] = $name;            //先查分配次数,在查错误率            $error_total = Db::name('real_exam_fault')->where(['flag'=>1,'fault_id'=>$val1['fault_id'],'answer_right'=>2])->count();            if($error_total==0){                unset($fault_three[$k1]);                continue;            }            $fault_three[$k1]['error_total'] = $error_total;        }        unset($val1);        $fault_three = collection($fault_three)->toArray();        if(count($fault_three)==1){            array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);            array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);            array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);            array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);        }else if(count($fault_three)==2){            array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);            array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);            array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);        }else if(count($fault_three)==3){            array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);            array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);        }else if(count($fault_three)==4){            array_push($fault_three,['fault_id'=>'','name'=>'','error_total'=>0]);        }        $vaccineCount = array_column($fault_three, 'error_total');        array_multisort($vaccineCount,SORT_DESC,$fault_three);        $largestFour = array_slice($fault_three, 0, 5); // 获取最大的四个值        $three_static = $largestFour;        $this->assignconfig('three_static', $three_static);        return $this->view->fetch();    }}
 |