queryDataFromDatabase(); // 将数据存入缓存,并设置过期时间 Cache::set($cacheKey, $Screendata, 3600); // 缓存有效期为1小时 } $this->success('ok', $Screendata); } /** * 查询大屏数据 */ private function queryDataFromDatabase() { //仪器总数 $count = Db::name('asset')->count(); //仪器总价值 $value = Db::name('asset')->sum('unit_price'); $value = round($value / 10000, 2); //已借出仪器数量 $lent_number = Db::name('asset')->where('status', 1)->count(); //维修中仪器数量 $repair_number = Db::name('asset')->where('status', 2)->count(); //仪器类型比例 $Instrumentlist = ['水准仪', 'RTK', '全站仪', '无人机', '其他']; foreach ($Instrumentlist as $list) { $Instrument_type = Db::name('asset')->where('asset_name', 'like', '%' . $list . '%')->count(); //$a仪器类型占比 $a[$list] = $Instrument_type; if ($list == "其他") { $Instrument_type = Db::name('asset')->whereNotLike('asset_name', ['%水准仪%', '%RTK%', '%全站仪%', '%无人机%'])->count(); $a[$list] = $Instrument_type; }; }; //用户信息 $teacher = Db::name('admin')->count(); $student = Db::name('student')->count(); $usersum = $teacher + $student; $userinfo = array('教职工' => $teacher, '学生' => $student, '用户总数' => $usersum); //仪器借取数量 foreach ($Instrumentlist as $list) { // $asset_groud_id=Db::name('asset_group')->where('belonging_category', 'like','%'.$list.'%')->column('id'); if ($list !== "其他") { $Instrument_type = Db::name('borrow_number')->where('asset_name', 'like', '%' . $list . '%')->sum('num'); $q[$list] = $Instrument_type; } else { // $asset_groud_id=Db::name('asset_group')->whereNotLike('belonging_category', ['%水准仪%','%RTK%','%全站仪%','%无人机%'])->column('id'); $Instrument_type = Db::name('borrow_number')->whereNotLike('asset_name', ['%水准仪%', '%RTK%', '%全站仪%', '%无人机%'])->sum('num'); //仪器借取数量 $q[$list] = $Instrument_type; arsort($q); // halt($q); } }; //每月仪器借取数量 $year = date("Y"); $Month = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']; foreach ($Month as $m) { $Monthq = Db::name('borrow_number')->whereMonth('create_time', $year . '-' . $m)->sum('num'); $mq[$m] = $Monthq; } //实验室介绍 $labinfo = Db::name('laboratory_introduction')->where('id', 1)->field('laboratorydisplay_diagram,laboratory_introduction')->select(); //仪器展示 $labdisplay = Db::name('instrument_display')->where('Instrument_status', 1)->field('Instrument_name,Instrument_picture,Instrument_value,Instrument_num,Instrument_introduction')->select(); //借单列表 $labborrow = Db::name('borrow')->alias('a')->leftjoin('admin b', 'a.user_id = b.id')->field('a.purpose,a.create_time,a.username,b.nickname,a.status')->order('a.create_time DESC')->limit(15)->select(); $data = [ // 数据数组 'count' => $count, 'value' => $value, 'lent_number' => $lent_number, 'repair_number' => $repair_number, 'a' => $a, 'userinfo' => $userinfo, 'q' => $q, 'mq' => $mq, 'labinfo' => $labinfo, 'labdisplay' => $labdisplay, 'labborrow' => $labborrow, ]; return $data; } //大屏操作 public function getCurrent(): void { $data = Db::name('operation')->where('switch', 1)->find(); $this->success('', [ 'data' => $data ]); } }