Jelajahi Sumber

超节损接口返回优化

unknown 4 hari lalu
induk
melakukan
f1646a0801
1 mengubah file dengan 66 tambahan dan 2 penghapusan
  1. 66 2
      application/api/controller/OrderSuperLoss.php

+ 66 - 2
application/api/controller/OrderSuperLoss.php

@@ -1752,7 +1752,7 @@ class OrderSuperLoss extends Api
         $list['real_rate'] = number_format($list['real_rate'],2);
         $list['real_rate'] = $list['real_rate'].'%';
 
-        //查询工序数据
+        //查询工序数据(字段名与历史 ProcessLoss 一致)
         $gy_field = '  
             `工序` AS Gy0_gxh,  
             MAX(`工序名称`) AS Gy0_gxmc,  
@@ -1844,7 +1844,8 @@ class OrderSuperLoss extends Api
         }
         $list['机检废'] = array_sum($machine);//机检废
         $list['total'] = $total;
-        $this->success('成功',$list);
+        $list = $this->formatProcessLossResponse($list);
+        $this->success('成功', $list);
     }
 
 
@@ -2310,6 +2311,69 @@ class OrderSuperLoss extends Api
         return $this->isSuperLossIntangibleExcluded($gxName);
     }
 
+    /**
+     * ProcessLoss 接口返回结构与历史前端一致(多数数值为字符串,total/部分汇总为数字)
+     */
+    private function formatProcessLossResponse(array $list): array
+    {
+        $strFields = [
+            'Gd_gdbh', 'yjno', 'ls', '成品代号', '成品名称', '计量单位', 'warehousing_date',
+            'warehousing_num', '计划损耗', '废品合计', 'intangible_loss', '材料废', '零头处理',
+            '外发废', 'zcfp', '班组分摊质检废品', '订单数量', '销售订单号', 'target_rate', 'real_rate', '考核',
+        ];
+        foreach ($strFields as $f) {
+            if (array_key_exists($f, $list)) {
+                $list[$f] = $list[$f] === null ? '' : (string)$list[$f];
+            }
+        }
+        if (array_key_exists('订单数量', $list) && $list['订单数量'] !== '') {
+            $list['订单数量'] = number_format((float)$list['订单数量'], 6, '.', '');
+        }
+        if (!array_key_exists('质量考核', $list) || $list['质量考核'] === '') {
+            $list['质量考核'] = null;
+        }
+        $list['实际投料'] = $list['实际投料'] === null || $list['实际投料'] === ''
+            ? 0
+            : (float)$list['实际投料'];
+        $list['机检废'] = isset($list['机检废']) ? (int)$list['机检废'] : 0;
+
+        if (!empty($list['gy_data']) && is_array($list['gy_data'])) {
+            foreach ($list['gy_data'] as $i => $row) {
+                $list['gy_data'][$i]['Gy0_gxh'] = (string)($row['Gy0_gxh'] ?? '');
+                $list['gy_data'][$i]['Gy0_gxmc'] = (string)($row['Gy0_gxmc'] ?? '');
+                $list['gy_data'][$i]['Gy0_yjno'] = (string)($row['Gy0_yjno'] ?? '');
+                $list['gy_data'][$i]['Gy0_ls'] = (string)($row['Gy0_ls'] ?? '');
+                $list['gy_data'][$i]['Gy0_无形损'] = (string)(int)($row['Gy0_无形损'] ?? 0);
+                $list['gy_data'][$i]['Gy0_计划损耗'] = (string)(int)($row['Gy0_计划损耗'] ?? 0);
+                $list['gy_data'][$i]['Gy0_计划接货数'] = (string)(int)($row['Gy0_计划接货数'] ?? 0);
+                $list['gy_data'][$i]['total_cl'] = (string)(int)($row['total_cl'] ?? 0);
+                $list['gy_data'][$i]['total_fp'] = (string)(int)($row['total_fp'] ?? 0);
+                $list['gy_data'][$i]['waste_quality'] = (string)(int)($row['waste_quality'] ?? 0);
+                $list['gy_data'][$i]['loss'] = (string)(int)($row['loss'] ?? 0);
+                $list['gy_data'][$i]['total_waste'] = (int)($row['total_waste'] ?? 0);
+                $list['gy_data'][$i]['actual_loss_rate'] = (string)($row['actual_loss_rate'] ?? '');
+                $list['gy_data'][$i]['target_loss_rate'] = (string)($row['target_loss_rate'] ?? '');
+                $list['gy_data'][$i]['loss_rate'] = (string)($row['loss_rate'] ?? '');
+                $list['gy_data'][$i]['工序超节损金额'] = number_format((float)($row['工序超节损金额'] ?? 0), 2, '.', '');
+                $list['gy_data'][$i]['超节损承担比例'] = number_format((float)($row['超节损承担比例'] ?? 0), 3, '.', '');
+                $list['gy_data'][$i]['无形损承担比例'] = number_format((float)($row['无形损承担比例'] ?? 0), 3, '.', '');
+            }
+        }
+
+        if (!empty($list['total']) && is_array($list['total'])) {
+            $t = &$list['total'];
+            $t['total_waste'] = (int)($t['total_waste'] ?? 0);
+            $t['total_zjfp'] = (int)($t['total_zjfp'] ?? 0);
+            $t['total_fp'] = (int)($t['total_fp'] ?? 0);
+            $t['plan_loss'] = (int)($t['plan_loss'] ?? 0);
+            $t['waste_intangible'] = (int)($t['waste_intangible'] ?? 0);
+            $t['loss'] = (int)($t['loss'] ?? 0);
+            $t['reward'] = round((float)($t['reward'] ?? 0), 2);
+        }
+
+        return $list;
+    }
+
     /**
      * 产量计酬按班组聚合,避免与工单基本资料等 JOIN 时 SUM(sczl_zcfp) 被放大
      */