Files
zyt/server/app/common/service/pharmacy/EjPharmacyTrackingPolicy.php
T
2026-07-22 14:50:34 +08:00

35 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace app\common\service\pharmacy;
use DomainException;
final class EjPharmacyTrackingPolicy
{
/**
* @param array<string,mixed>|null $current Active tracking for this order.
* @param array<string,mixed>|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];
}
}