zck 10 månader sedan
förälder
incheckning
0518dd74ca
1 ändrade filer med 21 tillägg och 25 borttagningar
  1. 21 25
      application/api/controller/Achievementatestatistics.php

+ 21 - 25
application/api/controller/Achievementatestatistics.php

@@ -448,17 +448,17 @@ class Achievementatestatistics extends Api
         if (!$this->request->isGet()) {
             $this->error('请求方式错误');
         }
-
+    
         $param = $this->request->param();
-
+    
         if (empty($param['jtbh']) || empty($param['rq'])) {
             $this->error('缺少必要参数:jtbh(机台编号)、rq(年月)');
         }
-
+    
         $jtbh = $param['jtbh'];
         $rq = $param['rq'];
         $ym = substr($rq, 0, 4) . '-' . substr($rq, 4, 2);
-
+    
         // 查询该月份内该机台的每日工单产量明细
         $records = Db::name('设备_产量计酬')->alias('a')
             ->field([
@@ -485,46 +485,42 @@ class Achievementatestatistics extends Api
                 'SUM(sczl_异常工时1) as 异常补时',
                 'SUM(sczl_设备运行工时) as 运行工时'
             ])
-            ->join('工单_印件资料 b', 'a.sczl_gdbh = b.Yj_Gdbh', 'LEFT')
+            ->join('工单_印件资料 b', 'a.sczl_gdbh = b.Yj_Gdbh AND a.sczl_yjno = b.Yj_YjNo', 'LEFT') // 添加印件号关联条件
             ->where('a.sczl_jtbh', $jtbh)
             ->whereLike('a.sczl_rq', $ym . '%')
-            ->group('a.sczl_rq, a.sczl_gdbh')
-            ->order('a.sczl_rq desc')
+            ->group('a.sczl_rq, a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh, a.sczl_bzdh') // 确保唯一性分组
+            ->order('a.sczl_rq desc, a.sczl_bzdh')
             ->select();
-
+    
         // 数据格式化与目标产量计算
         foreach ($records as &$row) {
             $row['日期'] = date('Y-m-d', strtotime($row['日期']));
             $row['印件工序'] = $row['印件号'] . '-' . $row['工序名称'];
             $row['小时产能'] = 50000;
-
+    
             // 计算目标产量
             $row['目标产量'] = round(
                 max(0, $row['运行工时'] - $row['保养工时'] - $row['装版补产工时'] - $row['异常总工时']) * 50000,
                 2
             );
-
+    
             // 计算负荷产量
             $row['负荷产量'] = round(
                 max(0, $row['运行工时'] - $row['保养工时'] - $row['装版补产工时'] - $row['异常总工时']) * 50000,
                 2
             );
-
-            // 计算目标达成率 (避免除以0)
-            if ($row['目标产量'] > 0) {
-                $row['目标达成'] = round($row['实际产量'] / $row['目标产量'] * 100, 2) . '%';
-            } else {
-                $row['目标达成'] = '0%';
-            }
-
-            // 计算总和利用率 (避免除以0)
-            if ($row['负荷产量'] > 0) {
-                $row['综合利用率'] = round($row['实际产量'] / $row['负荷产量'] * 100, 2) . '%';
-            } else {
-                $row['综合利用率'] = '0%';
-            }
+    
+            // 计算目标达成率
+            $row['目标达成'] = $row['目标产量'] > 0 
+                ? round($row['实际产量'] / $row['目标产量'] * 100, 2) . '%' 
+                : '0%';
+    
+            // 计算综合利用率
+            $row['综合利用率'] = $row['负荷产量'] > 0 
+                ? round($row['实际产量'] / $row['负荷产量'] * 100, 2) . '%' 
+                : '0%';
         }
-
+    
         $this->success('明细获取成功', $records);
     }