Преглед изворни кода

Merge remote-tracking branch 'origin/master'

qiuenguang пре 1 недеља
родитељ
комит
84af549514
2 измењених фајлова са 85 додато и 15 уклоњено
  1. 53 15
      application/api/controller/Facility.php
  2. 32 0
      application/api/controller/OrderSuperLoss.php

+ 53 - 15
application/api/controller/Facility.php

@@ -3411,29 +3411,67 @@ class Facility extends Api
             $this->error('请求错误');
             $this->error('请求错误');
         }
         }
         $param = $this->request->param();
         $param = $this->request->param();
-        // $where = [
-        //     '类别' => '现场巡查记录'
-        // ];
+        $where = [];
         if (isset($param['machine'])){
         if (isset($param['machine'])){
             $where['设备编号'] = $param['machine'];
             $where['设备编号'] = $param['machine'];
         }
         }
-        
+
         // 添加最近一个月的时间条件
         // 添加最近一个月的时间条件
         $oneMonthAgo = date('Y-m-d H:i:s', strtotime('-1 month'));
         $oneMonthAgo = date('Y-m-d H:i:s', strtotime('-1 month'));
         $where['提交时间'] = ['>=', $oneMonthAgo];
         $where['提交时间'] = ['>=', $oneMonthAgo];
-        
-        $field = '设备编号,提交时间';
-        $data = db('制程检验_记录')->where($where)->field($field)->select();
-        $result = [];
-        foreach ($data as $key=>$value){
-            $date = date('Y-m-d',strtotime($value['提交时间']));
-            if (!isset($result[$value['设备编号']])){
-                $result[$value['设备编号']] = [];
+
+        $rows = \db('制程检验_记录')->where($where)->field('设备编号,提交时间')->select();
+
+        // 机台 --> 使用部门 / 设备名称 映射
+        $machineInfo = [];
+        $machines = \db('设备_基本资料')
+            ->where('sys_sbID','<>','')
+            ->where('使用部门','<>','研发中心')
+            ->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称,rtrim(使用部门) as 使用部门')
+            ->select();
+        foreach ($machines as $m) {
+            $machineInfo[$m['设备编号']] = $m;
+        }
+
+        // 使用部门 => 机台 => 日期列表
+        $data = [];
+        foreach ($rows as $row) {
+            $machine = trim($row['设备编号']);
+            if ($machine === ''){
+                continue;
+            }
+            $info = isset($machineInfo[$machine]) ? $machineInfo[$machine] : null;
+            $department = $info ? $info['使用部门'] : '未分类';
+            if ($department === ''){
+                $department = '未分类';
             }
             }
-            array_push($result[$value['设备编号']],$date);
+            $machineName = $info ? $info['设备名称'] : '';
+            $machineLabel = ($machineName === '' || $machineName === null) ? $machine : $machine . '-->' . $machineName;
+            $date = date('Y-m-d', strtotime($row['提交时间']));
+            $data[$department][$machineLabel][$date] = $date;
+        }
+
+        // 部门按业务顺序:胶印车间 → 凹丝印车间 → 印后车间 → 其余按名称
+        $deptOrder = ['胶印车间' => 1, '凹丝印车间' => 2, '印后车间' => 3];
+        uksort($data, function ($a, $b) use ($deptOrder) {
+            $pa = isset($deptOrder[$a]) ? $deptOrder[$a] : 999;
+            $pb = isset($deptOrder[$b]) ? $deptOrder[$b] : 999;
+            if ($pa === $pb) {
+                return strcmp($a, $b);
+            }
+            return $pa <=> $pb;
+        });
+        foreach ($data as $department => &$machineList) {
+            ksort($machineList);
+            foreach ($machineList as $label => &$dates) {
+                $dates = array_values($dates);
+                rsort($dates);
+            }
+            unset($dates);
         }
         }
-        ksort($result);
-        $this->success('成功',$result);
+        unset($machineList);
+
+        $this->success('成功',$data);
     }
     }
 
 
     /**
     /**

+ 32 - 0
application/api/controller/OrderSuperLoss.php

@@ -3238,12 +3238,44 @@ class OrderSuperLoss extends Api
                 WHERE qczl_gdbh = '{$order}' AND qczl_yjno = '{$yjno}'";
                 WHERE qczl_gdbh = '{$order}' AND qczl_yjno = '{$yjno}'";
         $rows = Db::query($sql);
         $rows = Db::query($sql);
 
 
+        // 废品分类字典校验:只有与 erp_常用字典(分类=废品分类)对得上的缺陷才保留
+        // 字典名称格式:废品分类_A-卷凹_A01-色差_  → 有效值为 A01-色差
+        $allowMap = [];
+        $dictNames = db('erp_常用字典')->where('分类', '废品分类')->column('名称');
+        foreach ($dictNames as $dictName) {
+            $dictName = trim($dictName);
+            if ($dictName === '') {
+                continue;
+            }
+            $parts = array_values(array_filter(explode('_', $dictName), function ($v) {
+                return trim($v) !== '';
+            }));
+            if (empty($parts)) {
+                continue;
+            }
+            $code = trim(end($parts));
+            if ($code === '') {
+                continue;
+            }
+            $allowMap[$code] = true;
+            // 兼容缺陷表只存中文名的情况(如 色差)
+            $pos = strpos($code, '-');
+            if ($pos !== false) {
+                $suffix = trim(substr($code, $pos + 1));
+                if ($suffix !== '') {
+                    $allowMap[$suffix] = true;
+                }
+            }
+        }
+
         // 按类别汇总数量:key = 类别名,value = 累计数量
         // 按类别汇总数量:key = 类别名,value = 累计数量
         $aggMap = [];
         $aggMap = [];
         foreach ($rows as $entry) {
         foreach ($rows as $entry) {
             for ($i = 1; $i <= 13; $i++) {
             for ($i = 1; $i <= 13; $i++) {
                 $label = trim($entry['fp_lb' . $i] ?? '');
                 $label = trim($entry['fp_lb' . $i] ?? '');
                 if ($label === '' || $label === null) continue;
                 if ($label === '' || $label === null) continue;
+                // 字典中不存在该缺陷类别 → 不显示
+                if (!isset($allowMap[$label])) continue;
                 $sl = floatval($entry['fp_sl' . $i] ?? 0);
                 $sl = floatval($entry['fp_sl' . $i] ?? 0);
                 if (!isset($aggMap[$label])) {
                 if (!isset($aggMap[$label])) {
                     $aggMap[$label] = 0;
                     $aggMap[$label] = 0;