chore(governance): block batch mark activated when reconcile/refund inconsistent

This commit is contained in:
萝卜
2026-03-16 23:16:25 +08:00
parent a26be5de9e
commit 75d64195d6
6 changed files with 89 additions and 2 deletions

View File

@@ -1884,6 +1884,11 @@ class PlatformOrderController extends Controller
if ((string) ($filters['syncable_only'] ?? '') === '1') { if ((string) ($filters['syncable_only'] ?? '') === '1') {
return redirect()->back()->with('warning', '当前已勾选「只看可同步」:该集合语义为“已生效(activated)+未同步”,与本动作处理的“待处理(pending)”互斥。请先取消只看可同步后再执行。'); return redirect()->back()->with('warning', '当前已勾选「只看可同步」:该集合语义为“已生效(activated)+未同步”,与本动作处理的“待处理(pending)”互斥。请先取消只看可同步后再执行。');
} }
// 治理优先:当筛选集合命中“对账不一致/退款不一致”时,不允许直接批量生效
if ((string) ($filters['reconcile_mismatch'] ?? '') === '1' || (string) ($filters['refund_inconsistent'] ?? '') === '1') {
return redirect()->back()->with('warning', '当前筛选集合包含「对账不一致/退款不一致」订单,为避免带病推进,请先完成金额/状态治理(补回执/核对退款/修正状态)后再执行批量仅标记为已生效。');
}
} }
// 防误操作scope=all 需要二次确认 // 防误操作scope=all 需要二次确认

View File

@@ -132,6 +132,9 @@ class PlatformOrderToolsGuard
if ((string) ($filters['syncable_only'] ?? '') === '1') { if ((string) ($filters['syncable_only'] ?? '') === '1') {
return '当前已勾选「只看可同步」:该集合语义为“已生效(activated)+未同步”,与本动作处理的“待处理(pending)”互斥。请先取消只看可同步后再执行。'; return '当前已勾选「只看可同步」:该集合语义为“已生效(activated)+未同步”,与本动作处理的“待处理(pending)”互斥。请先取消只看可同步后再执行。';
} }
if (((string) ($filters['reconcile_mismatch'] ?? '') === '1') || ((string) ($filters['refund_inconsistent'] ?? '') === '1')) {
return '当前集合包含「对账不一致/退款不一致」治理集合:建议先完成金额/状态治理(补回执/核对退款/修正状态)后再批量生效。';
}
return ''; return '';
} }

View File

@@ -73,7 +73,10 @@ class AdminPlatformOrderBatchMarkActivatedReceiptStatusFilterFieldsTest extends
$res->assertRedirect(); $res->assertRedirect();
// 口径升级:批量生效不再允许在“收费闭环缺口/需治理”的集合上直接推进
$res->assertSessionHas('warning');
$order->refresh(); $order->refresh();
$this->assertSame('activated', $order->status); $this->assertSame('pending', $order->status);
} }
} }

View File

@@ -77,8 +77,9 @@ class AdminPlatformOrderBatchMarkActivatedReconcileMismatchFilterFieldsTest exte
]); ]);
$res->assertRedirect(); $res->assertRedirect();
$res->assertSessionHas('warning');
$order->refresh(); $order->refresh();
$this->assertSame('activated', $order->status); $this->assertSame('pending', $order->status);
} }
} }

View File

@@ -0,0 +1,38 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderBatchMarkActivatedShouldBlockWhenRefundInconsistentTest extends TestCase
{
use RefreshDatabase;
protected function loginAsPlatformAdmin(): void
{
$this->seed();
$this->post('/admin/login', [
'email' => 'platform.admin@demo.local',
'password' => 'Platform@123456',
])->assertRedirect('/admin');
}
public function test_batch_mark_activated_should_block_when_refund_inconsistent_is_set(): void
{
$this->loginAsPlatformAdmin();
$res = $this->post('/admin/platform-orders/batch-mark-activated', [
'scope' => 'filtered',
'payment_status' => 'paid',
'status' => 'pending',
'sync_status' => 'unsynced',
'refund_inconsistent' => '1',
'limit' => 50,
]);
$res->assertRedirect();
$res->assertSessionHas('warning');
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderIndexBatchMarkActivatedButtonShouldDisableWhenRefundInconsistentTest extends TestCase
{
use RefreshDatabase;
protected function loginAsPlatformAdmin(): void
{
$this->seed();
$this->post('/admin/login', [
'email' => 'platform.admin@demo.local',
'password' => 'Platform@123456',
])->assertRedirect('/admin');
}
public function test_batch_mark_activated_button_should_disable_when_refund_inconsistent_is_set_even_if_paid_pending(): void
{
$this->loginAsPlatformAdmin();
$res = $this->get('/admin/platform-orders?payment_status=paid&status=pending&sync_status=unsynced&refund_inconsistent=1');
$res->assertOk();
$html = (string) $res->getContent();
$this->assertStringContainsString('批量仅标记为已生效(当前筛选范围)', $html);
$this->assertStringContainsString('data-role="batch-mark-activated-blocked-hint"', $html);
$this->assertStringContainsString('退款不一致', $html);
$this->assertTrue(str_contains($html, 'type="submit" disabled') || str_contains($html, 'disabled="disabled"'));
}
}