liuhairui 2 недель назад
Родитель
Сommit
8c8318a860
1 измененных файлов с 56 добавлено и 14 удалено
  1. 56 14
      application/index/controller/Index.php

+ 56 - 14
application/index/controller/Index.php

@@ -581,7 +581,7 @@ class Index extends Frontend
             if (is_array($col)) {
                 foreach ($col as $v) {
                     $id = (int)$v;
-                    if ($id > 0) {
+                    if ($this->mprocIsValidScydgyRowId($id)) {
                         $poSidList[$id] = true;
                     }
                 }
@@ -803,6 +803,11 @@ class Index extends Frontend
         ];
     }
 
+    protected function mprocIsValidScydgyRowId($id): bool
+    {
+        return (int)$id !== 0;
+    }
+
     /**
      * 将 purchase_order(工序行主表)快照合并进 purchase_order_detail 行:订单级信息以主表为准;
      * 金额、交期、外厂 company、明细 status 等仍保留明细表。
@@ -833,14 +838,42 @@ class Index extends Frontend
                 $row[$out] = $v;
             }
         }
-        // 本次数量、最高限价:仅存在于主表;PDO 列名可能为小写 ceilingprice
-        if (array_key_exists('this_quantity', $pl)) {
-            $row['This_quantity'] = $pl['this_quantity'];
+        // 本次数量、最高限价:仅存在于主表;PDO 列名大小写可能不一致
+        $qtyRaw = '';
+        foreach (['this_quantity', 'This_quantity'] as $qk) {
+            if (array_key_exists($qk, $pl) && $pl[$qk] !== null && $pl[$qk] !== '') {
+                $qtyRaw = trim((string)$pl[$qk]);
+                break;
+            }
+        }
+        if ($qtyRaw === '') {
+            foreach (['This_quantity', 'this_quantity'] as $qk) {
+                if (array_key_exists($qk, $poRow) && $poRow[$qk] !== null && $poRow[$qk] !== '') {
+                    $qtyRaw = trim((string)$poRow[$qk]);
+                    break;
+                }
+            }
+        }
+        if ($qtyRaw !== '') {
+            $row['This_quantity'] = $qtyRaw;
         }
-        if (array_key_exists('ceilingprice', $pl)) {
-            $row['ceilingPrice'] = $pl['ceilingprice'];
-        } elseif (array_key_exists('ceiling_price', $pl)) {
-            $row['ceilingPrice'] = $pl['ceiling_price'];
+        $ceilRaw = '';
+        foreach (['ceilingprice', 'ceiling_price', 'CeilingPrice'] as $ck) {
+            if (array_key_exists($ck, $pl) && $pl[$ck] !== null && $pl[$ck] !== '') {
+                $ceilRaw = trim((string)$pl[$ck]);
+                break;
+            }
+        }
+        if ($ceilRaw === '') {
+            foreach (['ceilingPrice', 'ceiling_price', 'CeilingPrice'] as $ck) {
+                if (array_key_exists($ck, $poRow) && $poRow[$ck] !== null && $poRow[$ck] !== '') {
+                    $ceilRaw = trim((string)$poRow[$ck]);
+                    break;
+                }
+            }
+        }
+        if ($ceilRaw !== '') {
+            $row['ceilingPrice'] = $ceilRaw;
         }
     }
 
@@ -883,7 +916,7 @@ class Index extends Frontend
                 continue;
             }
             $sid0 = (int)($r0['scydgy_id'] ?? $r0['SCYDGY_ID'] ?? 0);
-            if ($sid0 > 0) {
+            if ($this->mprocIsValidScydgyRowId($sid0)) {
                 $sidList[$sid0] = true;
             }
         }
@@ -895,7 +928,7 @@ class Index extends Frontend
                 if (is_array($poRows)) {
                     foreach ($poRows as $pr) {
                         $sidk = (int)($pr['scydgy_id'] ?? $pr['SCYDGY_ID'] ?? 0);
-                        if ($sidk > 0) {
+                        if ($this->mprocIsValidScydgyRowId($sidk)) {
                             $poBySid[$sidk] = $pr;
                         }
                     }
@@ -910,7 +943,7 @@ class Index extends Frontend
             }
             $row['eid'] = (int)($row['id'] ?? $row['ID'] ?? 0);
             $sid = (int)($row['scydgy_id'] ?? $row['SCYDGY_ID'] ?? 0);
-            if ($sid > 0 && isset($poBySid[$sid])) {
+            if ($this->mprocIsValidScydgyRowId($sid) && isset($poBySid[$sid])) {
                 $this->mprocMergePurchaseOrderIntoDetail($row, $poBySid[$sid]);
             }
             // status_name 由库表/后端维护,不在此根据 amount 覆盖
@@ -1324,15 +1357,24 @@ class Index extends Frontend
     protected function mprocResolveCeilingPriceForDetailRow(array $detailRow): ?float
     {
         $sid = (int)($detailRow['scydgy_id'] ?? $detailRow['SCYDGY_ID'] ?? 0);
-        $raw = '';
-        if ($sid !== 0) {
+        $raw = trim((string)($detailRow['ceilingPrice'] ?? $detailRow['ceiling_price'] ?? ''));
+        if ($raw === '' && $this->mprocIsValidScydgyRowId($sid)) {
             try {
                 $po = Db::table('purchase_order')->where('scydgy_id', $sid)->find();
             } catch (\Throwable $e) {
                 $po = null;
             }
             if (is_array($po)) {
-                $raw = trim((string)($po['ceilingPrice'] ?? $po['ceiling_price'] ?? ''));
+                $pl = array_change_key_case($po, CASE_LOWER);
+                foreach (['ceilingprice', 'ceiling_price'] as $ck) {
+                    if (array_key_exists($ck, $pl) && $pl[$ck] !== null && $pl[$ck] !== '') {
+                        $raw = trim((string)$pl[$ck]);
+                        break;
+                    }
+                }
+                if ($raw === '') {
+                    $raw = trim((string)($po['ceilingPrice'] ?? $po['ceiling_price'] ?? ''));
+                }
             }
         }
         if ($raw === '' || !preg_match('/^-?\d+(\.\d{1,5})?$/', $raw)) {