feat: add zyt medicine bootstrap

This commit is contained in:
2026-07-22 14:50:34 +08:00
parent 8a6890767e
commit 31312ae975
51 changed files with 6567 additions and 1 deletions
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace app\common\service\pharmacy;
use DomainException;
final class PharmacySubmissionClaimPolicy
{
/** @param array<string,mixed> $claim @return array<string,mixed> */
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('药房提交状态异常,请先对账处理');
}
}