admin: 回执追加后重定向回详情并保留 back + 锚点

This commit is contained in:
萝卜
2026-03-17 21:46:08 +08:00
parent 4fafd80b75
commit 2ea92cd6f1
4 changed files with 172 additions and 2 deletions

View File

@@ -989,7 +989,15 @@ class PlatformOrderController extends Controller
$order->meta = $meta;
$order->save();
return redirect()->back()->with('success', '已追加支付回执记录(仅用于对账留痕,不自动改状态)。');
$safeBack = BackUrl::sanitizeForLinks((string) $request->input('back', ''));
$redirectUrl = '/admin/platform-orders/' . $order->id;
if ($safeBack !== '') {
$redirectUrl .= '?' . \Illuminate\Support\Arr::query(['back' => $safeBack]);
}
return redirect($redirectUrl . '#payment-receipts')
->with('success', '已追加支付回执记录(仅用于对账留痕,不自动改状态)。');
}
public function addRefundReceipt(Request $request, PlatformOrder $order): RedirectResponse
@@ -1081,7 +1089,15 @@ class PlatformOrderController extends Controller
$order->meta = $meta;
$order->save();
return redirect()->back()->with('success', '已追加退款记录(用于退款轨迹留痕)。');
$safeBack = BackUrl::sanitizeForLinks((string) $request->input('back', ''));
$redirectUrl = '/admin/platform-orders/' . $order->id;
if ($safeBack !== '') {
$redirectUrl .= '?' . \Illuminate\Support\Arr::query(['back' => $safeBack]);
}
return redirect($redirectUrl . '#refund-receipts')
->with('success', '已追加退款记录(用于退款轨迹留痕)。');
}
public function markRefunded(Request $request, PlatformOrder $order): RedirectResponse

View File

@@ -615,6 +615,7 @@
<details class="mt-12 collapsible" id="add-payment-receipt" data-storage-key="admin.platform_orders.add_payment_receipt">
<summary class="collapsible-summary muted">追加一条支付回执(不自动改状态)</summary>
<form method="post" action="/admin/platform-orders/{{ $order->id }}/add-payment-receipt" class="mt-10 collapsible-body" data-action="disable-on-submit">
<input type="hidden" name="back" value="{{ $safeBackForLinks }}">
@csrf
<div class="grid-3">
<input type="text" name="type" placeholder="类型bank_transfer/现金/支付宝等" value="bank_transfer">
@@ -693,6 +694,7 @@
<details class="mt-12 collapsible" id="add-refund-receipt" data-storage-key="admin.platform_orders.add_refund_receipt">
<summary class="collapsible-summary muted">追加一条退款记录(会自动推进支付状态)</summary>
<form method="post" action="/admin/platform-orders/{{ $order->id }}/add-refund-receipt" class="mt-10 collapsible-body" data-action="disable-on-submit" onsubmit="return confirm('确认追加退款记录?该操作会写入退款轨迹,并可能推进支付状态为部分退款/已退款');">
<input type="hidden" name="back" value="{{ $safeBackForLinks }}">
@csrf
<div class="grid-3">
<input type="text" name="type" placeholder="类型refund/chargeback/手工退款等" value="refund">

View File

@@ -0,0 +1,75 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Arr;
use Tests\TestCase;
class AdminPlatformOrderAddPaymentReceiptShouldRedirectBackToShowWithAnchorAndBackTest 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_add_payment_receipt_should_redirect_to_show_with_back_and_payment_anchor(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'add_payment_receipt_redirect_back_anchor_plan',
'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_ADD_PAYMENT_RECEIPT_REDIRECT_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(),
]);
$back = '/admin/platform-orders?reconcile_mismatch=1';
$res = $this->post('/admin/platform-orders/' . $order->id . '/add-payment-receipt', [
'type' => 'bank_transfer',
'channel' => 'icbc',
'amount' => 30,
'paid_at' => now()->format('Y-m-d H:i:s'),
'note' => '测试回执',
'back' => $back,
]);
$expected = '/admin/platform-orders/' . $order->id . '?' . Arr::query([
'back' => $back,
]) . '#payment-receipts';
$res->assertRedirect($expected);
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Arr;
use Tests\TestCase;
class AdminPlatformOrderAddRefundReceiptShouldRedirectBackToShowWithAnchorAndBackTest 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_add_refund_receipt_should_redirect_to_show_with_back_and_refund_anchor(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'add_refund_receipt_redirect_back_anchor_plan',
'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_ADD_REFUND_RECEIPT_REDIRECT_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' => 30,
'paid_amount' => 30,
'placed_at' => now(),
'paid_at' => now(),
'activated_at' => now(),
]);
$back = '/admin/platform-orders?refund_inconsistent=1';
$res = $this->post('/admin/platform-orders/' . $order->id . '/add-refund-receipt', [
'type' => 'refund',
'channel' => 'icbc',
'amount' => 10,
'refunded_at' => now()->format('Y-m-d H:i:s'),
'note' => '测试退款',
'back' => $back,
]);
$expected = '/admin/platform-orders/' . $order->id . '?' . Arr::query([
'back' => $back,
]) . '#refund-receipts';
$res->assertRedirect($expected);
}
}