diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index f19d78f..643823a 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -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 diff --git a/resources/views/admin/platform_orders/show.blade.php b/resources/views/admin/platform_orders/show.blade.php index b36949b..cf215fb 100644 --- a/resources/views/admin/platform_orders/show.blade.php +++ b/resources/views/admin/platform_orders/show.blade.php @@ -615,6 +615,7 @@
追加一条支付回执(不自动改状态)
+ @csrf
@@ -693,6 +694,7 @@
追加一条退款记录(会自动推进支付状态) + @csrf
diff --git a/tests/Feature/AdminPlatformOrderAddPaymentReceiptShouldRedirectBackToShowWithAnchorAndBackTest.php b/tests/Feature/AdminPlatformOrderAddPaymentReceiptShouldRedirectBackToShowWithAnchorAndBackTest.php new file mode 100644 index 0000000..781fb64 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderAddPaymentReceiptShouldRedirectBackToShowWithAnchorAndBackTest.php @@ -0,0 +1,75 @@ +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); + } +} diff --git a/tests/Feature/AdminPlatformOrderAddRefundReceiptShouldRedirectBackToShowWithAnchorAndBackTest.php b/tests/Feature/AdminPlatformOrderAddRefundReceiptShouldRedirectBackToShowWithAnchorAndBackTest.php new file mode 100644 index 0000000..7a3ac82 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderAddRefundReceiptShouldRedirectBackToShowWithAnchorAndBackTest.php @@ -0,0 +1,77 @@ +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); + } +}