feat: subscriptions index add create renewal order quick link
This commit is contained in:
@@ -129,14 +129,32 @@
|
||||
|
||||
<div class="card mb-20">
|
||||
<h3>工具</h3>
|
||||
<form method="get" action="/admin/site-subscriptions/export">
|
||||
<input type="hidden" name="status" value="{{ $filters['status'] ?? '' }}">
|
||||
<input type="hidden" name="merchant_id" value="{{ $filters['merchant_id'] ?? '' }}">
|
||||
<input type="hidden" name="plan_id" value="{{ $filters['plan_id'] ?? '' }}">
|
||||
<input type="hidden" name="expiry" value="{{ $filters['expiry'] ?? '' }}">
|
||||
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
|
||||
<button type="submit">导出当前筛选结果(CSV)</button>
|
||||
</form>
|
||||
<div class="grid-2">
|
||||
<form method="get" action="/admin/site-subscriptions/export">
|
||||
<input type="hidden" name="status" value="{{ $filters['status'] ?? '' }}">
|
||||
<input type="hidden" name="merchant_id" value="{{ $filters['merchant_id'] ?? '' }}">
|
||||
<input type="hidden" name="plan_id" value="{{ $filters['plan_id'] ?? '' }}">
|
||||
<input type="hidden" name="expiry" value="{{ $filters['expiry'] ?? '' }}">
|
||||
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
|
||||
<button type="submit">导出当前筛选结果(CSV)</button>
|
||||
</form>
|
||||
|
||||
@php
|
||||
$q = [
|
||||
'order_type' => 'renewal',
|
||||
'back' => $selfWithoutBack,
|
||||
];
|
||||
if ((int) ($filters['merchant_id'] ?? 0) > 0) {
|
||||
$q['merchant_id'] = (int) $filters['merchant_id'];
|
||||
}
|
||||
if ((int) ($filters['plan_id'] ?? 0) > 0) {
|
||||
$q['plan_id'] = (int) $filters['plan_id'];
|
||||
}
|
||||
$createOrderFromSubIndexUrl = '/admin/platform-orders/create?' . \Illuminate\Support\Arr::query($q);
|
||||
@endphp
|
||||
<a class="btn" href="{!! $createOrderFromSubIndexUrl !!}">创建续费订单(带当前筛选)</a>
|
||||
</div>
|
||||
<div class="muted muted-xs" style="margin-top:6px;">用于运营从订阅目录快速补单/续费:会把当前 merchant_id/plan_id/site_subscription_id 作为默认值带到下单页。</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Merchant;
|
||||
use App\Models\Plan;
|
||||
use App\Models\SiteSubscription;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Arr;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminSiteSubscriptionIndexCreateRenewalOrderLinkTest 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_index_should_render_create_renewal_order_link_with_current_filters_and_safe_back(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$merchant = Merchant::query()->firstOrFail();
|
||||
$plan = Plan::query()->create([
|
||||
'code' => 'sub_index_create_order_plan',
|
||||
'name' => '订阅列表创建续费订单测试套餐',
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 10,
|
||||
'list_price' => 10,
|
||||
'status' => 'active',
|
||||
'sort' => 10,
|
||||
'published_at' => now(),
|
||||
]);
|
||||
|
||||
SiteSubscription::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'status' => 'activated',
|
||||
'source' => 'manual',
|
||||
'subscription_no' => 'SUB_INDEX_CREATE_ORDER_0001',
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => $plan->billing_cycle,
|
||||
'period_months' => 1,
|
||||
'amount' => 10,
|
||||
'starts_at' => now()->subDay(),
|
||||
'ends_at' => now()->addMonth(),
|
||||
'activated_at' => now()->subDay(),
|
||||
]);
|
||||
|
||||
// 模拟:订阅列表本身带 back(避免嵌套),同时带 merchant_id/plan_id 筛选
|
||||
$currentUrl = '/admin/site-subscriptions?' . Arr::query([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'status' => 'activated',
|
||||
'back' => '/admin',
|
||||
]);
|
||||
|
||||
$res = $this->get($currentUrl);
|
||||
$res->assertOk();
|
||||
|
||||
$selfWithoutBack = '/admin/site-subscriptions?' . Arr::query([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'status' => 'activated',
|
||||
]);
|
||||
|
||||
// 不依赖 query 顺序:解析 href 后按键值断言
|
||||
$html = $res->getContent();
|
||||
|
||||
preg_match_all('/href="([^"]+)"/', $html, $matches);
|
||||
$hrefs = $matches[1] ?? [];
|
||||
|
||||
$createUrls = array_values(array_filter($hrefs, fn ($u) => str_contains($u, '/admin/platform-orders/create?')));
|
||||
$this->assertNotEmpty($createUrls, '未找到创建续费订单链接');
|
||||
|
||||
$found = false;
|
||||
foreach ($createUrls as $u) {
|
||||
$parts = parse_url($u);
|
||||
parse_str($parts['query'] ?? '', $q);
|
||||
|
||||
if (($q['order_type'] ?? '') === 'renewal'
|
||||
&& (string) ($q['merchant_id'] ?? '') === (string) $merchant->id
|
||||
&& (string) ($q['plan_id'] ?? '') === (string) $plan->id
|
||||
&& (string) ($q['back'] ?? '') === $selfWithoutBack) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertTrue($found, '未找到包含当前筛选条件与 back 的创建续费订单链接');
|
||||
$res->assertSee('创建续费订单(带当前筛选)', false);
|
||||
|
||||
// 防 back 嵌套
|
||||
$res->assertDontSee('back%3D', false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user