瀏覽代碼

糊盒手工报工优化

unknown 1 周之前
父節點
當前提交
fa41eab7b3
共有 1 個文件被更改,包括 27 次插入30 次删除
  1. 27 30
      application/api/controller/GluingReport.php

+ 27 - 30
application/api/controller/GluingReport.php

@@ -1085,54 +1085,51 @@ class GluingReport extends Api
 
     /**
      * 报工时自动解析单价
+     * 优先按 sczl_jtbh 匹配 machine_price.machine_id;未找到则按 sczl_gxmc + sczl_ls 匹配手工工序单价
      * @param array $param
      * @return float|null
      */
     protected function resolveReportPrice(array $param)
     {
         $machine = trim($param['sczl_jtbh']);
-        $gxmc = trim((string)($param['sczl_gxmc'] ?? $param['gxmc'] ?? ''));
+        $gxmc = trim((string)($param['sczl_gxmc'] ?? ''));
         $count = $this->extractManualProcessCountSilent($param);
-        $processText = $this->resolveManualProcessText($machine, $gxmc);
 
-        if ($processText !== '') {
-            $manualPrice = $this->resolveManualProcessPriceSilent($processText, $count);
-            if ($manualPrice !== null) {
-                return $manualPrice;
-            }
+        $price = $this->resolvePriceByMachineId($machine, $count);
+        if ($price !== null) {
+            return $price;
         }
 
-        if (!$this->isManualMachineId($machine)) {
-            $machinePrices = $this->collectMachinePriceValues($machine);
-            if (!empty($machinePrices)) {
-                return (float)$machinePrices[0];
-            }
+        if ($gxmc !== '') {
+            return $this->resolveManualProcessPriceSilent($gxmc, $count);
         }
 
-        $aiService = new Aicompute();
-        $rates = $aiService->fetchWorkshopRatesByMachine($machine);
-        if (empty($rates)) {
+        return null;
+    }
+
+    /**
+     * 按机台编号(machine_price.machine_id)解析单价
+     * @param string $machineId
+     * @param int|null $count sczl_ls(贴片个数/孔数/拼数)
+     * @return float|null
+     */
+    protected function resolvePriceByMachineId($machineId, $count)
+    {
+        $machineId = trim((string)$machineId);
+        if ($machineId === '') {
             return null;
         }
 
-        $productName = db('工单_基本资料')
-            ->where('Gd_gdbh', trim($param['sczl_gdbh']))
-            ->value('Gd_cpmc');
-        $productName = $productName ? trim($productName) : '';
-
-        if ($productName !== '') {
-            $matched = $aiService->matchWorkshopRateByProductName($rates, $productName);
-            if (!empty($matched)) {
-                return (float)$matched['piece_price'];
-            }
+        if ($this->isManualMachineId($machineId)) {
+            return $this->resolveManualProcessPriceSilent($machineId, $count);
         }
 
-        $aiPrice = $aiService->resolvePiecePriceByAi(trim($param['sczl_gdbh']), $machine);
-        if ($aiPrice !== null) {
-            return $aiPrice;
+        $machinePrices = $this->collectMachinePriceValues($machineId);
+        if (!empty($machinePrices)) {
+            return (float)$machinePrices[0];
         }
 
-        return (float)$rates[0]['piece_price'];
+        return null;
     }
 
     /**
@@ -1249,7 +1246,7 @@ class GluingReport extends Api
      */
     protected function extractManualProcessCountSilent(array $params)
     {
-        foreach (['count', '孔数', '拼数', 'hole_count', 'piece_count'] as $field) {
+        foreach (['sczl_ls', 'count', '孔数', '拼数', 'hole_count', 'piece_count'] as $field) {
             if (!isset($params[$field]) || $params[$field] === '') {
                 continue;
             }