diff --git a/resources/views/admin/platform_orders/index.blade.php b/resources/views/admin/platform_orders/index.blade.php index b0cb2eb..1f7a59a 100644 --- a/resources/views/admin/platform_orders/index.blade.php +++ b/resources/views/admin/platform_orders/index.blade.php @@ -826,6 +826,20 @@
批量同步订阅
+ @php + // 批量同步订阅:前端治理提示(后端仍有安全阀阻断,这里只做“减少误点/更可治理”) + $batchActivateBlockedReason = ''; + if ((string) ($filters['syncable_only'] ?? '') !== '1') { + $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
@csrf @@ -860,7 +874,10 @@
提示:建议先勾选筛选条件「只看可同步」,再执行批量同步。
- + + @if($batchActivateBlocked) +
提示:{{ $batchActivateBlockedReason }}
+ @endif
diff --git a/tests/Feature/AdminPlatformOrderIndexBatchActivateButtonShouldDisableWhenNotSyncableOnlyOrReceiptNoneTest.php b/tests/Feature/AdminPlatformOrderIndexBatchActivateButtonShouldDisableWhenNotSyncableOnlyOrReceiptNoneTest.php new file mode 100644 index 0000000..4aea16e --- /dev/null +++ b/tests/Feature/AdminPlatformOrderIndexBatchActivateButtonShouldDisableWhenNotSyncableOnlyOrReceiptNoneTest.php @@ -0,0 +1,124 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_batch_activate_button_should_disable_when_syncable_only_not_checked(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'po_index_batch_sync_btn_disable_plan', + 'name' => '批量同步按钮禁用测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_IDX_BATCH_SYNC_BTN_DISABLE_0001', + 'order_type' => 'new_purchase', + 'status' => 'activated', + 'payment_status' => 'paid', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'quantity' => 1, + 'payable_amount' => 10, + 'paid_amount' => 10, + 'placed_at' => now(), + 'paid_at' => now(), + 'activated_at' => now(), + 'meta' => [ + 'payment_summary' => [ + 'count' => 1, + 'total_amount' => 10, + ], + ], + ]); + + // 未勾选 syncable_only=1 + $res = $this->get('/admin/platform-orders?payment_status=paid&status=activated'); + $res->assertOk(); + + $html = (string) $res->getContent(); + + $this->assertStringContainsString('批量同步订阅(当前筛选范围)', $html); + $this->assertStringContainsString('disabled', $html); + $this->assertStringContainsString('data-role="batch-activate-subscriptions-blocked-hint"', $html); + $this->assertStringContainsString('只看可同步', $html); + } + + public function test_batch_activate_button_should_disable_when_receipt_status_none(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'po_index_batch_sync_btn_disable_receipt_none_plan', + 'name' => '批量同步按钮禁用无回执测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_IDX_BATCH_SYNC_BTN_DISABLE_RC_NONE_0001', + 'order_type' => 'new_purchase', + 'status' => 'activated', + 'payment_status' => 'paid', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'quantity' => 1, + 'payable_amount' => 10, + 'paid_amount' => 10, + 'placed_at' => now(), + 'paid_at' => now(), + 'activated_at' => now(), + // meta 为空 => 无回执 + 'meta' => [], + ]); + + // 勾选 syncable_only=1 且 receipt_status=none + $res = $this->get('/admin/platform-orders?syncable_only=1&receipt_status=none'); + $res->assertOk(); + + $html = (string) $res->getContent(); + + $this->assertStringContainsString('批量同步订阅(当前筛选范围)', $html); + $this->assertStringContainsString('disabled', $html); + $this->assertStringContainsString('无回执', $html); + $this->assertStringContainsString('data-role="batch-activate-subscriptions-blocked-hint"', $html); + } +}