feat(admin): 关联订阅区块补齐续费缺订阅治理提示与查找订阅入口

This commit is contained in:
萝卜
2026-03-15 07:55:55 +00:00
parent 59d024cc93
commit 553b064e51
2 changed files with 105 additions and 0 deletions

View File

@@ -429,6 +429,37 @@
</table> </table>
@else @else
<p class="muted">该订单尚未关联订阅site_subscription_id 为空)。</p> <p class="muted">该订单尚未关联订阅site_subscription_id 为空)。</p>
@php
$isRenewalMissingSubscription = ((string) ($order->order_type ?? '') === 'renewal')
&& ((int) ($order->site_subscription_id ?? 0) <= 0);
$missingSubHelpUrlForRelationBlock = '';
if ($isRenewalMissingSubscription) {
$missingSubHelpUrlForRelationBlock = \App\Support\BackUrl::withBack('/admin/site-subscriptions?' . \Illuminate\Support\Arr::query([
'merchant_id' => (int) ($order->merchant_id ?? 0) ?: null,
'plan_id' => (int) ($order->plan_id ?? 0) ?: null,
'page' => null,
]), $orderShowSelf);
}
@endphp
@if($isRenewalMissingSubscription)
<div class="card governance-block mt-10">
<div class="muted text-danger governance-block-title"><strong>订阅关联治理提示</strong></div>
<div class="muted governance-block-body">
<div>
当前订单类型为「续费」但未绑定订阅site_subscription_id 为空)。
<span class="muted"></span>
<span class="muted">建议先找到正确订阅并补齐关联,再进行 BMPA/同步/标记生效等动作。</span>
@if($missingSubHelpUrlForRelationBlock !== '')
<span class="muted"></span>
<a class="btn btn-secondary btn-sm" href="{!! $missingSubHelpUrlForRelationBlock !!}">去订阅管理查找订阅</a>
@endif
</div>
</div>
</div>
@endif
@endif @endif
</div> </div>

View File

@@ -0,0 +1,74 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderShowRelationSubscriptionBlockShouldIncludeFindSubscriptionLinkWhenRenewalMissingSubscriptionTest 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_show_should_render_relation_governance_block_when_renewal_missing_subscription(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'po_show_relation_block_renewal_no_sub_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_SHOW_RELATION_BLOCK_RENEW_NO_SUB_0001',
'order_type' => 'renewal',
'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(),
'meta' => [],
]);
$res = $this->get('/admin/platform-orders/' . $order->id);
$res->assertOk();
$html = (string) $res->getContent();
$this->assertStringContainsString('订阅关联治理提示', $html);
$this->assertStringContainsString('续费', $html);
$this->assertStringContainsString('未绑定订阅', $html);
$this->assertStringContainsString('去订阅管理查找订阅', $html);
// 链接应包含 merchant_id/plan_id并携带 back 回到当前订单详情
$this->assertStringContainsString('/admin/site-subscriptions?', $html);
$this->assertStringContainsString('merchant_id=' . $merchant->id, $html);
$this->assertStringContainsString('plan_id=' . $plan->id, $html);
$this->assertStringContainsString('back=' . urlencode('/admin/platform-orders/' . $order->id), $html);
}
}