header('统计'); $content->description('微考试信息'); $start_time = $request->get('start_time'); $stop_time = $request->get('stop_time'); $content->row(function ($row) use ($request) { $school_num = School::count(); $sclass_num = Sclass::count(); $student_num = User::count(); $question_num = Question::count(); $art_count = Article::count(); $exam_count = Examarg::count(); //$row->column(2, new InfoBox('总项目数', 'users', 'aqua', '/demo/users', Project::filter($request)->count('*'))); $row->column(2, new InfoBox('学校数量', 'bank', 'green', '/admin/school', $school_num)); $row->column(2, new InfoBox('班级数量', 'asl-interpreting', 'red', '/admin/sclass', $sclass_num)); $row->column(2, new InfoBox('学生数量', 'graduation-cap', 'yellow', '/admin/users', $student_num)); $row->column(2, new InfoBox('试卷数', 'twitch', 'purple', '/admin/examarg', $exam_count)); $row->column(2, new InfoBox('题目数量', 'file-text', 'purple', '/admin/question', $question_num)); $row->column(2, new InfoBox('文章总数', 'bars', 'purple', '/admin/article', $art_count)); }); $bills = (User::get([DB::raw('DATE_FORMAT(created_at,"%Y-%m") as ym'), DB::raw('DATE_FORMAT(created_at,"%Y") as year'), DB::raw('DATE_FORMAT(created_at,"%m") as month')])); $content->row(function ($row) use ($bills) { $studentCount = collect($bills)->groupBy('ym')->map(function ($v, $k) { // Salary::where('time', 'like', "{$k}%")->where('ac', 'F')->sum('money') return (collect($v)->count() + 0); })->toArray(); $keys = array_keys(array_flip(array_keys($studentCount))); $row->column(12, view('admin.charts.line', [ 'title' => '每月学生增加数', 'come' => ($this->getValue($studentCount, $keys)), 'keys' => $keys ])); }); $school = (School::get([DB::raw('DATE_FORMAT(created_at,"%Y-%m") as ym'), DB::raw('DATE_FORMAT(created_at,"%Y") as year'), DB::raw('DATE_FORMAT(created_at,"%m") as month'), DB::raw('schools.*')])); $sclass = (Sclass::get([DB::raw('DATE_FORMAT(created_at,"%Y-%m") as ym'), DB::raw('DATE_FORMAT(created_at,"%Y") as year'), DB::raw('DATE_FORMAT(created_at,"%m") as month')])); $article = (Article::get([DB::raw('DATE_FORMAT(created_at,"%Y-%m") as ym'), DB::raw('DATE_FORMAT(created_at,"%Y") as year'), DB::raw('DATE_FORMAT(created_at,"%m") as month'), DB::raw('articles.*')])); $content->row(function ($row) use ($school, $sclass, $article) { $scloo_num = collect($school)->groupBy('ym')->map(function ($v, $k) { return (collect($v)->count() + 0); })->toArray(); $sclass_num = collect($sclass)->groupBy('ym')->map(function ($v, $k) { // Salary::where('time', 'like', "{$k}%")->where('ac', 'F')->sum('money') return (collect($v)->count() + 0); })->toArray(); $article_num = collect($article)->groupBy('ym')->map(function ($v, $k) { // Salary::where('time', 'like', "{$k}%")->where('ac', 'F')->sum('money') return (collect($v)->count() + 0); })->toArray(); $keys = array_keys(array_flip(array_keys($article_num))); $row->column(12, view('admin.charts.sline', [ 'title' => '每月学校班级等增加数', 'school' => ($this->getValue($scloo_num, $keys)), "sclass" => ($this->getValue($sclass_num, $keys)), "article" => ($this->getValue($article_num, $keys)), 'keys' => $keys, ])); }); }); } public function getValue($arr, $keys) { return collect($keys)->map(function ($v) use ($arr) { return isset($arr[$v]) ? $arr[$v] : 0; })->values(); } public function getSchoolApi(Request $request) { $q = $request->get('q'); return School::where('name', 'like', "%$q%")->paginate(null, ['id', 'name as text']); } public function getClassApi(Request $request) { $q = $request->get('q'); return Sclass::where('school_id', $q)->select('id', 'name as text')->get(); } public function getArticleTypeApi(Request $request) { return Articletype::select('id', 'name as text')->get(); } public function getExams() { return Exam::select('id', 'name as text')->get(); } public function getSchoolSclass() { $allsclass = Sclass::get(); $selectdata = []; foreach ($allsclass as $key => $value) { $selectdata[] = array( 'id' => $value['id'], "text" => $value['school']['name'] . '-' . $value['name'] ); } return $selectdata; } protected function upload(Request $request) { //图片存储方法。如果为图片存起来。如果不是返回'' $fileCharater = $request->file('file'); if (!$fileCharater) { $msg = '请选择上传文件'; return view('admin.tools.excelskip', compact('msg')); } if ($fileCharater->isValid()) { //括号里面的是必须加的哦 //如果括号里面的不加上的话,下面的方法也无法调用的 $originalName = $fileCharater->getClientOriginalName(); // 文件原名 $ext = $fileCharater->getClientOriginalExtension(); // 扩展名 $realPath = $fileCharater->getRealPath(); //临时文件的绝对路径 $type = $fileCharater->getClientMimeType(); // image/jpeg if (strpos($type, 'vnd.openxmlformats-officedocument.spreadsheetml.sheet') === false) { return '非法格式'; } //// // 上传文件 $filename = date('Y-m-d-H-i-s') . '-' . uniqid() . '.' . 'xlsx'; // 使用我们新建的uploads本地存储空间(目录) //这里的uploads是配置文件的名称 $bool = Storage::disk('uploads')->put($filename, file_get_contents($realPath)); if ($bool) { $filePath = 'storage/app/public/uploads/' . $filename; $data = []; Excel::load($filePath, function ($reader) use (&$data) { $reader = $reader->getSheet(0); $data = $reader->toArray(); }); array_splice($data, 0, 2); $questions = []; foreach ($data as $key => $row) { $question['name'] = $row[1]; $question['category'] = array_search($row[2], Question::$categoryMap); $question['type'] = $row[3]; $question['answers'] = []; for ($i = 0; $i < strlen($row[4]); $i++) { $question['answers'][] = strtoupper(substr($row[4], $i, 1)); } $question['options'] = []; if ($row[5] !== null) $question['options'][] = ['name' => 'A', 'val' => $row[5]]; if ($row[6] !== null) $question['options'][] = ['name' => 'B', 'val' => $row[6]]; if ($row[7] !== null) $question['options'][] = ['name' => 'C', 'val' => $row[7]]; if ($row[8] !== null) $question['options'][] = ['name' => 'D', 'val' => $row[8]]; if ($row[9] !== null) $question['options'][] = ['name' => 'E', 'val' => $row[9]]; if ($row[10] !== null) $question['options'][] = ['name' => 'F', 'val' => $row[10]]; if ($row[11] !== null) $question['options'][] = ['name' => 'G', 'val' => $row[11]]; if ($question['name'] && $question['type'] && count($question['answers']) && count($question['options'])) { $model = new Question($question); $model->save(); } } $msg = "上传成功"; return view('admin.tools.excelskip', compact('msg')); } return "文件错误只能使用模板上传"; } } // protected function upload(Request $request) // { // //图片存储方法。如果为图片存起来。如果不是返回'' // $fileCharater = $request->file('file'); // // if ($fileCharater->isValid()) { //括号里面的是必须加的哦 // //如果括号里面的不加上的话,下面的方法也无法调用的 // // $originalName = $fileCharater->getClientOriginalName(); // 文件原名 // $ext = $fileCharater->getClientOriginalExtension(); // 扩展名 // $realPath = $fileCharater->getRealPath(); //临时文件的绝对路径 // $type = $fileCharater->getClientMimeType(); // image/jpeg // //// if (strpos($type, 'octet-stream') === false) { //// return '非法格式'; //// } // // $filePath = 'storage/app/public/uploads/2019-02-18-09-57-23-5c6a8183ebc40.xlsx'; //// $filePath = 'storage/exports/'.iconv('UTF-8', 'GBK', '学生成绩').'.xls'; // // Excel::load($filePath, function($reader) { // $data = $reader->get(); // return $data->toArray(); //// foreach($qdatas as $qdata => $value){ //// //// } // // }); // //// // 上传文件 //// $filename = date('Y-m-d-H-i-s') . '-' . uniqid() . '.' . 'xls'; //// // 使用我们新建的uploads本地存储空间(目录) //// //这里的uploads是配置文件的名称 //// $bool = Storage::disk('uploads')->put($filename, file_get_contents($realPath)); //// if ($bool) { //// return '/storage/uploads/' . $filename; //// } // } // return 'error'; // } }