chore(governance): block batch activate when syncable_only conflicts with failed filters

This commit is contained in:
萝卜
2026-03-16 21:05:13 +08:00
parent 6790771364
commit 512de34da4
2 changed files with 64 additions and 0 deletions

View File

@@ -1424,6 +1424,19 @@ class PlatformOrderController extends Controller
return redirect()->back()->with('warning', '为避免误操作,请先在筛选条件中勾选「只看可同步」,再执行批量同步订阅。');
}
// 防误操作(口径一致):当已勾选 syncable_only=1 时,不允许叠加互斥的“同步状态/失败原因”筛选
// 说明syncable_only=1 的语义已统一为 unsynced未同步且非失败。若仍保留 sync_status=failed/synced 或失败原因关键词,
// 会导致集合为空或语义混乱;这里直接 warning 阻断,避免运营误解。
if ($scope === 'filtered' && ($filters['syncable_only'] ?? '') === '1') {
$syncStatus = (string) ($filters['sync_status'] ?? '');
if ($syncStatus !== '' && $syncStatus !== 'unsynced') {
return redirect()->back()->with('warning', '当前已勾选「只看可同步」,但同步状态筛选不是「未同步」。请先切回 sync_status=unsynced或清空同步状态筛选后再执行批量同步。');
}
if ((string) ($filters['fail_only'] ?? '') === '1' || trim((string) ($filters['sync_error_keyword'] ?? '')) !== '') {
return redirect()->back()->with('warning', '当前筛选包含「同步失败/失败原因」。请先治理失败原因或切回未同步集合,再执行批量同步。');
}
}
// 防误操作(治理优先):当筛选集合同时命中“对账不一致/退款不一致”时,不允许直接批量同步,避免把“带病订单”同步到订阅
if ($scope === 'filtered'
&& ($filters['syncable_only'] ?? '') === '1'

View File

@@ -0,0 +1,51 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderBatchActivateSubscriptionsShouldBlockWhenSyncableOnlyConflictsWithSyncStatusTest 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_activate_should_warn_and_block_when_syncable_only_and_sync_status_failed_present(): void
{
$this->loginAsPlatformAdmin();
$res = $this->post('/admin/platform-orders/batch-activate-subscriptions', [
'scope' => 'filtered',
'syncable_only' => '1',
'sync_status' => 'failed',
'limit' => 50,
]);
$res->assertRedirect();
$res->assertSessionHas('warning');
}
public function test_batch_activate_should_warn_and_block_when_syncable_only_and_sync_error_keyword_present(): void
{
$this->loginAsPlatformAdmin();
$res = $this->post('/admin/platform-orders/batch-activate-subscriptions', [
'scope' => 'filtered',
'syncable_only' => '1',
'sync_error_keyword' => 'demo',
'limit' => 50,
]);
$res->assertRedirect();
$res->assertSessionHas('warning');
}
}