Admin subscriptions: expiring 7d add merchant+plan top10 and renewal CTA
This commit is contained in:
@@ -333,6 +333,7 @@ class SiteSubscriptionController extends Controller
|
|||||||
$baseQuery = $this->applyFilters(SiteSubscription::query(), $filters);
|
$baseQuery = $this->applyFilters(SiteSubscription::query(), $filters);
|
||||||
|
|
||||||
$expiryMerchantRows = [];
|
$expiryMerchantRows = [];
|
||||||
|
$expiryMerchantPlanRows = [];
|
||||||
if ((string) ($filters['expiry'] ?? '') === 'expiring_7d') {
|
if ((string) ($filters['expiry'] ?? '') === 'expiring_7d') {
|
||||||
// 到期提醒清单:站点维度 Top10(用于运营快速触达/续费跟进)
|
// 到期提醒清单:站点维度 Top10(用于运营快速触达/续费跟进)
|
||||||
$expiryMerchantRows = $this->applyFilters(SiteSubscription::query(), $filters)
|
$expiryMerchantRows = $this->applyFilters(SiteSubscription::query(), $filters)
|
||||||
@@ -354,6 +355,30 @@ class SiteSubscriptionController extends Controller
|
|||||||
})
|
})
|
||||||
->values()
|
->values()
|
||||||
->all();
|
->all();
|
||||||
|
|
||||||
|
// 到期提醒清单:站点+套餐维度 Top10(更精确的续费下单入口)
|
||||||
|
$expiryMerchantPlanRows = $this->applyFilters(SiteSubscription::query(), $filters)
|
||||||
|
->leftJoin('merchants', 'site_subscriptions.merchant_id', '=', 'merchants.id')
|
||||||
|
->leftJoin('plans', 'site_subscriptions.plan_id', '=', 'plans.id')
|
||||||
|
->whereNotNull('site_subscriptions.ends_at')
|
||||||
|
->selectRaw('site_subscriptions.merchant_id as merchant_id, merchants.name as merchant_name, site_subscriptions.plan_id as plan_id, plans.name as plan_name, count(*) as cnt, min(site_subscriptions.ends_at) as min_ends_at')
|
||||||
|
->groupBy('site_subscriptions.merchant_id', 'merchants.name', 'site_subscriptions.plan_id', 'plans.name')
|
||||||
|
->orderByDesc('cnt')
|
||||||
|
->orderBy('min_ends_at')
|
||||||
|
->limit(10)
|
||||||
|
->get()
|
||||||
|
->map(function ($row) {
|
||||||
|
return [
|
||||||
|
'merchant_id' => (int) ($row->merchant_id ?? 0),
|
||||||
|
'merchant_name' => (string) ($row->merchant_name ?? ''),
|
||||||
|
'plan_id' => (int) ($row->plan_id ?? 0),
|
||||||
|
'plan_name' => (string) ($row->plan_name ?? ''),
|
||||||
|
'count' => (int) ($row->cnt ?? 0),
|
||||||
|
'min_ends_at' => (string) ($row->min_ends_at ?? ''),
|
||||||
|
];
|
||||||
|
})
|
||||||
|
->values()
|
||||||
|
->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('admin.site_subscriptions.index', [
|
return view('admin.site_subscriptions.index', [
|
||||||
@@ -382,6 +407,7 @@ class SiteSubscriptionController extends Controller
|
|||||||
->count(),
|
->count(),
|
||||||
],
|
],
|
||||||
'expiryMerchantRows' => $expiryMerchantRows,
|
'expiryMerchantRows' => $expiryMerchantRows,
|
||||||
|
'expiryMerchantPlanRows' => $expiryMerchantPlanRows,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -147,6 +147,58 @@
|
|||||||
@endforelse
|
@endforelse
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<div class="mt-16">
|
||||||
|
<div class="muted"><strong>7天内到期|站点 + 套餐维度提醒清单(Top10)</strong></div>
|
||||||
|
<div class="muted muted-xs mt-6">用于更精确续费下单:按到期订阅数排序,展示最早到期时间;并提供 merchant+plan 的续费下单入口。</div>
|
||||||
|
|
||||||
|
<table class="mt-10" data-role="expiring-7d-merchant-plan-top10">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>站点</th>
|
||||||
|
<th>套餐</th>
|
||||||
|
<th>到期订阅数</th>
|
||||||
|
<th>最早到期</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@forelse(($expiryMerchantPlanRows ?? []) as $row)
|
||||||
|
@php
|
||||||
|
$mid = (int) ($row['merchant_id'] ?? 0);
|
||||||
|
$mname = (string) ($row['merchant_name'] ?? '');
|
||||||
|
$pid = (int) ($row['plan_id'] ?? 0);
|
||||||
|
$pname = (string) ($row['plan_name'] ?? '');
|
||||||
|
$cnt = (int) ($row['count'] ?? 0);
|
||||||
|
$minEndsAt = (string) ($row['min_ends_at'] ?? '');
|
||||||
|
$mpUrl = $buildSelfUrl(['merchant_id' => $mid, 'plan_id' => $pid, 'page' => null]);
|
||||||
|
|
||||||
|
$renewalCtaUrlByMerchantPlan = \App\Support\BackUrl::withBack('/admin/platform-orders/create?' . \Illuminate\Support\Arr::query([
|
||||||
|
'order_type' => 'renewal',
|
||||||
|
'require_subscription' => '1',
|
||||||
|
'merchant_id' => $mid,
|
||||||
|
'plan_id' => $pid,
|
||||||
|
]), $selfWithoutBack);
|
||||||
|
@endphp
|
||||||
|
<tr>
|
||||||
|
<td><a class="link" href="{!! $mpUrl !!}">{{ $mname !== '' ? $mname : ('站点#' . $mid) }}</a></td>
|
||||||
|
<td>{{ $pname !== '' ? $pname : ('套餐#' . $pid) }}</td>
|
||||||
|
<td>{{ $cnt }}</td>
|
||||||
|
<td>
|
||||||
|
{{ $minEndsAt !== '' ? $minEndsAt : '-' }}
|
||||||
|
<div class="muted muted-xs mt-6">
|
||||||
|
<a class="link" href="{!! $renewalCtaUrlByMerchantPlan !!}">去创建续费订单</a>
|
||||||
|
<span class="muted">(merchant+plan 预填)</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@empty
|
||||||
|
<tr>
|
||||||
|
<td colspan="4" class="muted">暂无数据</td>
|
||||||
|
</tr>
|
||||||
|
@endforelse
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Models\Merchant;
|
||||||
|
use App\Models\Plan;
|
||||||
|
use App\Models\SiteSubscription;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AdminSiteSubscriptionIndexExpiring7dMerchantPlanTop10ShouldIncludeRenewalCtaTest 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_expiring_7d_merchant_plan_top10_should_include_create_renewal_order_cta_with_plan_id_and_back(): void
|
||||||
|
{
|
||||||
|
$this->loginAsPlatformAdmin();
|
||||||
|
|
||||||
|
$merchant = Merchant::query()->firstOrFail();
|
||||||
|
$plan = Plan::query()->create([
|
||||||
|
'code' => 'sub_expiry_top10_cta_plan_with_plan_id',
|
||||||
|
'name' => '到期治理 CTA(带 plan_id)测试套餐',
|
||||||
|
'billing_cycle' => 'monthly',
|
||||||
|
'price' => 1,
|
||||||
|
'list_price' => 1,
|
||||||
|
'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_EXP_TOP10_CTA_PLAN_0001',
|
||||||
|
'plan_name' => $plan->name,
|
||||||
|
'billing_cycle' => $plan->billing_cycle,
|
||||||
|
'period_months' => 1,
|
||||||
|
'amount' => 1,
|
||||||
|
'starts_at' => now()->subDays(10),
|
||||||
|
'ends_at' => now()->addDays(3),
|
||||||
|
'activated_at' => now()->subDays(10),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$res = $this->get('/admin/site-subscriptions?expiry=expiring_7d');
|
||||||
|
$res->assertOk();
|
||||||
|
|
||||||
|
$html = (string) $res->getContent();
|
||||||
|
|
||||||
|
$this->assertStringContainsString('站点 + 套餐维度提醒清单', $html);
|
||||||
|
$this->assertStringContainsString('data-role="expiring-7d-merchant-plan-top10"', $html);
|
||||||
|
|
||||||
|
// CTA 链接应包含 merchant_id + plan_id,并保持 require_subscription=1。
|
||||||
|
$this->assertStringContainsString('/admin/platform-orders/create?', $html);
|
||||||
|
$this->assertStringContainsString('order_type=renewal', $html);
|
||||||
|
$this->assertStringContainsString('require_subscription=1', $html);
|
||||||
|
$this->assertStringContainsString('merchant_id=' . $merchant->id, $html);
|
||||||
|
$this->assertStringContainsString('plan_id=' . $plan->id, $html);
|
||||||
|
|
||||||
|
// back 必须回到仪表盘(selfWithoutBack=/admin)。
|
||||||
|
$this->assertStringContainsString('back=%2Fadmin', $html);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user