Dashboard: bmpa processable count excludes refund trace and renewal missing subscription
This commit is contained in:
@@ -48,10 +48,31 @@ class DashboardController extends Controller
|
||||
->where('ends_at', '<', now()->addDays(7))
|
||||
->count(),
|
||||
'platform_orders' => PlatformOrder::count(),
|
||||
'platform_orders_unpaid_pending' => PlatformOrder::query()
|
||||
->where('payment_status', 'unpaid')
|
||||
->where('status', 'pending')
|
||||
->count(),
|
||||
// 可BMPA处理(尽量贴近后端治理安全阀):
|
||||
// - pending + unpaid
|
||||
// - 排除:存在退款轨迹(refund_total > 0)
|
||||
// - 排除:续费缺订阅(order_type=renewal 且 site_subscription_id 为空)
|
||||
'platform_orders_unpaid_pending' => (function () {
|
||||
$q = PlatformOrder::query()
|
||||
->where('payment_status', 'unpaid')
|
||||
->where('status', 'pending')
|
||||
->where(function ($b) {
|
||||
$b->where('order_type', '!=', 'renewal')
|
||||
->orWhereNotNull('site_subscription_id');
|
||||
});
|
||||
|
||||
$driver = $q->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)";
|
||||
$q->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)";
|
||||
$q->whereRaw("ROUND(($refundTotalExpr) * 100) <= 0");
|
||||
}
|
||||
|
||||
return $q->count();
|
||||
})(),
|
||||
'platform_orders_paid_pending' => PlatformOrder::query()
|
||||
->where('payment_status', 'paid')
|
||||
->where('status', 'pending')
|
||||
|
||||
Reference in New Issue
Block a user