feat(admin): platform orders filter by subscription id
This commit is contained in:
@@ -26,6 +26,8 @@ class PlatformOrderController extends Controller
|
||||
'payment_status' => trim((string) $request->query('payment_status', '')),
|
||||
'merchant_id' => trim((string) $request->query('merchant_id', '')),
|
||||
'plan_id' => trim((string) $request->query('plan_id', '')),
|
||||
// 精确过滤:订阅ID(用于从订阅详情页跳转到平台订单列表时锁定范围)
|
||||
'site_subscription_id' => trim((string) $request->query('site_subscription_id', '')),
|
||||
'fail_only' => (string) $request->query('fail_only', ''),
|
||||
'synced_only' => (string) $request->query('synced_only', ''),
|
||||
'sync_status' => trim((string) $request->query('sync_status', '')),
|
||||
@@ -219,6 +221,8 @@ class PlatformOrderController extends Controller
|
||||
'payment_status' => trim((string) $request->query('payment_status', '')),
|
||||
'merchant_id' => trim((string) $request->query('merchant_id', '')),
|
||||
'plan_id' => trim((string) $request->query('plan_id', '')),
|
||||
// 精确过滤:订阅ID(用于从订阅详情页跳转到平台订单列表时锁定范围)
|
||||
'site_subscription_id' => trim((string) $request->query('site_subscription_id', '')),
|
||||
'fail_only' => (string) $request->query('fail_only', ''),
|
||||
'synced_only' => (string) $request->query('synced_only', ''),
|
||||
'sync_status' => trim((string) $request->query('sync_status', '')),
|
||||
@@ -333,6 +337,7 @@ class PlatformOrderController extends Controller
|
||||
'payment_status' => trim((string) $request->input('payment_status', '')),
|
||||
'merchant_id' => trim((string) $request->input('merchant_id', '')),
|
||||
'plan_id' => trim((string) $request->input('plan_id', '')),
|
||||
'site_subscription_id' => trim((string) $request->input('site_subscription_id', '')),
|
||||
'fail_only' => (string) $request->input('fail_only', ''),
|
||||
'synced_only' => (string) $request->input('synced_only', ''),
|
||||
'sync_status' => trim((string) $request->input('sync_status', '')),
|
||||
@@ -458,6 +463,7 @@ class PlatformOrderController extends Controller
|
||||
'payment_status' => trim((string) $request->input('payment_status', '')),
|
||||
'merchant_id' => trim((string) $request->input('merchant_id', '')),
|
||||
'plan_id' => trim((string) $request->input('plan_id', '')),
|
||||
'site_subscription_id' => trim((string) $request->input('site_subscription_id', '')),
|
||||
'fail_only' => (string) $request->input('fail_only', ''),
|
||||
'synced_only' => (string) $request->input('synced_only', ''),
|
||||
'sync_status' => trim((string) $request->input('sync_status', '')),
|
||||
@@ -514,6 +520,7 @@ class PlatformOrderController extends Controller
|
||||
->when($filters['payment_status'] !== '', fn (Builder $builder) => $builder->where('payment_status', $filters['payment_status']))
|
||||
->when(($filters['merchant_id'] ?? '') !== '', fn (Builder $builder) => $builder->where('merchant_id', (int) $filters['merchant_id']))
|
||||
->when(($filters['plan_id'] ?? '') !== '', fn (Builder $builder) => $builder->where('plan_id', (int) $filters['plan_id']))
|
||||
->when(($filters['site_subscription_id'] ?? '') !== '', fn (Builder $builder) => $builder->where('site_subscription_id', (int) $filters['site_subscription_id']))
|
||||
->when(($filters['fail_only'] ?? '') !== '', function (Builder $builder) {
|
||||
// 只看同步失败:meta.subscription_activation_error.message 存在即视为失败
|
||||
$builder->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NOT NULL");
|
||||
|
||||
@@ -42,6 +42,8 @@
|
||||
<option value="synced" @selected(($filters['sync_status'] ?? '') === 'synced')>已同步</option>
|
||||
<option value="failed" @selected(($filters['sync_status'] ?? '') === 'failed')>同步失败</option>
|
||||
</select>
|
||||
|
||||
<input type="number" name="site_subscription_id" placeholder="订阅ID(可选)" value="{{ $filters['site_subscription_id'] ?? '' }}" class="w-140">
|
||||
<label class="form-inline-row">
|
||||
<input type="checkbox" name="fail_only" value="1" @checked(($filters['fail_only'] ?? '') === '1')>
|
||||
<span>只看同步失败</span>
|
||||
@@ -116,6 +118,7 @@
|
||||
<input type="hidden" name="payment_status" value="{{ $filters['payment_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="site_subscription_id" value="{{ $filters['site_subscription_id'] ?? '' }}">
|
||||
<input type="hidden" name="fail_only" value="{{ $filters['fail_only'] ?? '' }}">
|
||||
<input type="hidden" name="synced_only" value="{{ $filters['synced_only'] ?? '' }}">
|
||||
<input type="hidden" name="sync_status" value="{{ $filters['sync_status'] ?? '' }}">
|
||||
@@ -138,6 +141,7 @@
|
||||
<input type="hidden" name="payment_status" value="{{ $filters['payment_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="site_subscription_id" value="{{ $filters['site_subscription_id'] ?? '' }}">
|
||||
<input type="hidden" name="fail_only" value="{{ $filters['fail_only'] ?? '' }}">
|
||||
<input type="hidden" name="synced_only" value="{{ $filters['synced_only'] ?? '' }}">
|
||||
<input type="hidden" name="sync_status" value="{{ $filters['sync_status'] ?? '' }}">
|
||||
@@ -162,6 +166,7 @@
|
||||
<input type="hidden" name="payment_status" value="{{ $filters['payment_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="site_subscription_id" value="{{ $filters['site_subscription_id'] ?? '' }}">
|
||||
<input type="hidden" name="fail_only" value="{{ $filters['fail_only'] ?? '' }}">
|
||||
<input type="hidden" name="synced_only" value="{{ $filters['synced_only'] ?? '' }}">
|
||||
<input type="hidden" name="sync_status" value="{{ $filters['sync_status'] ?? '' }}">
|
||||
@@ -188,6 +193,7 @@
|
||||
<input type="hidden" name="payment_status" value="{{ $filters['payment_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="site_subscription_id" value="{{ $filters['site_subscription_id'] ?? '' }}">
|
||||
<input type="hidden" name="fail_only" value="{{ $filters['fail_only'] ?? '' }}">
|
||||
<input type="hidden" name="synced_only" value="{{ $filters['synced_only'] ?? '' }}">
|
||||
<input type="hidden" name="sync_status" value="{{ $filters['sync_status'] ?? '' }}">
|
||||
|
||||
@@ -358,4 +358,95 @@ class AdminPlatformOrderTest extends TestCase
|
||||
->assertDontSee('PO202603100101')
|
||||
->assertDontSee('PO202603100102');
|
||||
}
|
||||
|
||||
|
||||
public function test_platform_orders_page_can_filter_by_site_subscription_id(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$merchant = \App\Models\Merchant::query()->firstOrFail();
|
||||
$plan = \App\Models\Plan::query()->create([
|
||||
'code' => 'po_subid_test',
|
||||
'name' => '订阅ID筛选测试套餐',
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 10,
|
||||
'list_price' => 10,
|
||||
'status' => 'active',
|
||||
'sort' => 10,
|
||||
'published_at' => now(),
|
||||
]);
|
||||
|
||||
$sub1 = \App\Models\SiteSubscription::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'status' => 'activated',
|
||||
'source' => 'manual',
|
||||
'subscription_no' => 'SUB_FILTER_0001',
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => 'monthly',
|
||||
'period_months' => 1,
|
||||
'amount' => 10,
|
||||
'starts_at' => now()->subDay(),
|
||||
'ends_at' => now()->addMonth(),
|
||||
'activated_at' => now()->subDay(),
|
||||
]);
|
||||
|
||||
$sub2 = \App\Models\SiteSubscription::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'status' => 'activated',
|
||||
'source' => 'manual',
|
||||
'subscription_no' => 'SUB_FILTER_0002',
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => 'monthly',
|
||||
'period_months' => 1,
|
||||
'amount' => 10,
|
||||
'starts_at' => now()->subDay(),
|
||||
'ends_at' => now()->addMonth(),
|
||||
'activated_at' => now()->subDay(),
|
||||
]);
|
||||
|
||||
\App\Models\PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'site_subscription_id' => $sub1->id,
|
||||
'order_no' => 'PO_SUBID_0001',
|
||||
'order_type' => 'renewal',
|
||||
'status' => 'activated',
|
||||
'payment_status' => 'paid',
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => 'monthly',
|
||||
'period_months' => 1,
|
||||
'quantity' => 1,
|
||||
'payable_amount' => 10,
|
||||
'paid_amount' => 10,
|
||||
'placed_at' => now()->subMinutes(2),
|
||||
'paid_at' => now()->subMinute(),
|
||||
'activated_at' => now(),
|
||||
]);
|
||||
|
||||
\App\Models\PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'site_subscription_id' => $sub2->id,
|
||||
'order_no' => 'PO_SUBID_0002',
|
||||
'order_type' => 'renewal',
|
||||
'status' => 'activated',
|
||||
'payment_status' => 'paid',
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => 'monthly',
|
||||
'period_months' => 1,
|
||||
'quantity' => 1,
|
||||
'payable_amount' => 10,
|
||||
'paid_amount' => 10,
|
||||
'placed_at' => now()->subMinutes(2),
|
||||
'paid_at' => now()->subMinute(),
|
||||
'activated_at' => now(),
|
||||
]);
|
||||
|
||||
$this->get('/admin/platform-orders?site_subscription_id=' . $sub1->id)
|
||||
->assertOk()
|
||||
->assertSee('PO_SUBID_0001')
|
||||
->assertDontSee('PO_SUBID_0002');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user