m0_70156489 3 weeks ago
parent
commit
675c7f1d3e
1 changed files with 73 additions and 12 deletions
  1. 73 12
      application/admin/controller/Procuremen.php

+ 73 - 12
application/admin/controller/Procuremen.php

@@ -6868,7 +6868,64 @@ class Procuremen extends Backend
     }
 
     /**
-     * 确认供应商列表:按订单号 CCYDH 合并为一行(一单一行,工序汇总)
+     * 同一次下发批次的时间(优先 pick_time,空则 createtime)
+     */
+    protected function procuremenIssueBatchTime(array $row): string
+    {
+        $t = $this->procuremenRowListSortTime($row, 'pick_time');
+        if ($t !== '') {
+            return $t;
+        }
+        $t = $this->formatProcuremenDetailTime($row['createtime'] ?? null);
+        if ($t !== '' && stripos($t, '0000-00-00') !== 0) {
+            return $t;
+        }
+
+        return '';
+    }
+
+    /**
+     * 列表/弹窗合并键:同一订单号 + 同一次下发才合成一行。
+     * 避免 202606213S 8-06 下发封面覆膜、8-18 再下发书签模切被并到确认页同一行。
+     */
+    protected function procuremenIssueBatchGroupKey(array $row): string
+    {
+        $dh = trim((string)($row['CCYDH'] ?? ''));
+        $sid = (int)($row['scydgy_id'] ?? $row['ID'] ?? $row['id'] ?? 0);
+        if ($dh === '') {
+            return '_id_' . $sid;
+        }
+        $batch = $this->procuremenIssueBatchTime($row);
+
+        return $batch !== '' ? ($dh . '|' . $batch) : ($dh . '|sid:' . $sid);
+    }
+
+    /**
+     * 是否同一次下发(同一订单号且下发时间一致)
+     */
+    protected function isSameProcuremenIssueBatch(array $anchor, array $po): bool
+    {
+        return $this->procuremenIssueBatchGroupKey($anchor) === $this->procuremenIssueBatchGroupKey($po);
+    }
+
+    /**
+     * @param array<int, mixed> $pos
+     * @return array<int, array<string, mixed>>
+     */
+    protected function filterPurchaseOrdersSameIssueBatch(array $pos, array $anchor): array
+    {
+        $out = [];
+        foreach ($pos as $po) {
+            if (is_array($po) && $this->isSameProcuremenIssueBatch($anchor, $po)) {
+                $out[] = $po;
+            }
+        }
+
+        return $out !== [] ? $out : [$anchor];
+    }
+
+    /**
+     * 确认供应商列表:同一订单号且同一次下发才合并为一行
      *
      * @param array<int, array<string, mixed>> $pool
      * @return array<int, array<string, mixed>>
@@ -6883,8 +6940,7 @@ class Procuremen extends Backend
             if (!is_array($row)) {
                 continue;
             }
-            $dh = trim((string)($row['CCYDH'] ?? ''));
-            $key = $dh !== '' ? $dh : ('_id_' . (int)($row['ID'] ?? 0));
+            $key = $this->procuremenIssueBatchGroupKey($row);
             if (!isset($groups[$key])) {
                 $groups[$key] = [];
             }
@@ -6907,7 +6963,8 @@ class Procuremen extends Backend
                 }
             }
             $merged = $head;
-            $merged['order_key'] = strpos((string)$ccydh, '_id_') === 0 ? '' : (string)$ccydh;
+            $orderDh = trim((string)($head['CCYDH'] ?? ''));
+            $merged['order_key'] = $orderDh;
             $merged['process_count'] = count($rows);
             $merged['_order_merge_rows'] = $rows;
             $qtyList = [];
@@ -6982,7 +7039,7 @@ class Procuremen extends Backend
     }
 
     /**
-     * 待确认供应商订单下全部工序(同一 CCYDH,wflow_status=1
+     * 待确认供应商:同一订单号且同一次下发的工序(wflow_status=待确认
      *
      * @return array{ccydh:string, pos:array<int,array>, merge_rows:array<int,array>}
      */
@@ -7013,6 +7070,7 @@ class Procuremen extends Backend
         if (!is_array($pos) || $pos === []) {
             $pos = [$anchor];
         }
+        $pos = $this->filterPurchaseOrdersSameIssueBatch($pos, $anchor);
 
         return [
             'ccydh'       => $ccydh,
@@ -7045,7 +7103,7 @@ class Procuremen extends Backend
     }
 
     /**
-     * 采购确认:同一 CCYDH 下全部待确认工序(与列表合并规则一致)
+     * 采购确认:同一订单号且同一次下发的待审批工序(与列表合并规则一致)
      *
      * @return array{ccydh:string, pos:array<int,array>, merge_rows:array<int,array>}
      */
@@ -7088,6 +7146,7 @@ class Procuremen extends Backend
         if ($pos === []) {
             $pos = [$anchor];
         }
+        $pos = $this->filterPurchaseOrdersSameIssueBatch($pos, $anchor);
 
         return [
             'ccydh'      => $ccydh,
@@ -7154,14 +7213,11 @@ class Procuremen extends Backend
         $isValidPick = $pickTime !== '' && stripos($pickTime, '0000-00-00') !== 0;
         try {
             $q = Db::table('purchase_order');
-            if ($ccydh !== '') {
-                $q->where('CCYDH', $ccydh);
+            if ($ccydh !== '' && $isValidPick) {
+                $q->where('CCYDH', $ccydh)->where('pick_time', $pickTime);
             } else {
                 $q->where('scydgy_id', $scydgyId);
             }
-            if ($isValidPick) {
-                $q->where('pick_time', $pickTime);
-            }
             $pos = $q->order('scydgy_id', 'asc')->select();
         } catch (\Throwable $e) {
             $pos = [$anchor];
@@ -12329,6 +12385,7 @@ class Procuremen extends Backend
         if (!is_array($pos) || $pos === []) {
             $pos = [$anchor];
         }
+        $pos = $this->filterPurchaseOrdersSameIssueBatch($pos, $anchor);
 
         return [
             'ccydh'      => $ccydh,
@@ -12391,7 +12448,11 @@ class Procuremen extends Backend
                     continue;
                 }
                 $ccydh = trim((string)($bundle['ccydh'] ?? ''));
-                $dedupeKey = $ccydh !== '' ? $ccydh : ('sid:' . $anchorId);
+                $batchTime = '';
+                if (!empty($bundle['pos'][0]) && is_array($bundle['pos'][0])) {
+                    $batchTime = $this->procuremenIssueBatchTime($bundle['pos'][0]);
+                }
+                $dedupeKey = $ccydh !== '' ? ($ccydh . '|' . $batchTime) : ('sid:' . $anchorId);
                 if (isset($processedCcydh[$dedupeKey])) {
                     continue;
                 }