feat: 补充结算批次财务汇总并返回投注与利润数据
This commit is contained in:
30
app/Support/SettlementBatchFinancialSummary.php
Normal file
30
app/Support/SettlementBatchFinancialSummary.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Models\SettlementBatch;
|
||||
|
||||
final class SettlementBatchFinancialSummary
|
||||
{
|
||||
/**
|
||||
* @return array{total_bet_amount: int, total_actual_deduct: int, platform_profit: int}
|
||||
*/
|
||||
public static function forBatch(SettlementBatch $batch): array
|
||||
{
|
||||
$totals = $batch->details()
|
||||
->join('ticket_items', 'ticket_items.id', '=', 'ticket_settlement_details.ticket_item_id')
|
||||
->selectRaw('COALESCE(SUM(ticket_items.total_bet_amount), 0) as total_bet_amount')
|
||||
->selectRaw('COALESCE(SUM(ticket_items.actual_deduct_amount), 0) as total_actual_deduct')
|
||||
->first();
|
||||
|
||||
$totalBet = (int) ($totals?->total_bet_amount ?? 0);
|
||||
$totalActualDeduct = (int) ($totals?->total_actual_deduct ?? 0);
|
||||
$totalPayout = (int) $batch->total_payout_amount;
|
||||
|
||||
return [
|
||||
'total_bet_amount' => $totalBet,
|
||||
'total_actual_deduct' => $totalActualDeduct,
|
||||
'platform_profit' => $totalActualDeduct - $totalPayout,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user