unknown преди 10 месеца
родител
ревизия
e973c4a60a
променени са 1 файла, в които са добавени 105 реда и са изтрити 0 реда
  1. 105 0
      application/api/controller/MachineInspection.php

+ 105 - 0
application/api/controller/MachineInspection.php

@@ -0,0 +1,105 @@
+<?php
+
+namespace app\api\controller;
+
+
+
+use app\common\controller\Api;
+
+class MachineInspection extends Api
+{
+
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+
+    /**
+     * 设备点检统计左侧菜单栏
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function getTab()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        //筛选出参与点检的设备编号
+        $machie = db('设备_点检项目')
+            ->group('适用机型')
+            ->column('适用机型');
+        $str = '';
+        foreach ($machie as $k => $v){
+            $str = $str . substr($v, 1);
+        }
+        $string = explode(';', $str);
+        array_pop($string);
+        //查询出点检设备基本资料
+        $MachineList = db('设备_基本资料')
+            ->where('sys_sbID','<>','')
+            ->whereNotNull('sys_sbID')
+            ->where('设备编号','in',$string)
+            ->order('设备编号')
+            ->select();
+        $data = [];
+        foreach ($MachineList as $k => $v) {
+            if (!isset($data[rtrim($v['使用部门'])])) {
+                $data[rtrim($v['使用部门'])] = [];
+            }
+            if (!isset($data[rtrim($v['使用部门'])][substr(rtrim($v['设备编组']),5)])) {
+                $data[rtrim($v['使用部门'])][substr(rtrim($v['设备编组']),5)] = [];
+            }
+            array_push($data[rtrim($v['使用部门'])][substr(rtrim($v['设备编组']),5)], rtrim($v['设备编号']).'【'.rtrim($v['设备名称']).'】');
+        }
+        $this->success('成功', $data);
+    }
+
+    /**
+     * 设备点检详情
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function InspectionDetail()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('成功');
+        }
+        $params = $this->request->param();
+        if (empty($params) || !isset($params['machineID']) || empty($params['machineID'])){
+            $this->error('参数错误');
+        }
+        //获取最新一个月参与点检日期
+        $lastDay = db('设备_点检记录')
+            ->where('点检设备', $params['machineID'])
+            ->order('日期', 'desc')
+            ->value('DATE_FORMAT(日期, "%Y-%m-%d")');
+        $startDay = date('Y-m-d', strtotime($lastDay)-2592000);
+        $dayList = db('设备_点检记录')
+            ->where('日期','between',[$startDay,$lastDay])
+            ->where('点检设备', $params['machineID'])
+            ->group('日期')
+            ->order('日期','desc')
+            ->column('DATE_FORMAT(日期, "%Y%m%d")');
+        //查询点检项目
+        $ProjectList = db('设备_点检项目')
+            ->where('适用机型','like','%'.$params['machineID'].'%')
+            ->field('部件编号,rtrim(部件名称) as 部件名称,rtrim(检验项目) as 检验项目')
+            ->select();
+        $data = ['日期'=>$dayList,'项目'=>[]];
+        foreach ($ProjectList as $k => $v) {
+            $res = db('设备_点检记录')
+                ->where('部件名称', $v['部件名称'])
+                ->where('检验项目', $v['检验项目'])
+                ->where('点检设备', $params['machineID'])
+                ->where('日期','between',[$startDay,$lastDay])
+                ->where('点检结果','合格')
+                ->order('日期','desc')
+                ->column('DATE_FORMAT(日期, "%Y%m%d")');
+            $data['项目'][] = array_merge($v,$res);
+        }
+        $this->success('成功', $data);
+    }
+}