批量BMPA 安全阀:续费单未绑订阅不允许推进并新增测试

This commit is contained in:
萝卜
2026-03-15 04:56:18 +00:00
parent 61e615efac
commit a50cd0675e
2 changed files with 81 additions and 0 deletions

View File

@@ -1536,6 +1536,11 @@ class PlatformOrderController extends Controller
} }
try { try {
// 治理优先:续费单必须绑定订阅(兼容历史脏数据/手工改库等场景)
if ((string) ($order->order_type ?? '') === 'renewal' && ! (int) ($order->site_subscription_id ?? 0)) {
throw new \InvalidArgumentException('续费单未绑定订阅site_subscription_id 为空),不允许批量标记支付并生效。');
}
// 治理优先:若该订单已有退款轨迹,则不允许推进 // 治理优先:若该订单已有退款轨迹,则不允许推进
if ((float) $order->refundTotal() > 0) { if ((float) $order->refundTotal() > 0) {
throw new \InvalidArgumentException('订单存在退款轨迹,不允许批量标记支付并生效,请先完成退款治理。'); throw new \InvalidArgumentException('订单存在退款轨迹,不允许批量标记支付并生效,请先完成退款治理。');

View File

@@ -0,0 +1,76 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderBatchMarkPaidAndActivateRenewalMissingSubscriptionShouldFailTest 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_paid_and_activate_should_fail_when_renewal_order_missing_subscription(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'batch_bmpa_renewal_no_sub_plan',
'name' => '批量BMPA 续费无订阅安全阀测试套餐',
'billing_cycle' => 'monthly',
'price' => 30,
'list_price' => 30,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$order = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_BATCH_BMPA_RENEW_NO_SUB_0001',
'order_type' => 'renewal',
'status' => 'pending',
'payment_status' => 'unpaid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 30,
'paid_amount' => 0,
'placed_at' => now()->subMinutes(5),
'meta' => [],
]);
$res = $this->post('/admin/platform-orders/batch-mark-paid-and-activate', [
'scope' => 'filtered',
'status' => 'pending',
'payment_status' => 'unpaid',
'limit' => 50,
]);
$res->assertRedirect();
$order->refresh();
$this->assertSame('unpaid', $order->payment_status);
$this->assertSame('pending', $order->status);
$this->assertNull($order->site_subscription_id);
$msg = (string) (data_get($order->meta, 'batch_mark_paid_and_activate_error.message') ?? '');
$this->assertNotSame('', $msg);
$this->assertStringContainsString('续费单未绑定订阅', $msg);
}
}