feat(admin): platform orders add reconciliation delta card
This commit is contained in:
@@ -166,6 +166,28 @@ class PlatformOrderController extends Controller
|
|||||||
];
|
];
|
||||||
})->values()->all();
|
})->values()->all();
|
||||||
|
|
||||||
|
// 运营摘要中的 meta 汇总(refund/payment)需要遍历订单 meta。
|
||||||
|
// 为避免重复 get(),在当前筛选范围内一次性拉取所需字段。
|
||||||
|
$metaOrders = (clone $baseQuery)->get(['id', 'paid_amount', 'meta']);
|
||||||
|
$totalRefundedAmount = (float) $metaOrders->sum(function ($o) {
|
||||||
|
// 优先读 meta.refund_summary.total_amount,回退汇总 meta.refund_receipts[].amount
|
||||||
|
$total = (float) (data_get($o->meta, 'refund_summary.total_amount') ?? 0);
|
||||||
|
if ($total > 0) {
|
||||||
|
return $total;
|
||||||
|
}
|
||||||
|
|
||||||
|
$refunds = (array) (data_get($o->meta, 'refund_receipts', []) ?? []);
|
||||||
|
$sum = 0.0;
|
||||||
|
foreach ($refunds as $r) {
|
||||||
|
$sum += (float) (data_get($r, 'amount') ?? 0);
|
||||||
|
}
|
||||||
|
return $sum;
|
||||||
|
});
|
||||||
|
|
||||||
|
$totalReceiptAmount = (float) $this->sumReceiptAmount($metaOrders);
|
||||||
|
$totalPayableAmount = (float) ((clone $baseQuery)->sum('payable_amount') ?: 0);
|
||||||
|
$totalPaidAmount = (float) ((clone $baseQuery)->sum('paid_amount') ?: 0);
|
||||||
|
|
||||||
return view('admin.platform_orders.index', [
|
return view('admin.platform_orders.index', [
|
||||||
'orders' => $orders,
|
'orders' => $orders,
|
||||||
'filters' => $filters,
|
'filters' => $filters,
|
||||||
@@ -207,8 +229,8 @@ class PlatformOrderController extends Controller
|
|||||||
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation.subscription_id') IS NULL")
|
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation.subscription_id') IS NULL")
|
||||||
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NULL")
|
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NULL")
|
||||||
->count(),
|
->count(),
|
||||||
'total_payable_amount' => (float) ((clone $baseQuery)->sum('payable_amount') ?: 0),
|
'total_payable_amount' => $totalPayableAmount,
|
||||||
'total_paid_amount' => (float) ((clone $baseQuery)->sum('paid_amount') ?: 0),
|
'total_paid_amount' => $totalPaidAmount,
|
||||||
'syncable_orders' => (clone $baseQuery)
|
'syncable_orders' => (clone $baseQuery)
|
||||||
->where('payment_status', 'paid')
|
->where('payment_status', 'paid')
|
||||||
->where('status', 'activated')
|
->where('status', 'activated')
|
||||||
@@ -246,37 +268,11 @@ class PlatformOrderController extends Controller
|
|||||||
})(),
|
})(),
|
||||||
'partially_refunded_orders' => (clone $baseQuery)->where('payment_status', 'partially_refunded')->count(),
|
'partially_refunded_orders' => (clone $baseQuery)->where('payment_status', 'partially_refunded')->count(),
|
||||||
'refunded_orders' => (clone $baseQuery)->where('payment_status', 'refunded')->count(),
|
'refunded_orders' => (clone $baseQuery)->where('payment_status', 'refunded')->count(),
|
||||||
'total_refunded_amount' => (clone $baseQuery)->get()->sum(function ($o) {
|
'total_refunded_amount' => $totalRefundedAmount,
|
||||||
// 优先读 meta.refund_summary.total_amount,回退汇总 meta.refund_receipts[].amount
|
|
||||||
$total = (float) (data_get($o->meta, 'refund_summary.total_amount') ?? 0);
|
|
||||||
if ($total > 0) {
|
|
||||||
return $total;
|
|
||||||
}
|
|
||||||
|
|
||||||
$refunds = (array) (data_get($o->meta, 'refund_receipts', []) ?? []);
|
|
||||||
$sum = 0.0;
|
|
||||||
foreach ($refunds as $r) {
|
|
||||||
$sum += (float) (data_get($r, 'amount') ?? 0);
|
|
||||||
}
|
|
||||||
return $sum;
|
|
||||||
}),
|
|
||||||
'receipt_orders' => (clone $baseQuery)->whereRaw("JSON_EXTRACT(meta, '$.payment_receipts[0].amount') IS NOT NULL")->count(),
|
'receipt_orders' => (clone $baseQuery)->whereRaw("JSON_EXTRACT(meta, '$.payment_receipts[0].amount') IS NOT NULL")->count(),
|
||||||
'total_receipt_amount' => (clone $baseQuery)->get()->sum(function ($o) {
|
'total_receipt_amount' => $totalReceiptAmount,
|
||||||
// 优先读 meta.payment_summary.total_amount,回退汇总 meta.payment_receipts[].amount
|
|
||||||
$total = (float) (data_get($o->meta, 'payment_summary.total_amount') ?? 0);
|
|
||||||
if ($total > 0) {
|
|
||||||
return $total;
|
|
||||||
}
|
|
||||||
|
|
||||||
$receipts = (array) (data_get($o->meta, 'payment_receipts', []) ?? []);
|
|
||||||
$sum = 0.0;
|
|
||||||
foreach ($receipts as $r) {
|
|
||||||
$sum += (float) (data_get($r, 'amount') ?? 0);
|
|
||||||
}
|
|
||||||
return $sum;
|
|
||||||
}),
|
|
||||||
// 对账差额:回执总额 - 订单已付总额(当前筛选范围)
|
// 对账差额:回执总额 - 订单已付总额(当前筛选范围)
|
||||||
'reconciliation_delta' => (float) ($this->sumReceiptAmount((clone $baseQuery)->get()) - (float) ((clone $baseQuery)->sum('paid_amount') ?: 0)),
|
'reconciliation_delta' => (float) ($totalReceiptAmount - $totalPaidAmount),
|
||||||
'reconciliation_delta_note' => '回执总额 - 订单已付总额',
|
'reconciliation_delta_note' => '回执总额 - 订单已付总额',
|
||||||
],
|
],
|
||||||
'failedReasonStats' => $failedReasonStats,
|
'failedReasonStats' => $failedReasonStats,
|
||||||
|
|||||||
Reference in New Issue
Block a user