feat(subscriptions): 订阅详情支持一键创建续费订单

This commit is contained in:
萝卜
2026-03-10 14:46:16 +00:00
parent 3f809c8150
commit 6ebd3510db
4 changed files with 23 additions and 8 deletions

View File

@@ -27,11 +27,23 @@ class PlatformOrderController extends Controller
$merchants = Merchant::query()->orderBy('id')->get(['id', 'name']);
$plans = Plan::query()->orderBy('sort')->orderByDesc('id')->get();
// 支持从其它页面(例如订阅详情)带默认值跳转过来,提高运营效率
$defaults = [
'merchant_id' => (int) $request->query('merchant_id', 0),
'plan_id' => (int) $request->query('plan_id', 0),
'order_type' => (string) $request->query('order_type', 'new_purchase'),
'quantity' => (int) $request->query('quantity', 1),
'discount_amount' => (float) $request->query('discount_amount', 0),
'payment_channel' => (string) $request->query('payment_channel', ''),
'remark' => (string) $request->query('remark', ''),
];
return view('admin.platform_orders.form', [
'merchants' => $merchants,
'plans' => $plans,
'billingCycleLabels' => $this->billingCycleLabels(),
'orderTypeLabels' => $this->orderTypeLabels(),
'defaults' => $defaults,
]);
}

View File

@@ -17,7 +17,7 @@
<select name="merchant_id" required>
<option value="">请选择站点</option>
@foreach(($merchants ?? []) as $m)
<option value="{{ $m->id }}" @selected((string)old('merchant_id') === (string)$m->id)>{{ $m->name }}</option>
<option value="{{ $m->id }}" @selected((string)old('merchant_id', $defaults['merchant_id'] ?? '') === (string)$m->id)>{{ $m->name }}</option>
@endforeach
</select>
</label>
@@ -27,7 +27,7 @@
<select name="plan_id" required>
<option value="">请选择套餐</option>
@foreach(($plans ?? []) as $p)
<option value="{{ $p->id }}" @selected((string)old('plan_id') === (string)$p->id)>
<option value="{{ $p->id }}" @selected((string)old('plan_id', $defaults['plan_id'] ?? '') === (string)$p->id)>
{{ $p->name }}{{ $billingCycleLabels[$p->billing_cycle] ?? $p->billing_cycle }} / ¥{{ number_format((float)$p->price, 2) }}
</option>
@endforeach
@@ -39,31 +39,31 @@
<span>订单类型</span>
<select name="order_type" required>
@foreach(($orderTypeLabels ?? []) as $value => $label)
<option value="{{ $value }}" @selected(old('order_type', 'new_purchase') === $value)>{{ $label }}</option>
<option value="{{ $value }}" @selected(old('order_type', $defaults['order_type'] ?? 'new_purchase') === $value)>{{ $label }}</option>
@endforeach
</select>
</label>
<label>
<span>购买数量(周期数)</span>
<input type="number" min="1" max="120" name="quantity" value="{{ old('quantity', 1) }}" required>
<input type="number" min="1" max="120" name="quantity" value="{{ old('quantity', $defaults['quantity'] ?? 1) }}" required>
<small class="muted">例如:月付套餐 quantity=3 表示购买 3 个月;年付套餐 quantity=2 表示购买 2 年。</small>
</label>
<label>
<span>优惠金额(可选)</span>
<input type="number" step="0.01" min="0" name="discount_amount" value="{{ old('discount_amount', 0) }}">
<input type="number" step="0.01" min="0" name="discount_amount" value="{{ old('discount_amount', $defaults['discount_amount'] ?? 0) }}">
</label>
<label>
<span>支付渠道(可选)</span>
<input name="payment_channel" value="{{ old('payment_channel') }}" placeholder="例如offline / wechat / alipay">
<input name="payment_channel" value="{{ old('payment_channel', $defaults['payment_channel'] ?? '') }}" placeholder="例如offline / wechat / alipay">
<small class="muted">当前阶段仅用于记录口径,支付回执/对账后续再补。</small>
</label>
<label class="full">
<span>备注(可选)</span>
<textarea name="remark" rows="3" placeholder="可记录线下收款说明、对账备注等">{{ old('remark') }}</textarea>
<textarea name="remark" rows="3" placeholder="可记录线下收款说明、对账备注等">{{ old('remark', $defaults['remark'] ?? '') }}</textarea>
</label>
<div class="form-actions">

View File

@@ -73,6 +73,8 @@
<a href="/admin/platform-orders?site_subscription_id={{ $subscription->id }}" class="muted">查看关联平台订单按订阅ID精确过滤</a>
<span class="muted"></span>
<a href="/admin/platform-orders?site_subscription_id={{ $subscription->id }}&syncable_only=1" class="muted">查看可同步订单</a>
<span class="muted"></span>
<a href="/admin/platform-orders/create?merchant_id={{ $subscription->merchant_id }}&plan_id={{ $subscription->plan_id }}&order_type=renewal&quantity=1&remark={{ urlencode('来自订阅:' . $subscription->subscription_no) }}" class="muted">创建续费订单</a>
@endif
</div>

View File

@@ -96,7 +96,8 @@ class AdminSiteSubscriptionShowTest extends TestCase
->assertSee('同步时间')
->assertSee('失败原因')
->assertSee('查看关联平台订单按订阅ID精确过滤')
->assertSee('查看可同步订单');
->assertSee('查看可同步订单')
->assertSee('/admin/platform-orders/create?merchant_id=' . $merchant->id . '&plan_id=' . $plan->id, false);
}
public function test_guest_cannot_open_site_subscription_show_page(): void