| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- namespace app\api\controller;
- use think\Request;
- use app\common\controller\Api;
- /**
- * 设备维修保养记录
- */
- class MachineList extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- //设备维修保养记录左侧菜单
- public function getTab()
- {
- if ($this->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('参数错误');
- }
- }
- }
|