request->isGet() === false){ $this->error('请求错误'); } $year = date('Y',time()); $lastYear = date('Y', strtotime('-1 year')); //年度维修统计 $yearResult1 = $this->getYearSite($year); $yearResult2 = $this->getYearSite($lastYear); $data['1、年度维修统计'] = [ $year => $yearResult1, $lastYear => $yearResult2 ]; //月度维修记录 $lastMouth = date('Y-m', strtotime('-1 year')); $mouthReault = $this->getMouthSite($lastMouth); $data['2、月度维修记录'] = $mouthReault; //年度保养记录 $YearMaintenanceSist1 = $this->getYearMaintenanceSist($year); $YearMaintenanceSist2 = $this->getYearMaintenanceSist($lastYear); if (!empty($YearMaintenanceSist1)){ $data['3、年度保养统计'][$year] = $YearMaintenanceSist1; } if (!empty($YearMaintenanceSist2)){ $data['3、年度保养统计'][$lastYear] = $YearMaintenanceSist2; } //月度保养记录 $mouthMaintenanceSist = $this->getMouthMaintenanceSist($lastMouth); $data['4、月度保养记录'] = $mouthMaintenanceSist; $this->success('成功',$data); } private function getYearSite($year) { $sist = db('设备_维修记录') ->where('报障时间','like',$year.'%') ->group('使用部门') ->column('rtrim(使用部门)'); $data = []; if (!empty($sist)){ foreach ($sist as $item){ $count = db('设备_维修记录') ->where('使用部门',$item) ->where('报障时间','like',$year.'%') ->count(); if ($count !== 0){ $data[] = $item.'('.$count.'台次)'; } } } return $data; } private function getMouthSite($mouth) { $mouth = db('设备_维修记录') ->where('报障时间','>',$mouth.'-01 00:00:00') ->where('报障时间','<',date('Y-m-d H:i:s',time())) ->group('date') ->order('date desc') ->column('DATE_FORMAT(报障时间, "%Y-%m") AS date'); $data = []; foreach ($mouth as $item){ $sist = db('设备_维修记录') ->where('报障时间','like',$item.'%') ->group('使用部门') ->column('rtrim(使用部门)'); foreach ($sist as $value){ $count = db('设备_维修记录') ->where('使用部门',$value) ->where('报障时间','like',$item.'%') ->count(); $data[$item][] = $value.'('.$count.'台次)'; } } return $data; } private function getYearMaintenanceSist($year) { $sist = db('设备_保养记录') ->where('保养开始时间','like',$year.'%') ->group('使用部门') ->column('rtrim(使用部门)'); $data = []; if (!empty($sist)){ foreach ($sist as $item){ $count = db('设备_保养记录') ->where('使用部门',$item) ->where('保养开始时间','like',$year.'%') ->count(); if ($count !== 0){ $data[] = $item.'('.$count.'台次)'; } } } return $data; } private function getMouthMaintenanceSist($mouth) { $mouth = db('设备_保养记录') ->where('保养开始时间','>',$mouth.'-01 00:00:00') ->where('保养开始时间','<',date('Y-m-d H:i:s',time())) ->group('date') ->order('date desc') ->column('DATE_FORMAT(保养开始时间, "%Y-%m") AS date'); $data = []; foreach ($mouth as $item){ $sist = db('设备_保养记录') ->where('保养开始时间','like',$item.'%') ->group('使用部门') ->column('rtrim(使用部门)'); foreach ($sist as $value){ $count = db('设备_保养记录') ->where('使用部门',$value) ->where('保养开始时间','like',$item.'%') ->count(); $data[$item][] = $value.'('.$count.'台次)'; } } return $data; } //年度维修记录上方列表 public function MachineList() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $param = $this->request->param(); if (empty($param)){ $this->error('参数错误'); } } }