Ver código fonte

设备维修保养维修工时统计

unknown 10 meses atrás
pai
commit
2bb306a562
1 arquivos alterados com 68 adições e 0 exclusões
  1. 68 0
      application/api/controller/MachineList.php

+ 68 - 0
application/api/controller/MachineList.php

@@ -411,6 +411,7 @@ class MachineList extends Api
             ->join('人事_基本资料 b','a.报障人 = b.员工编号','left')
             ->field('rtrim(a.设备编号) as 设备编号,rtrim(a.设备名称) as 设备名称,a.报障时间,a.维修受理时间,a.修复时间,a.实际维修工时 as 故障维修工时,rtrim(a.验收情况) as 验收情况,
             rtrim(b.员工姓名) as 机长,rtrim(c1.员工姓名) as 维修姓名1,rtrim(c2.员工姓名) as 维修姓名2,rtrim(c3.员工姓名) as 维修姓名3,rtrim(c4.员工姓名) as 维修姓名4,
+            a.维修人员1,a.维修人员2,a.维修人员3,a.维修人员4,
             rtrim(a.故障现象) as 故障现象,rtrim(a.处理方法) as 处理方法,rtrim(a.使用部门) as 使用部门,a.sys_id as 创建用户,a.sys_rq as 创建时间,a.mod_rq as 修改时间,a.UniqId');
         for($i=1;$i<=4;$i++){
             $tableNumber = 'c'.$i;
@@ -682,4 +683,71 @@ class MachineList extends Api
             $this->error('删除失败');
         }
     }
+
+
+    /**
+     * 维修工时统计
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function MaintenanceHours()
+    {
+        if ($this->request->isGet() === false) {
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param) || !isset($param['month'])) {
+            $this->error('参数错误');
+        }
+        $where['a.报障时间'] = ['like',$param['month'].'%'];
+        $field = 'a.维修人员1,a.维修人员2,a.维修人员3,a.维修人员4,c1.员工姓名 as 维修人员姓名1,c2.员工姓名 as 维修人员姓名2,c3.员工姓名 as 维修人员姓名3,c4.员工姓名 as 维修人员姓名4,
+        a.实际维修工时';
+        $query = db('设备_维修记录')
+            ->alias('a')
+            ->where($where)
+            ->field($field);
+        for($i=1;$i<=4;$i++){
+            $tableNumber = 'c'.$i;
+            $field = 'a.维修人员'.$i;
+            $query->join("人事_基本资料 $tableNumber", "$field = {$tableNumber}.员工编号 AND {$field} IS NOT NULL", 'LEFT');
+        }
+        $list = $query->select();
+        $data = array();
+        foreach ($list as $k=>$v){
+            for ($i=1;$i<=4;$i++){
+                $code = $v['维修人员'.$i];
+                $name = $v['维修人员姓名'.$i];
+                if ($code !== '') {
+                    $data[] = [
+                        'code' => $code,
+                        'name' => $name,
+                        'hour' => $v['实际维修工时'],
+                    ];
+                }
+            }
+        }
+        $result = [];
+        foreach ($data as $item) {
+            $code = $item['code'];
+            $hour = (float)$item['hour'];
+
+
+            if (isset($result[$code])) {
+                $result[$code]['hour'] += $hour;
+                $result[$code]['Frequency'] += 1;
+            } else {
+
+                $result[$code] = [
+                    'code' => $code,
+                    'name' => '',
+                    'hour' => $hour,
+                    'Frequency' => 1
+                ];
+            }
+        }
+        $result = array_values($result);
+        $this->success('成功', $result);
+    }
 }