refactor(admin-platform-order): centralize tool guard reasons
This commit is contained in:
118
app/Support/PlatformOrderToolsGuard.php
Normal file
118
app/Support/PlatformOrderToolsGuard.php
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Support;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 平台订单列表页工具区:前端治理阻断口径(减少误点)。
|
||||||
|
*
|
||||||
|
* 说明:后端各批量动作/清理动作本身仍有安全阀阻断;这里仅用于 UI 层“按钮禁用 + 提示原因”。
|
||||||
|
*/
|
||||||
|
class PlatformOrderToolsGuard
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $filters
|
||||||
|
* @return array<string, array{blocked:bool, reason:string}>
|
||||||
|
*/
|
||||||
|
public static function forIndex(array $filters): array
|
||||||
|
{
|
||||||
|
$batchActivateReason = self::batchActivateSubscriptionsReason($filters);
|
||||||
|
$batchBmpaReason = self::batchBmpaReason($filters);
|
||||||
|
$batchMarkActivatedReason = self::batchMarkActivatedReason($filters);
|
||||||
|
$clearSyncReason = self::clearSyncErrorsReason($filters);
|
||||||
|
$clearBmpaReason = self::clearBmpaErrorsReason($filters);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'batch_activate_subscriptions' => [
|
||||||
|
'blocked' => $batchActivateReason !== '',
|
||||||
|
'reason' => $batchActivateReason,
|
||||||
|
],
|
||||||
|
'batch_bmpa' => [
|
||||||
|
'blocked' => $batchBmpaReason !== '',
|
||||||
|
'reason' => $batchBmpaReason,
|
||||||
|
],
|
||||||
|
'batch_mark_activated' => [
|
||||||
|
'blocked' => $batchMarkActivatedReason !== '',
|
||||||
|
'reason' => $batchMarkActivatedReason,
|
||||||
|
],
|
||||||
|
'clear_sync_errors' => [
|
||||||
|
'blocked' => $clearSyncReason !== '',
|
||||||
|
'reason' => $clearSyncReason,
|
||||||
|
],
|
||||||
|
'clear_bmpa_errors' => [
|
||||||
|
'blocked' => $clearBmpaReason !== '',
|
||||||
|
'reason' => $clearBmpaReason,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $filters
|
||||||
|
*/
|
||||||
|
public static function batchActivateSubscriptionsReason(array $filters): string
|
||||||
|
{
|
||||||
|
if ((string) ($filters['syncable_only'] ?? '') !== '1') {
|
||||||
|
return '请先勾选「只看可同步」再执行批量同步。';
|
||||||
|
}
|
||||||
|
if ((string) ($filters['receipt_status'] ?? '') === 'none') {
|
||||||
|
return '当前集合为「无回执」:建议先补齐支付回执留痕后再批量同步。';
|
||||||
|
}
|
||||||
|
if (((string) ($filters['reconcile_mismatch'] ?? '') === '1') || ((string) ($filters['refund_inconsistent'] ?? '') === '1')) {
|
||||||
|
return '当前集合包含「对账不一致/退款不一致」:建议先完成金额/状态治理后再批量同步。';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $filters
|
||||||
|
*/
|
||||||
|
public static function batchBmpaReason(array $filters): string
|
||||||
|
{
|
||||||
|
if ((string) ($filters['status'] ?? '') !== 'pending' || (string) ($filters['payment_status'] ?? '') !== 'unpaid') {
|
||||||
|
return '请先筛选「订单状态=待处理」且「支付状态=未支付」再执行批量 BMPA。';
|
||||||
|
}
|
||||||
|
if (((string) ($filters['reconcile_mismatch'] ?? '') === '1') || ((string) ($filters['refund_inconsistent'] ?? '') === '1')) {
|
||||||
|
return '当前集合包含「对账不一致/退款不一致」治理集合:建议先完成回执/退款治理后再批量推进。';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $filters
|
||||||
|
*/
|
||||||
|
public static function batchMarkActivatedReason(array $filters): string
|
||||||
|
{
|
||||||
|
if ((string) ($filters['payment_status'] ?? '') !== 'paid' || (string) ($filters['status'] ?? '') !== 'pending') {
|
||||||
|
return '请先筛选「支付状态=已支付」且「订单状态=待处理」再执行批量生效。';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $filters
|
||||||
|
*/
|
||||||
|
public static function clearSyncErrorsReason(array $filters): string
|
||||||
|
{
|
||||||
|
if ((string) ($filters['sync_status'] ?? '') !== 'failed' && (string) ($filters['fail_only'] ?? '') === '') {
|
||||||
|
return '建议先筛选「同步失败」集合(sync_status=failed)后再执行清理,避免误清理。';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $filters
|
||||||
|
*/
|
||||||
|
public static function clearBmpaErrorsReason(array $filters): string
|
||||||
|
{
|
||||||
|
if ((string) ($filters['bmpa_failed_only'] ?? '') === ''
|
||||||
|
&& (string) ($filters['bmpa_error_keyword'] ?? '') === ''
|
||||||
|
&& (string) ($filters['batch_mark_paid_and_activate_24h'] ?? '') === '') {
|
||||||
|
return '建议先筛选「BMPA失败」集合(bmpa_failed_only=1 或失败原因关键词)后再执行清理,避免误清理。';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -827,18 +827,9 @@
|
|||||||
<div class="tool-group focus-box">
|
<div class="tool-group focus-box">
|
||||||
<div class="tool-group-title">批量同步订阅</div>
|
<div class="tool-group-title">批量同步订阅</div>
|
||||||
@php
|
@php
|
||||||
// 批量同步订阅:前端治理提示(后端仍有安全阀阻断,这里只做“减少误点/更可治理”)
|
$toolGuards = $toolGuards ?? \App\Support\PlatformOrderToolsGuard::forIndex((array) ($filters ?? []));
|
||||||
$batchActivateBlockedReason = '';
|
$batchActivateBlocked = (bool) ($toolGuards['batch_activate_subscriptions']['blocked'] ?? false);
|
||||||
if ((string) ($filters['syncable_only'] ?? '') !== '1') {
|
$batchActivateBlockedReason = (string) ($toolGuards['batch_activate_subscriptions']['reason'] ?? '');
|
||||||
$batchActivateBlockedReason = '请先勾选「只看可同步」再执行批量同步。';
|
|
||||||
}
|
|
||||||
if ($batchActivateBlockedReason === '' && ((string) ($filters['receipt_status'] ?? '') === 'none')) {
|
|
||||||
$batchActivateBlockedReason = '当前集合为「无回执」:建议先补齐支付回执留痕后再批量同步。';
|
|
||||||
}
|
|
||||||
if ($batchActivateBlockedReason === '' && (((string) ($filters['reconcile_mismatch'] ?? '') === '1') || ((string) ($filters['refund_inconsistent'] ?? '') === '1'))) {
|
|
||||||
$batchActivateBlockedReason = '当前集合包含「对账不一致/退款不一致」:建议先完成金额/状态治理后再批量同步。';
|
|
||||||
}
|
|
||||||
$batchActivateBlocked = $batchActivateBlockedReason !== '';
|
|
||||||
@endphp
|
@endphp
|
||||||
<form method="post" action="/admin/platform-orders/batch-activate-subscriptions" data-action="disable-on-submit" onsubmit="return confirm('确认批量同步当前筛选范围内“可同步”的订单?(仅处理:已支付+已生效+未同步)');" class="mb-10">
|
<form method="post" action="/admin/platform-orders/batch-activate-subscriptions" data-action="disable-on-submit" onsubmit="return confirm('确认批量同步当前筛选范围内“可同步”的订单?(仅处理:已支付+已生效+未同步)');" class="mb-10">
|
||||||
@csrf
|
@csrf
|
||||||
@@ -923,15 +914,9 @@
|
|||||||
<div class="tool-group focus-box">
|
<div class="tool-group focus-box">
|
||||||
<div class="tool-group-title">批量标记支付并生效(BMPA)</div>
|
<div class="tool-group-title">批量标记支付并生效(BMPA)</div>
|
||||||
@php
|
@php
|
||||||
// 批量 BMPA:前端治理提示(后端仍有安全阀阻断,这里只做“减少误点/更可治理”)
|
$toolGuards = $toolGuards ?? \App\Support\PlatformOrderToolsGuard::forIndex((array) ($filters ?? []));
|
||||||
$batchBmpaBlockedReason = '';
|
$batchBmpaBlocked = (bool) ($toolGuards['batch_bmpa']['blocked'] ?? false);
|
||||||
if ((string) ($filters['status'] ?? '') !== 'pending' || (string) ($filters['payment_status'] ?? '') !== 'unpaid') {
|
$batchBmpaBlockedReason = (string) ($toolGuards['batch_bmpa']['reason'] ?? '');
|
||||||
$batchBmpaBlockedReason = '请先筛选「订单状态=待处理」且「支付状态=未支付」再执行批量 BMPA。';
|
|
||||||
}
|
|
||||||
if ($batchBmpaBlockedReason === '' && (((string) ($filters['reconcile_mismatch'] ?? '') === '1') || ((string) ($filters['refund_inconsistent'] ?? '') === '1'))) {
|
|
||||||
$batchBmpaBlockedReason = '当前集合包含「对账不一致/退款不一致」治理集合:建议先完成回执/退款治理后再批量推进。';
|
|
||||||
}
|
|
||||||
$batchBmpaBlocked = $batchBmpaBlockedReason !== '';
|
|
||||||
@endphp
|
@endphp
|
||||||
<form method="post" action="/admin/platform-orders/batch-mark-paid-and-activate" data-action="disable-on-submit" onsubmit="return confirm('确认批量将当前筛选范围内“待处理+未支付”的订单标记为已支付并生效,并同步订阅?(会补回执留痕;遇到退款/回执不一致会安全阀阻断并记录失败原因)');" class="mb-10">
|
<form method="post" action="/admin/platform-orders/batch-mark-paid-and-activate" data-action="disable-on-submit" onsubmit="return confirm('确认批量将当前筛选范围内“待处理+未支付”的订单标记为已支付并生效,并同步订阅?(会补回执留痕;遇到退款/回执不一致会安全阀阻断并记录失败原因)');" class="mb-10">
|
||||||
@csrf
|
@csrf
|
||||||
@@ -994,12 +979,9 @@
|
|||||||
<div class="tool-group focus-box">
|
<div class="tool-group focus-box">
|
||||||
<div class="tool-group-title">批量仅标记为已生效</div>
|
<div class="tool-group-title">批量仅标记为已生效</div>
|
||||||
@php
|
@php
|
||||||
// 批量仅标记为已生效:前端治理提示(后端仍有安全阀阻断,这里只做“减少误点/更可治理”)
|
$toolGuards = $toolGuards ?? \App\Support\PlatformOrderToolsGuard::forIndex((array) ($filters ?? []));
|
||||||
$batchMarkActivatedBlockedReason = '';
|
$batchMarkActivatedBlocked = (bool) ($toolGuards['batch_mark_activated']['blocked'] ?? false);
|
||||||
if ((string) ($filters['payment_status'] ?? '') !== 'paid' || (string) ($filters['status'] ?? '') !== 'pending') {
|
$batchMarkActivatedBlockedReason = (string) ($toolGuards['batch_mark_activated']['reason'] ?? '');
|
||||||
$batchMarkActivatedBlockedReason = '请先筛选「支付状态=已支付」且「订单状态=待处理」再执行批量生效。';
|
|
||||||
}
|
|
||||||
$batchMarkActivatedBlocked = $batchMarkActivatedBlockedReason !== '';
|
|
||||||
@endphp
|
@endphp
|
||||||
<form method="post" action="/admin/platform-orders/batch-mark-activated" data-action="disable-on-submit" onsubmit="return confirm('确认批量将当前筛选范围内“已支付+待处理”的订单标记为已生效?(不修改支付状态,不自动同步订阅)');" class="mb-10">
|
<form method="post" action="/admin/platform-orders/batch-mark-activated" data-action="disable-on-submit" onsubmit="return confirm('确认批量将当前筛选范围内“已支付+待处理”的订单标记为已生效?(不修改支付状态,不自动同步订阅)');" class="mb-10">
|
||||||
@csrf
|
@csrf
|
||||||
@@ -1062,12 +1044,9 @@
|
|||||||
<div class="tool-group focus-box">
|
<div class="tool-group focus-box">
|
||||||
<div class="tool-group-title">清理失败标记:同步订阅</div>
|
<div class="tool-group-title">清理失败标记:同步订阅</div>
|
||||||
@php
|
@php
|
||||||
// 清理同步失败标记:前端治理提示(后端仍有 confirm=YES 等安全阀,这里只做“减少误点/更可治理”)
|
$toolGuards = $toolGuards ?? \App\Support\PlatformOrderToolsGuard::forIndex((array) ($filters ?? []));
|
||||||
$clearSyncBlockedReason = '';
|
$clearSyncBlocked = (bool) ($toolGuards['clear_sync_errors']['blocked'] ?? false);
|
||||||
if ((string) ($filters['sync_status'] ?? '') !== 'failed' && (string) ($filters['fail_only'] ?? '') === '') {
|
$clearSyncBlockedReason = (string) ($toolGuards['clear_sync_errors']['reason'] ?? '');
|
||||||
$clearSyncBlockedReason = '建议先筛选「同步失败」集合(sync_status=failed)后再执行清理,避免误清理。';
|
|
||||||
}
|
|
||||||
$clearSyncBlocked = $clearSyncBlockedReason !== '';
|
|
||||||
@endphp
|
@endphp
|
||||||
<form method="post" action="/admin/platform-orders/clear-sync-errors" data-action="disable-on-submit" onsubmit="return confirm('确认清除当前筛选范围内命中的订单的“同步失败”标记?');" class="mb-10">
|
<form method="post" action="/admin/platform-orders/clear-sync-errors" data-action="disable-on-submit" onsubmit="return confirm('确认清除当前筛选范围内命中的订单的“同步失败”标记?');" class="mb-10">
|
||||||
@csrf
|
@csrf
|
||||||
@@ -1121,12 +1100,9 @@
|
|||||||
<div class="tool-group focus-box">
|
<div class="tool-group focus-box">
|
||||||
<div class="tool-group-title">清理失败标记:批量 BMPA</div>
|
<div class="tool-group-title">清理失败标记:批量 BMPA</div>
|
||||||
@php
|
@php
|
||||||
// 清理 BMPA 失败标记:前端治理提示(建议先进入 BMPA 失败集合再清理,避免误清理)
|
$toolGuards = $toolGuards ?? \App\Support\PlatformOrderToolsGuard::forIndex((array) ($filters ?? []));
|
||||||
$clearBmpaBlockedReason = '';
|
$clearBmpaBlocked = (bool) ($toolGuards['clear_bmpa_errors']['blocked'] ?? false);
|
||||||
if ((string) ($filters['bmpa_failed_only'] ?? '') === '' && (string) ($filters['bmpa_error_keyword'] ?? '') === '' && (string) ($filters['batch_mark_paid_and_activate_24h'] ?? '') === '') {
|
$clearBmpaBlockedReason = (string) ($toolGuards['clear_bmpa_errors']['reason'] ?? '');
|
||||||
$clearBmpaBlockedReason = '建议先筛选「BMPA失败」集合(bmpa_failed_only=1 或失败原因关键词)后再执行清理,避免误清理。';
|
|
||||||
}
|
|
||||||
$clearBmpaBlocked = $clearBmpaBlockedReason !== '';
|
|
||||||
@endphp
|
@endphp
|
||||||
<form method="post" action="/admin/platform-orders/clear-bmpa-errors" data-action="disable-on-submit" onsubmit="return confirm('确认清除当前筛选范围内命中的订单的“批量标记支付失败”标记?');" class="mb-10">
|
<form method="post" action="/admin/platform-orders/clear-bmpa-errors" data-action="disable-on-submit" onsubmit="return confirm('确认清除当前筛选范围内命中的订单的“批量标记支付失败”标记?');" class="mb-10">
|
||||||
@csrf
|
@csrf
|
||||||
|
|||||||
Reference in New Issue
Block a user