feat(platform-orders): 增加批量生效24h筛选与统计
This commit is contained in:
@@ -134,8 +134,11 @@ class PlatformOrderController extends Controller
|
||||
'syncable_only' => (string) $request->query('syncable_only', ''),
|
||||
// 只看最近 24 小时批量同步过的订单(可治理追踪)
|
||||
'batch_synced_24h' => (string) $request->query('batch_synced_24h', ''),
|
||||
// 只看最近 24 小时批量“仅标记为已生效”过的订单(可治理追踪)
|
||||
'batch_mark_activated_24h' => (string) $request->query('batch_mark_activated_24h', ''),
|
||||
];
|
||||
|
||||
|
||||
$orders = $this->applyFilters(PlatformOrder::query()->with(['merchant', 'plan', 'siteSubscription']), $filters)
|
||||
->latest('id')
|
||||
->paginate(10)
|
||||
@@ -224,6 +227,21 @@ class PlatformOrderController extends Controller
|
||||
$q->whereRaw("JSON_UNQUOTE(JSON_EXTRACT(meta, '$.batch_activation.at')) >= ?", [$since]);
|
||||
}
|
||||
|
||||
return $q->count();
|
||||
})(),
|
||||
'batch_mark_activated_24h_orders' => (function () use ($baseQuery) {
|
||||
$since = now()->subHours(24)->format('Y-m-d H:i:s');
|
||||
|
||||
$q = (clone $baseQuery)
|
||||
->whereRaw("JSON_EXTRACT(meta, '$.batch_mark_activated.at') IS NOT NULL");
|
||||
|
||||
$driver = $q->getQuery()->getConnection()->getDriverName();
|
||||
if ($driver === 'sqlite') {
|
||||
$q->whereRaw("JSON_EXTRACT(meta, '$.batch_mark_activated.at') >= ?", [$since]);
|
||||
} else {
|
||||
$q->whereRaw("JSON_UNQUOTE(JSON_EXTRACT(meta, '$.batch_mark_activated.at')) >= ?", [$since]);
|
||||
}
|
||||
|
||||
return $q->count();
|
||||
})(),
|
||||
],
|
||||
@@ -363,8 +381,11 @@ class PlatformOrderController extends Controller
|
||||
'syncable_only' => (string) $request->query('syncable_only', ''),
|
||||
// 只看最近 24 小时批量同步过的订单(可治理追踪)
|
||||
'batch_synced_24h' => (string) $request->query('batch_synced_24h', ''),
|
||||
// 只看最近 24 小时批量“仅标记为已生效”过的订单(可治理追踪)
|
||||
'batch_mark_activated_24h' => (string) $request->query('batch_mark_activated_24h', ''),
|
||||
];
|
||||
|
||||
|
||||
$includeMeta = (string) $request->query('include_meta', '') === '1';
|
||||
|
||||
$query = $this->applyFilters(
|
||||
@@ -817,6 +838,19 @@ class PlatformOrderController extends Controller
|
||||
} else {
|
||||
$builder->whereRaw("JSON_UNQUOTE(JSON_EXTRACT(meta, '$.batch_activation.at')) >= ?", [$since]);
|
||||
}
|
||||
})
|
||||
->when(($filters['batch_mark_activated_24h'] ?? '') !== '', function (Builder $builder) {
|
||||
// 只看最近 24 小时批量“仅标记为已生效”过的订单(基于 meta.batch_mark_activated.at)
|
||||
$since = now()->subHours(24)->format('Y-m-d H:i:s');
|
||||
|
||||
$builder->whereRaw("JSON_EXTRACT(meta, '$.batch_mark_activated.at') IS NOT NULL");
|
||||
|
||||
$driver = $builder->getQuery()->getConnection()->getDriverName();
|
||||
if ($driver === 'sqlite') {
|
||||
$builder->whereRaw("JSON_EXTRACT(meta, '$.batch_mark_activated.at') >= ?", [$since]);
|
||||
} else {
|
||||
$builder->whereRaw("JSON_UNQUOTE(JSON_EXTRACT(meta, '$.batch_mark_activated.at')) >= ?", [$since]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,10 @@
|
||||
<input type="checkbox" name="batch_synced_24h" value="1" @checked(($filters['batch_synced_24h'] ?? '') === '1')>
|
||||
<span>最近24小时批量同步过</span>
|
||||
</label>
|
||||
<label class="form-inline-row">
|
||||
<input type="checkbox" name="batch_mark_activated_24h" value="1" @checked(($filters['batch_mark_activated_24h'] ?? '') === '1')>
|
||||
<span>最近24小时批量生效过</span>
|
||||
</label>
|
||||
<input type="text" name="keyword" placeholder="关键词:订单号/站点/订阅号" value="{{ $filters['keyword'] ?? '' }}">
|
||||
<div>
|
||||
<button type="submit">应用筛选</button>
|
||||
@@ -108,6 +112,11 @@
|
||||
<div class="metric-number">{{ $summaryStats['batch_synced_24h_orders'] ?? 0 }}</div>
|
||||
<div class="muted muted-xs">基于 meta.batch_activation.at</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h3>近24小时批量生效</h3>
|
||||
<div class="metric-number">{{ $summaryStats['batch_mark_activated_24h_orders'] ?? 0 }}</div>
|
||||
<div class="muted muted-xs">基于 meta.batch_mark_activated.at</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h3>同步失败原因 TOP5</h3>
|
||||
@php $failedReasonStats = $failedReasonStats ?? []; @endphp
|
||||
@@ -138,6 +147,7 @@
|
||||
<input type="hidden" name="sync_status" value="{{ $filters['sync_status'] ?? '' }}">
|
||||
<input type="hidden" name="syncable_only" value="{{ $filters['syncable_only'] ?? '' }}">
|
||||
<input type="hidden" name="batch_synced_24h" value="{{ $filters['batch_synced_24h'] ?? '' }}">
|
||||
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
|
||||
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
|
||||
|
||||
<label class="form-inline-row mb-8">
|
||||
@@ -161,6 +171,7 @@
|
||||
<input type="hidden" name="sync_status" value="{{ $filters['sync_status'] ?? '' }}">
|
||||
<input type="hidden" name="syncable_only" value="{{ $filters['syncable_only'] ?? '' }}">
|
||||
<input type="hidden" name="batch_synced_24h" value="{{ $filters['batch_synced_24h'] ?? '' }}">
|
||||
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
|
||||
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
|
||||
|
||||
<label class="muted form-inline-row mb-8">
|
||||
@@ -186,6 +197,7 @@
|
||||
<input type="hidden" name="sync_status" value="{{ $filters['sync_status'] ?? '' }}">
|
||||
<input type="hidden" name="syncable_only" value="{{ $filters['syncable_only'] ?? '' }}">
|
||||
<input type="hidden" name="batch_synced_24h" value="{{ $filters['batch_synced_24h'] ?? '' }}">
|
||||
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
|
||||
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
|
||||
<label class="muted form-inline-row mb-8">
|
||||
<span>确认输入</span>
|
||||
@@ -252,6 +264,7 @@
|
||||
<input type="hidden" name="sync_status" value="{{ $filters['sync_status'] ?? '' }}">
|
||||
<input type="hidden" name="syncable_only" value="{{ $filters['syncable_only'] ?? '' }}">
|
||||
<input type="hidden" name="batch_synced_24h" value="{{ $filters['batch_synced_24h'] ?? '' }}">
|
||||
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
|
||||
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
|
||||
<button type="submit">清除当前筛选范围的失败标记</button>
|
||||
</form>
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
<?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 AdminPlatformOrderBatchMarkActivated24hFilterTest 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_platform_orders_page_can_filter_by_batch_mark_activated_24h(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$merchant = Merchant::query()->firstOrFail();
|
||||
$plan = Plan::query()->create([
|
||||
'code' => 'batch_mark_activated_24h_plan',
|
||||
'name' => '批量生效24h筛选测试套餐',
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 10,
|
||||
'list_price' => 10,
|
||||
'status' => 'active',
|
||||
'sort' => 10,
|
||||
'published_at' => now(),
|
||||
]);
|
||||
|
||||
PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'order_no' => 'PO_MARK24H_RECENT',
|
||||
'order_type' => 'renewal',
|
||||
'status' => 'activated',
|
||||
'payment_status' => 'paid',
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => $plan->billing_cycle,
|
||||
'period_months' => 1,
|
||||
'quantity' => 1,
|
||||
'payable_amount' => 10,
|
||||
'paid_amount' => 10,
|
||||
'placed_at' => now()->subMinutes(20),
|
||||
'paid_at' => now()->subMinutes(18),
|
||||
'activated_at' => now()->subMinutes(10),
|
||||
'meta' => [
|
||||
'batch_mark_activated' => [
|
||||
'at' => now()->toDateTimeString(),
|
||||
'admin_id' => 1,
|
||||
'scope' => 'filtered',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'order_no' => 'PO_MARK24H_OLD',
|
||||
'order_type' => 'renewal',
|
||||
'status' => 'activated',
|
||||
'payment_status' => 'paid',
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => $plan->billing_cycle,
|
||||
'period_months' => 1,
|
||||
'quantity' => 1,
|
||||
'payable_amount' => 10,
|
||||
'paid_amount' => 10,
|
||||
'placed_at' => now()->subHours(30),
|
||||
'paid_at' => now()->subHours(30),
|
||||
'activated_at' => now()->subHours(30),
|
||||
'meta' => [
|
||||
'batch_mark_activated' => [
|
||||
'at' => now()->subHours(30)->toDateTimeString(),
|
||||
'admin_id' => 1,
|
||||
'scope' => 'filtered',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$res = $this->get('/admin/platform-orders?batch_mark_activated_24h=1');
|
||||
$res->assertOk();
|
||||
$res->assertSee('PO_MARK24H_RECENT');
|
||||
$res->assertDontSee('PO_MARK24H_OLD');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user