Add bmpa error keyword filter and stats for batch mark paid+activate governance
This commit is contained in:
@@ -143,6 +143,8 @@ class PlatformOrderController extends Controller
|
||||
'keyword' => trim((string) $request->query('keyword', '')),
|
||||
// 同步失败原因关键词:用于快速定位同原因失败订单(可治理)
|
||||
'sync_error_keyword' => trim((string) $request->query('sync_error_keyword', '')),
|
||||
// 批量“标记支付并生效”失败原因关键词:用于定位同原因失败订单(可治理)
|
||||
'bmpa_error_keyword' => trim((string) $request->query('bmpa_error_keyword', '')),
|
||||
// 只看“可同步订阅”的订单:已支付 + 已生效 + 未同步(用于运营快速处理)
|
||||
'syncable_only' => (string) $request->query('syncable_only', ''),
|
||||
// 只看最近 24 小时批量同步过的订单(可治理追踪)
|
||||
@@ -189,6 +191,15 @@ class PlatformOrderController extends Controller
|
||||
->limit($topN)
|
||||
->get();
|
||||
|
||||
// 批量“标记支付并生效”失败原因聚合(Top 5)
|
||||
$bmpaFailedReasonRows = (clone $baseQuery)
|
||||
->whereRaw("JSON_EXTRACT(meta, '$.batch_mark_paid_and_activate_error.message') IS NOT NULL")
|
||||
->selectRaw("JSON_EXTRACT(meta, '$.batch_mark_paid_and_activate_error.message') as reason, count(*) as cnt")
|
||||
->groupBy('reason')
|
||||
->orderByDesc('cnt')
|
||||
->limit($topN)
|
||||
->get();
|
||||
|
||||
$failedReasonStats = $failedReasonRows->map(function ($row) {
|
||||
$reason = (string) ($row->reason ?? '');
|
||||
$reason = trim($reason, "\" ");
|
||||
@@ -199,6 +210,16 @@ class PlatformOrderController extends Controller
|
||||
];
|
||||
})->values()->all();
|
||||
|
||||
$bmpaFailedReasonStats = $bmpaFailedReasonRows->map(function ($row) {
|
||||
$reason = (string) ($row->reason ?? '');
|
||||
$reason = trim($reason, "\" ");
|
||||
|
||||
return [
|
||||
'reason' => $reason !== '' ? $reason : '(空)',
|
||||
'count' => (int) ($row->cnt ?? 0),
|
||||
];
|
||||
})->values()->all();
|
||||
|
||||
// 运营摘要中的 meta 汇总(refund/payment)需要遍历订单 meta。
|
||||
// 为避免重复 get(),在当前筛选范围内一次性拉取所需字段。
|
||||
$metaOrders = (clone $baseQuery)->get(['id', 'paid_amount', 'meta']);
|
||||
@@ -342,6 +363,7 @@ class PlatformOrderController extends Controller
|
||||
})(),
|
||||
],
|
||||
'failedReasonStats' => $failedReasonStats,
|
||||
'bmpaFailedReasonStats' => $bmpaFailedReasonStats,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -802,6 +824,8 @@ class PlatformOrderController extends Controller
|
||||
'keyword' => trim((string) $request->query('keyword', '')),
|
||||
// 同步失败原因关键词:用于快速定位同原因失败订单(可治理)
|
||||
'sync_error_keyword' => trim((string) $request->query('sync_error_keyword', '')),
|
||||
// 批量“标记支付并生效”失败原因关键词:用于定位同原因失败订单(可治理)
|
||||
'bmpa_error_keyword' => trim((string) $request->query('bmpa_error_keyword', '')),
|
||||
// 只看“可同步订阅”的订单:已支付 + 已生效 + 未同步(用于运营快速处理)
|
||||
'syncable_only' => (string) $request->query('syncable_only', ''),
|
||||
// 只看最近 24 小时批量同步过的订单(可治理追踪)
|
||||
@@ -1563,6 +1587,20 @@ class PlatformOrderController extends Controller
|
||||
$builder->whereRaw("JSON_UNQUOTE(JSON_EXTRACT(meta, '$.subscription_activation_error.message')) LIKE ?", ['%' . $kw . '%']);
|
||||
}
|
||||
})
|
||||
->when(($filters['bmpa_error_keyword'] ?? '') !== '', function (Builder $builder) use ($filters) {
|
||||
// 批量“标记支付并生效”失败原因关键词:batch_mark_paid_and_activate_error.message like
|
||||
$kw = trim((string) ($filters['bmpa_error_keyword'] ?? ''));
|
||||
if ($kw === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$driver = $builder->getQuery()->getConnection()->getDriverName();
|
||||
if ($driver === 'sqlite') {
|
||||
$builder->whereRaw("JSON_EXTRACT(meta, '$.batch_mark_paid_and_activate_error.message') LIKE ?", ['%' . $kw . '%']);
|
||||
} else {
|
||||
$builder->whereRaw("JSON_UNQUOTE(JSON_EXTRACT(meta, '$.batch_mark_paid_and_activate_error.message')) LIKE ?", ['%' . $kw . '%']);
|
||||
}
|
||||
})
|
||||
->when(($filters['syncable_only'] ?? '') !== '', function (Builder $builder) {
|
||||
// 只看可同步:已支付 + 已生效 + 尚未写入 subscription_activation.subscription_id
|
||||
$builder->where('payment_status', 'paid')
|
||||
|
||||
@@ -118,7 +118,8 @@
|
||||
<span>只看退款不一致(状态 vs 退款总额)</span>
|
||||
</label>
|
||||
<input type="text" name="keyword" placeholder="关键词:订单号/站点/订阅号" value="{{ $filters['keyword'] ?? '' }}">
|
||||
<input type="text" name="sync_error_keyword" placeholder="失败原因关键词(可选)" value="{{ $filters['sync_error_keyword'] ?? '' }}">
|
||||
<input type="text" name="sync_error_keyword" placeholder="同步失败原因关键词(可选)" value="{{ $filters['sync_error_keyword'] ?? '' }}">
|
||||
<input type="text" name="bmpa_error_keyword" placeholder="批量标记支付并生效失败原因关键词(可选)" value="{{ $filters['bmpa_error_keyword'] ?? '' }}">
|
||||
<div>
|
||||
<button type="submit">应用筛选</button>
|
||||
</div>
|
||||
@@ -343,6 +344,7 @@
|
||||
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
|
||||
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
|
||||
<input type="hidden" name="sync_error_keyword" value="{{ $filters['sync_error_keyword'] ?? '' }}">
|
||||
<input type="hidden" name="bmpa_error_keyword" value="{{ $filters['bmpa_error_keyword'] ?? '' }}">
|
||||
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">
|
||||
<input type="hidden" name="refund_inconsistent" value="{{ $filters['refund_inconsistent'] ?? '' }}">
|
||||
|
||||
@@ -372,6 +374,7 @@
|
||||
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
|
||||
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
|
||||
<input type="hidden" name="sync_error_keyword" value="{{ $filters['sync_error_keyword'] ?? '' }}">
|
||||
<input type="hidden" name="bmpa_error_keyword" value="{{ $filters['bmpa_error_keyword'] ?? '' }}">
|
||||
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">
|
||||
<input type="hidden" name="refund_inconsistent" value="{{ $filters['refund_inconsistent'] ?? '' }}">
|
||||
|
||||
@@ -403,6 +406,7 @@
|
||||
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
|
||||
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
|
||||
<input type="hidden" name="sync_error_keyword" value="{{ $filters['sync_error_keyword'] ?? '' }}">
|
||||
<input type="hidden" name="bmpa_error_keyword" value="{{ $filters['bmpa_error_keyword'] ?? '' }}">
|
||||
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">
|
||||
<input type="hidden" name="refund_inconsistent" value="{{ $filters['refund_inconsistent'] ?? '' }}">
|
||||
<label class="muted form-inline-row mb-8">
|
||||
@@ -436,6 +440,7 @@
|
||||
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
|
||||
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
|
||||
<input type="hidden" name="sync_error_keyword" value="{{ $filters['sync_error_keyword'] ?? '' }}">
|
||||
<input type="hidden" name="bmpa_error_keyword" value="{{ $filters['bmpa_error_keyword'] ?? '' }}">
|
||||
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">
|
||||
<input type="hidden" name="refund_inconsistent" value="{{ $filters['refund_inconsistent'] ?? '' }}">
|
||||
|
||||
@@ -483,6 +488,7 @@
|
||||
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
|
||||
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
|
||||
<input type="hidden" name="sync_error_keyword" value="{{ $filters['sync_error_keyword'] ?? '' }}">
|
||||
<input type="hidden" name="bmpa_error_keyword" value="{{ $filters['bmpa_error_keyword'] ?? '' }}">
|
||||
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">
|
||||
<input type="hidden" name="refund_inconsistent" value="{{ $filters['refund_inconsistent'] ?? '' }}">
|
||||
|
||||
@@ -530,6 +536,7 @@
|
||||
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
|
||||
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
|
||||
<input type="hidden" name="sync_error_keyword" value="{{ $filters['sync_error_keyword'] ?? '' }}">
|
||||
<input type="hidden" name="bmpa_error_keyword" value="{{ $filters['bmpa_error_keyword'] ?? '' }}">
|
||||
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">
|
||||
<input type="hidden" name="refund_inconsistent" value="{{ $filters['refund_inconsistent'] ?? '' }}">
|
||||
<button type="submit">清除当前筛选范围的失败标记</button>
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
<?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 AdminPlatformOrderBmpaErrorKeywordFilterTest 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_bmpa_error_keyword(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$merchant = Merchant::query()->firstOrFail();
|
||||
$plan = Plan::query()->create([
|
||||
'code' => 'bmpa_error_kw_plan',
|
||||
'name' => '批量标记支付失败关键词筛选测试套餐',
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 10,
|
||||
'list_price' => 10,
|
||||
'status' => 'active',
|
||||
'sort' => 10,
|
||||
'published_at' => now(),
|
||||
]);
|
||||
|
||||
$hit = PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'order_no' => 'PO_BMPA_KW_HIT',
|
||||
'order_type' => 'new_purchase',
|
||||
'status' => 'pending',
|
||||
'payment_status' => 'unpaid',
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => $plan->billing_cycle,
|
||||
'period_months' => 1,
|
||||
'quantity' => 1,
|
||||
'payable_amount' => 10,
|
||||
'paid_amount' => 0,
|
||||
'placed_at' => now(),
|
||||
'meta' => [
|
||||
'batch_mark_paid_and_activate_error' => [
|
||||
'message' => '回执总额与应付金额不一致',
|
||||
'at' => now()->toDateTimeString(),
|
||||
'admin_id' => 1,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'order_no' => 'PO_BMPA_KW_MISS',
|
||||
'order_type' => 'new_purchase',
|
||||
'status' => 'pending',
|
||||
'payment_status' => 'unpaid',
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => $plan->billing_cycle,
|
||||
'period_months' => 1,
|
||||
'quantity' => 1,
|
||||
'payable_amount' => 10,
|
||||
'paid_amount' => 0,
|
||||
'placed_at' => now(),
|
||||
'meta' => [
|
||||
'batch_mark_paid_and_activate_error' => [
|
||||
'message' => '存在退款轨迹',
|
||||
'at' => now()->toDateTimeString(),
|
||||
'admin_id' => 1,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$res = $this->get('/admin/platform-orders?bmpa_error_keyword=' . urlencode('应付金额'));
|
||||
$res->assertOk();
|
||||
|
||||
$res->assertSee($hit->order_no);
|
||||
$res->assertDontSee('PO_BMPA_KW_MISS');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user