From 2396083d544497372f4bfa3be48b19b9f85e79de Mon Sep 17 00:00:00 2001 From: limeng <1131177064@qq.com> Date: Sun, 6 Dec 2026 17:07:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=9C=AA=E5=8F=91=E5=87=BA=E6=98=8E?= =?UTF-8?q?=E7=BB=86):=20=E6=8E=92=E9=99=A4=E5=A4=96=E9=83=A8=E4=BB=93?= =?UTF-8?q?=E5=8D=A0=E4=BD=8D=E5=8D=95=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Support/UnshippedWaybills.php | 14 +++++++--- .../Business/UnshippedWaybillsTest.php | 27 +++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/app/Support/UnshippedWaybills.php b/app/Support/UnshippedWaybills.php index cd1e7e963..e5734da86 100644 --- a/app/Support/UnshippedWaybills.php +++ b/app/Support/UnshippedWaybills.php @@ -53,6 +53,12 @@ final class UnshippedWaybills return ltrim(preg_replace('/\s+/u', '', $number ?? '') ?? '', '@'); } + private static function isPlaceholder(?string $number): bool + { + // 外部仓占位标记不是运单号,不能作为未发出或换单依据。 + return strcasecmp(self::normalize($number), 'OuterWMS') === 0; + } + public static function parseRemark(string $remark): ?array { if (!preg_match('/^\s*([^::]+)[::]([^::]+?)\s*->\s*([^::]+)[::]([^::]+)\s*$/u', $remark, $parts)) { @@ -61,7 +67,7 @@ final class UnshippedWaybills $old = self::normalize($parts[2]); $new = self::normalize($parts[4]); foreach ([$old, $new] as $number) { - if (!preg_match('/^[A-Za-z0-9-]{1,96}$/', $number) || preg_match('/^\d+(?:\.\d+)?e[+-]?\d+$/i', $number)) return null; + if (self::isPlaceholder($number) || !preg_match('/^[A-Za-z0-9-]{1,96}$/', $number) || preg_match('/^\d+(?:\.\d+)?e[+-]?\d+$/i', $number)) return null; } return ['old_waybill' => $old, 'new_waybill' => $new, 'old_courier' => trim($parts[1]), 'new_courier' => trim($parts[3])]; @@ -75,7 +81,8 @@ final class UnshippedWaybills public function unshippedSources(array $waybills): array { $result = []; - foreach (array_chunk(array_unique(array_filter(array_map(self::normalize(...), $waybills))), 500) as $chunk) { + foreach (array_chunk(array_unique(array_filter(array_map(self::normalize(...), $waybills), + fn ($number) => $number !== '' && !self::isPlaceholder($number))), 500) as $chunk) { foreach ($this->results()->whereIn('waybill_no', $chunk)->distinct()->get(['waybill_no', 'source']) as $row) { $label = self::label($row->source); $result[$row->waybill_no][$label] = $label; @@ -191,6 +198,7 @@ final class UnshippedWaybills $currentOrder = null; $finalNumber = null; foreach ($logs as $log) { + if (self::isPlaceholder($log->old_waybill) || self::isPlaceholder($log->new_waybill)) continue; if ($currentOrder !== $log->order_no) { $currentOrder = $log->order_no; $finalNumber = $log->new_waybill; @@ -211,7 +219,7 @@ final class UnshippedWaybills ->select(['id', 'source_id', 'front_no', 'express_no', 'trade_no', 'ship_time', 'express_name1'])->lazyById(500); foreach ($ships as $ship) { $old = self::normalize($ship->front_no); $new = self::normalize($ship->express_no); - if ($old === '' || $new === '' || $old === $new) continue; + if ($old === '' || $new === '' || $old === $new || self::isPlaceholder($old) || self::isPlaceholder($new)) continue; // 旧号码仍是现有发货包裹时,不因另一条换单记录把它排除。 if ($this->connection()->table('jst_oms_shipping')->whereIn('express_no', [$old, '@'.$old])->exists()) continue; $rows['shipping:'.$ship->source_id.'|'.$old] = [ diff --git a/tests/Feature/Business/UnshippedWaybillsTest.php b/tests/Feature/Business/UnshippedWaybillsTest.php index 533969d79..122447220 100644 --- a/tests/Feature/Business/UnshippedWaybillsTest.php +++ b/tests/Feature/Business/UnshippedWaybillsTest.php @@ -43,6 +43,33 @@ final class UnshippedWaybillsTest extends FeatureTestCase $this->assertSame(1, (int) $db->table('courier_unshipped_sync')->where('source', 'replacement')->value('row_count')); } + public function test_outerwms_placeholder_is_not_a_waybill_or_replacement(): void + { + foreach (['OuterWMS', ' @outerwms ', 'OUTERWMS'] as $marker) { + $this->assertNull(UnshippedWaybills::parseRemark('外部仓:'.$marker.'->圆通:YT001')); + $this->assertNull(UnshippedWaybills::parseRemark('圆通:YT001->外部仓:'.$marker)); + } + $service = app(UnshippedWaybills::class); + $service->connection()->table('courier_unshipped_order_logs')->insert([ + 'order_no'=>'OLD-LOG','operated_at'=>'2026-11-28 08:00:00', + 'old_waybill'=>'OuterWMS','new_waybill'=>'YT001','old_courier'=>'外部仓', + 'new_courier'=>'圆通','remark'=>'外部仓:OuterWMS->圆通:YT001', + ]); + $service->connection()->table('jst_oms_shipping')->insert([ + ['source_id'=>81,'front_no'=>'OuterWMS','express_no'=>'YT001','trade_no'=>'T81','ship_time'=>'2026-11-28','express_name1'=>'圆通'], + ['source_id'=>82,'front_no'=>' @outerwms ','express_no'=>'JT002','trade_no'=>'T82','ship_time'=>'2026-11-28','express_name1'=>'极兔'], + ['source_id'=>83,'front_no'=>'REAL-OLD','express_no'=>'REAL-NEW','trade_no'=>'T83','ship_time'=>'2026-11-28','express_name1'=>'真实快递'], + ['source_id'=>84,'front_no'=>'INVALID-NEW','express_no'=>'OUTERWMS','trade_no'=>'T84','ship_time'=>'2026-11-28','express_name1'=>'外部仓'], + ]); + $this->assertTrue($service->sync('replacement')); + $this->assertSame(['REAL-OLD'], $service->results()->pluck('waybill_no')->all()); + $this->assertSame('REAL-NEW', $service->results()->value('new_waybill_no')); + $this->assertSame(['REAL-OLD'=>['换单未发出']], $service->unshippedSources(['OuterWMS','REAL-OLD','YT001','JT002'])); + $this->loginAs(); + $url = route('business.pages.show', ['section'=>'courier-payables','page'=>'unshipped-waybills','waybills'=>'OuterWMS']); + $this->get($url)->assertOk()->assertSeeText('没有符合条件的明细')->assertDontSeeText('REAL-OLD'); + } + public function test_intercept_uses_earliest_qualifying_item_and_original_waybill(): void { $service = app(UnshippedWaybills::class); -- 2.47.2