perf(modal): unify cancellable frontend modal flows

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-05 02:04:55 +08:00
co-authored by Claude Fable 5
parent 25ce1d8f43
commit 5375ad6429
36 changed files with 2623 additions and 1806 deletions
+30 -9
View File
@@ -243,6 +243,18 @@ class Gateway {
return sanitize_text_field((string) ($order['order_number'] ?? $provider_ref));
}
/**
* Whether a pending order can be reconciled against an external provider.
*
* This is the single gate used by the order view and the actual reconcile
* operation, so ordinary detail reads never trigger provider I/O.
*
* @param array<string,mixed>|null $order
*/
public function needs_reconciliation(?array $order): bool {
return null !== $this->reconciliation_gateway($order);
}
/**
* Reconcile a pending external order against the configured provider.
*
@@ -254,18 +266,11 @@ class Gateway {
}
$repo = OrderRepository::get_instance();
$order = is_array($order) ? $order : $repo->get($order_number);
if (!$order || !in_array((string) ($order['status'] ?? ''), [Order::STATUS_CREATED, Order::STATUS_PENDING], true)) {
$gateway = $this->reconciliation_gateway($order);
if (!$gateway) {
return $order;
}
$gateway_id = sanitize_key((string) ($order['payment_method'] ?? ''));
if ($gateway_id === '' || in_array($gateway_id, ['balance', 'points', 'manual_review'], true)) {
return $order;
}
$gateway = $this->get_gateway($gateway_id);
if (!$gateway || !$gateway->is_configured()) {
return $order;
}
$throttle_key = 'aksrt_reconcile_' . hash('sha256', $order_number);
if (get_transient($throttle_key)) {
@@ -297,6 +302,22 @@ class Gateway {
return $repo->get($order_number) ?: $order;
}
/**
* @param array<string,mixed>|null $order
*/
private function reconciliation_gateway(?array $order): ?GatewayInterface {
if (!is_array($order) || !in_array((string) ($order['status'] ?? ''), [Order::STATUS_CREATED, Order::STATUS_PENDING], true)) {
return null;
}
$gateway_id = sanitize_key((string) ($order['payment_method'] ?? ''));
if ($gateway_id === '' || in_array($gateway_id, ['balance', 'points', 'manual_review'], true)) {
return null;
}
$gateway = $this->get_gateway($gateway_id);
return $gateway && $gateway->is_configured() ? $gateway : null;
}
/**
* 幂等、带金额校验的订单完成。仅由验签通过的回调调用。
*