单笔同步订阅:治理优先安全阀 + 测试修复
This commit is contained in:
@@ -359,6 +359,11 @@ class PlatformOrderController extends Controller
|
|||||||
{
|
{
|
||||||
$admin = $this->ensurePlatformAdmin($request);
|
$admin = $this->ensurePlatformAdmin($request);
|
||||||
|
|
||||||
|
// 治理优先:当订单命中金额/状态不一致时,不建议直接同步订阅(避免把“带病订单”同步到订阅)
|
||||||
|
if ($order->isReconcileMismatch() || $order->isRefundInconsistent()) {
|
||||||
|
return redirect()->back()->with('warning', '当前订单命中「对账不一致/退款不一致」,为避免带病同步,请先完成金额/状态治理(补回执/核对退款/修正状态)后再同步订阅。');
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$subscription = $service->activateOrder($order->id, $admin->id);
|
$subscription = $service->activateOrder($order->id, $admin->id);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
<?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 AdminPlatformOrderActivateSubscriptionGovernanceSafetyValveTest 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_activate_subscription_blocked_when_order_is_reconcile_mismatch(): void
|
||||||
|
{
|
||||||
|
$this->loginAsPlatformAdmin();
|
||||||
|
|
||||||
|
$merchant = Merchant::query()->firstOrFail();
|
||||||
|
$plan = Plan::query()->create([
|
||||||
|
'code' => 'activate_subscription_gov_safety_valve_test',
|
||||||
|
'name' => '单笔同步治理安全阀测试套餐',
|
||||||
|
'billing_cycle' => 'monthly',
|
||||||
|
'price' => 66,
|
||||||
|
'list_price' => 66,
|
||||||
|
'status' => 'active',
|
||||||
|
'sort' => 10,
|
||||||
|
'published_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$order = PlatformOrder::query()->create([
|
||||||
|
'merchant_id' => $merchant->id,
|
||||||
|
'plan_id' => $plan->id,
|
||||||
|
'order_no' => 'PO_ACT_GOV_BLOCK_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' => 66,
|
||||||
|
'paid_amount' => 66,
|
||||||
|
'placed_at' => now()->subMinutes(10),
|
||||||
|
'paid_at' => now()->subMinutes(5),
|
||||||
|
'activated_at' => now()->subMinutes(1),
|
||||||
|
// 对账不一致:receipt_total 65.98 vs paid_amount 66
|
||||||
|
'meta' => [
|
||||||
|
'payment_summary' => [
|
||||||
|
'count' => 1,
|
||||||
|
'total_amount' => 65.98,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$res = $this->post('/admin/platform-orders/' . $order->id . '/activate-subscription');
|
||||||
|
$res->assertRedirect();
|
||||||
|
$res->assertSessionHas('warning');
|
||||||
|
|
||||||
|
$order->refresh();
|
||||||
|
$this->assertNull($order->site_subscription_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -56,6 +56,13 @@ class AdminPlatformOrderActivateSubscriptionTest extends TestCase
|
|||||||
'placed_at' => now()->subMinutes(10),
|
'placed_at' => now()->subMinutes(10),
|
||||||
'paid_at' => now()->subMinutes(5),
|
'paid_at' => now()->subMinutes(5),
|
||||||
'activated_at' => now()->subMinutes(1),
|
'activated_at' => now()->subMinutes(1),
|
||||||
|
// 避免命中“治理优先”安全阀:构造回执与已付金额一致
|
||||||
|
'meta' => [
|
||||||
|
'payment_summary' => [
|
||||||
|
'count' => 1,
|
||||||
|
'total_amount' => 66.00,
|
||||||
|
],
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->post('/admin/platform-orders/' . $order->id . '/activate-subscription')
|
$this->post('/admin/platform-orders/' . $order->id . '/activate-subscription')
|
||||||
|
|||||||
Reference in New Issue
Block a user