$claim @return array */ public static function existingDecision(array $claim, string $requestedTarget, ?int $now = null): array { $target = (string) ($claim['target'] ?? ''); $status = strtoupper(trim((string) ($claim['status'] ?? ''))); if ($status === 'SUCCESS') { if ($target !== $requestedTarget) { throw new DomainException('该订单已上传其他药房'); } return ['action' => 'IDEMPOTENT'] + $claim; } if ($status === 'PENDING') { $leaseExpiresAt = (int) ($claim['lease_expires_at'] ?? 0); if ($leaseExpiresAt > 0 && $leaseExpiresAt <= ($now ?? time())) { return [ 'action' => $target === 'gancao' ? 'RECONCILE' : 'RETRY', 'lease_expired' => true, ] + $claim; } throw new DomainException('该订单正在上传药房,请勿重复提交'); } if (in_array($status, ['UNKNOWN', 'PENDING_RECONCILE'], true)) { if ($target !== $requestedTarget) { throw new DomainException('该订单远端结果待对账,禁止切换药房'); } return ['action' => 'RECONCILE'] + $claim; } if ($status === 'FAILED') { return ['action' => 'RETRY'] + $claim; } throw new DomainException('药房提交状态异常,请先对账处理'); } }