diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php
index 152ad44..43b80ea 100644
--- a/app/Http/Controllers/Admin/PlatformOrderController.php
+++ b/app/Http/Controllers/Admin/PlatformOrderController.php
@@ -56,6 +56,17 @@ class PlatformOrderController extends Controller
$siteSubscription = SiteSubscription::query()->with(['merchant', 'plan'])->find($siteSubscriptionId);
}
+ // 续费下单场景:若带了 site_subscription_id,但未显式指定 merchant/plan,则从订阅上补齐默认值。
+ // 目的:让“从订阅维度跳转到下单页”的链路更稳,不必每次手工二次选择。
+ if ($siteSubscription) {
+ if ((int) ($defaults['merchant_id'] ?? 0) <= 0) {
+ $defaults['merchant_id'] = (int) ($siteSubscription->merchant_id ?? 0);
+ }
+ if ((int) ($defaults['plan_id'] ?? 0) <= 0) {
+ $defaults['plan_id'] = (int) ($siteSubscription->plan_id ?? 0);
+ }
+ }
+
return view('admin.platform_orders.form', [
'merchants' => $merchants,
'plans' => $plans,
diff --git a/tests/Feature/AdminPlatformOrderCreateDefaultsAutoFillFromSubscriptionTest.php b/tests/Feature/AdminPlatformOrderCreateDefaultsAutoFillFromSubscriptionTest.php
new file mode 100644
index 0000000..e2a597d
--- /dev/null
+++ b/tests/Feature/AdminPlatformOrderCreateDefaultsAutoFillFromSubscriptionTest.php
@@ -0,0 +1,69 @@
+seed();
+
+ $this->post('/admin/login', [
+ 'email' => 'platform.admin@demo.local',
+ 'password' => 'Platform@123456',
+ ])->assertRedirect('/admin');
+ }
+
+ public function test_create_form_should_autofill_merchant_and_plan_from_subscription_when_not_provided(): void
+ {
+ $this->loginAsPlatformAdmin();
+
+ $merchant = Merchant::query()->firstOrFail();
+ $plan = Plan::query()->create([
+ 'code' => 'po_defaults_autofill_from_sub_plan',
+ 'name' => '创建订单默认值:从订阅补齐 merchant/plan 测试套餐',
+ 'billing_cycle' => 'monthly',
+ 'price' => 100,
+ 'list_price' => 100,
+ 'status' => 'active',
+ 'sort' => 10,
+ 'published_at' => now(),
+ ]);
+
+ $sub = SiteSubscription::query()->create([
+ 'merchant_id' => $merchant->id,
+ 'plan_id' => $plan->id,
+ 'status' => 'activated',
+ 'source' => 'manual',
+ 'subscription_no' => 'SUB_AUTOFILL_0001',
+ 'plan_name' => $plan->name,
+ 'billing_cycle' => $plan->billing_cycle,
+ 'period_months' => 1,
+ 'amount' => 100,
+ 'starts_at' => now()->subDay(),
+ 'ends_at' => now()->addMonth(),
+ 'activated_at' => now()->subDay(),
+ ]);
+
+ // 仅传 site_subscription_id,不传 merchant_id / plan_id
+ $url = '/admin/platform-orders/create?site_subscription_id=' . $sub->id . '&order_type=renewal';
+
+ $res = $this->get($url);
+ $res->assertOk();
+
+ // 应自动预选订阅所属站点/套餐
+ $res->assertSee('