|null $current Active tracking for this order. * @param array|null $matching Tracking already owning the incoming number. * @return array{action:string,archive_current:bool} */ public static function select(?array $current, ?array $matching, int $orderId, string $trackingNumber): array { $trackingNumber = trim($trackingNumber); if ($current !== null && trim((string) ($current['tracking_number'] ?? '')) === $trackingNumber) { return ['action' => 'REUSE_CURRENT', 'archive_current' => false]; } if ($matching !== null) { $ownerOrderId = (int) ($matching['order_id'] ?? 0); if ($ownerOrderId !== 0 && $ownerOrderId !== $orderId) { throw new DomainException('该运单号已关联其他订单,禁止重新绑定'); } return ['action' => 'REUSE_MATCHING', 'archive_current' => $current !== null]; } return ['action' => 'CREATE', 'archive_current' => $current !== null]; } }