订单详情:标记支付并生效的治理安全阀提示

This commit is contained in:
萝卜
2026-03-11 08:43:22 +00:00
parent 87df857d4d
commit f9b3af82b3
2 changed files with 125 additions and 0 deletions

View File

@@ -129,6 +129,15 @@
$canMarkPaid = ($order->payment_status !== 'paid') || ($order->status !== 'activated'); $canMarkPaid = ($order->payment_status !== 'paid') || ($order->status !== 'activated');
$syncError = data_get($order->meta, 'subscription_activation_error.message'); $syncError = data_get($order->meta, 'subscription_activation_error.message');
$syncErrorAt = data_get($order->meta, 'subscription_activation_error.at'); $syncErrorAt = data_get($order->meta, 'subscription_activation_error.at');
// 治理提示:标记支付并生效的安全阀(后端也会阻断)
$refundTotal = (float) $order->refundTotal();
$receiptTotal = (float) $order->receiptTotal();
$expectedPaid = (float) (((float) ($order->paid_amount ?? 0)) > 0 ? (float) $order->paid_amount : (float) ($order->payable_amount ?? 0));
$receiptCents = (int) round($receiptTotal * 100);
$expectedCents = (int) round($expectedPaid * 100);
$markPaidBlockedByRefund = $refundTotal > 0;
$markPaidBlockedByReceiptMismatch = $receiptCents > 0 && abs($receiptCents - $expectedCents) >= 1;
@endphp @endphp
<div style="margin-top:16px; display:flex; gap:12px; flex-wrap:wrap; align-items:center;"> <div style="margin-top:16px; display:flex; gap:12px; flex-wrap:wrap; align-items:center;">
@@ -137,6 +146,12 @@
<button type="submit" @disabled(! $canMarkPaid)>标记支付并生效</button> <button type="submit" @disabled(! $canMarkPaid)>标记支付并生效</button>
</form> </form>
@if($markPaidBlockedByRefund)
<div class="muted text-danger" style="margin-top:6px; width:100%;">提示:当前订单已存在退款记录/退款汇总,建议先核对退款轨迹与状态后再进行「标记支付并生效」。</div>
@elseif($markPaidBlockedByReceiptMismatch)
<div class="muted text-danger" style="margin-top:6px; width:100%;">提示:当前订单已存在支付回执,但回执总额与订单金额不一致,建议先补齐/修正回执后再进行「标记支付并生效」。</div>
@endif
<form method="post" action="/admin/platform-orders/{{ $order->id }}/activate-subscription" onsubmit="return confirm('确认同步订阅?将根据该订单创建/续期订阅');"> <form method="post" action="/admin/platform-orders/{{ $order->id }}/activate-subscription" onsubmit="return confirm('确认同步订阅?将根据该订单创建/续期订阅');">
@csrf @csrf
<button type="submit" @disabled(! $canActivate || $alreadySynced)>{{ $alreadySynced ? '已同步' : '同步订阅' }}</button> <button type="submit" @disabled(! $canActivate || $alreadySynced)>{{ $alreadySynced ? '已同步' : '同步订阅' }}</button>

View File

@@ -0,0 +1,110 @@
<?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 AdminPlatformOrderShowMarkPaidGovernanceHintTest 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_order_show_page_shows_hint_when_mark_paid_blocked_by_refund_total(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'show_mark_paid_hint_refund_test',
'name' => '详情页标记支付提示(退款)测试套餐',
'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_SHOW_MARK_PAID_HINT_REFUND_0001',
'order_type' => 'new_purchase',
'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(),
'meta' => [
'refund_summary' => [
'count' => 1,
'total_amount' => 1.00,
],
],
]);
$this->get('/admin/platform-orders/' . $order->id)
->assertOk()
->assertSee('已存在退款记录/退款汇总', false);
}
public function test_order_show_page_shows_hint_when_mark_paid_blocked_by_receipt_mismatch(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'show_mark_paid_hint_receipt_test',
'name' => '详情页标记支付提示(回执差额)测试套餐',
'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_SHOW_MARK_PAID_HINT_RECEIPT_0002',
'order_type' => 'new_purchase',
'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(),
'meta' => [
'payment_summary' => [
'count' => 1,
'total_amount' => 29.98,
],
],
]);
$this->get('/admin/platform-orders/' . $order->id)
->assertOk()
->assertSee('已存在支付回执,但回执总额与订单金额不一致', false);
}
}