Align dashboard BMPA quick link with bmpa_processable_only filter

This commit is contained in:
萝卜
2026-03-18 02:19:25 +08:00
parent 6e59ae3eb6
commit 3ff16b3d28
7 changed files with 50 additions and 14 deletions

View File

@@ -282,6 +282,12 @@ class PlatformOrderController extends Controller
// 创建时间范围(用于“趋势→集合”跳转与运营筛选)
'created_from' => trim((string) $request->query('created_from', '')),
'created_to' => trim((string) $request->query('created_to', '')),
// 真正可 BMPA 处理集合与仪表盘「可BMPA处理」口径对齐
// - pending + unpaid
// - 排除续费缺订阅order_type=renewal 且 site_subscription_id 为空)
// - 排除存在退款轨迹refund_total > 0
'bmpa_processable_only' => (string) $request->query('bmpa_processable_only', ''),
];
@@ -1342,6 +1348,12 @@ class PlatformOrderController extends Controller
// 创建时间范围(用于“趋势→集合”跳转与运营筛选)
'created_from' => trim((string) $request->query('created_from', '')),
'created_to' => trim((string) $request->query('created_to', '')),
// 真正可 BMPA 处理集合与仪表盘「可BMPA处理」口径对齐
// - pending + unpaid
// - 排除续费缺订阅order_type=renewal 且 site_subscription_id 为空)
// - 排除存在退款轨迹refund_total > 0
'bmpa_processable_only' => (string) $request->query('bmpa_processable_only', ''),
];
@@ -2605,6 +2617,28 @@ class PlatformOrderController extends Controller
} elseif ($to !== '') {
$builder->where('created_at', '<=', $to . ' 23:59:59');
}
})
->when(($filters['bmpa_processable_only'] ?? '') === '1', function (Builder $builder) {
// 真正可 BMPA 处理集合(与仪表盘统计口径对齐):
// - pending + unpaid
// - 排除续费缺订阅renewal 且 site_subscription_id 为空)
// - 排除存在退款轨迹refund_total > 0
$builder->where('status', 'pending')
->where('payment_status', 'unpaid')
->where(function (Builder $q) {
$q->where('order_type', '!=', 'renewal')
->orWhereNotNull('site_subscription_id');
});
$driver = $builder->getQuery()->getConnection()->getDriverName();
if ($driver === 'sqlite') {
$refundTotalExpr = "(CASE WHEN JSON_EXTRACT(meta, '$.refund_summary.total_amount') IS NOT NULL THEN CAST(JSON_EXTRACT(meta, '$.refund_summary.total_amount') AS REAL) ELSE (SELECT IFNULL(SUM(CAST(JSON_EXTRACT(value, '$.amount') AS REAL)), 0) FROM json_each(COALESCE(JSON_EXTRACT(meta, '$.refund_receipts'), '[]'))) END)";
$builder->whereRaw("ROUND(($refundTotalExpr) * 100) <= 0");
} else {
$refundTotalExpr = "(CASE WHEN JSON_EXTRACT(meta, '$.refund_summary.total_amount') IS NOT NULL THEN CAST(JSON_UNQUOTE(JSON_EXTRACT(meta, '$.refund_summary.total_amount')) AS DECIMAL(12,2)) ELSE (SELECT IFNULL(SUM(j.amount), 0) FROM JSON_TABLE(meta, '$.refund_receipts[*]' COLUMNS(amount DECIMAL(12,2) PATH '$.amount')) j) END)";
$builder->whereRaw("ROUND(($refundTotalExpr) * 100) <= 0");
}
});
}