- 在多个控制器中更新权限检查逻辑,确保管理员能够更灵活地管理代理和玩家。 - 在 AdminPlayerStoreController 中引入对玩家创建能力的验证,确保只有具备相应权限的管理员能够创建玩家。 - 更新请求验证逻辑,新增 credit_limit、rebate_rate 和 extra_rebate_rate 字段,以支持更细粒度的玩家管理。 - 在 AgentNodeProfileController 中添加对父代理能力授予的验证,确保子代理的权限在父代理范围内。 - 引入 AgentProfileFieldRules 以简化代理资料更新请求的规则定义,提升代码复用性。
85 lines
3.2 KiB
PHP
85 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services\AgentSettlement;
|
|
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
/** 账期维度账单笔数与待办汇总(结算中心看板)。 */
|
|
final class AgentSettlementPeriodSummaryService
|
|
{
|
|
public function __construct(
|
|
private readonly AgentSettlementPeriodPipelineService $pipelineService,
|
|
) {}
|
|
/**
|
|
* @param list<int> $periodIds
|
|
* @return array<int, array<string, int>>
|
|
*/
|
|
public function summariesForPeriodIds(array $periodIds): array
|
|
{
|
|
if ($periodIds === []) {
|
|
return [];
|
|
}
|
|
|
|
$rows = DB::table('settlement_bills')
|
|
->whereIn('settlement_period_id', $periodIds)
|
|
->groupBy('settlement_period_id')
|
|
->selectRaw('settlement_period_id')
|
|
->selectRaw("SUM(CASE WHEN bill_type = 'player' THEN 1 ELSE 0 END) as player_bills")
|
|
->selectRaw("SUM(CASE WHEN bill_type = 'agent' THEN 1 ELSE 0 END) as agent_bills")
|
|
->selectRaw("SUM(CASE WHEN bill_type IN ('adjustment', 'reversal') THEN 1 ELSE 0 END) as adjustment_bills")
|
|
->selectRaw("SUM(CASE WHEN status = 'pending_confirm' THEN 1 ELSE 0 END) as pending_confirm")
|
|
->selectRaw("SUM(CASE WHEN status IN ('confirmed', 'partial_paid', 'overdue') AND unpaid_amount > 0 THEN 1 ELSE 0 END) as awaiting_payment")
|
|
->selectRaw("SUM(CASE WHEN status = 'settled' THEN 1 ELSE 0 END) as settled")
|
|
->selectRaw('COALESCE(SUM(unpaid_amount), 0) as total_unpaid')
|
|
->get();
|
|
|
|
$out = [];
|
|
foreach ($rows as $row) {
|
|
$periodId = (int) $row->settlement_period_id;
|
|
$out[$periodId] = [
|
|
'player_bills' => (int) $row->player_bills,
|
|
'agent_bills' => (int) $row->agent_bills,
|
|
'adjustment_bills' => (int) $row->adjustment_bills,
|
|
'pending_confirm' => (int) $row->pending_confirm,
|
|
'awaiting_payment' => (int) $row->awaiting_payment,
|
|
'settled' => (int) $row->settled,
|
|
'total_unpaid' => (int) $row->total_unpaid,
|
|
];
|
|
}
|
|
|
|
return $out;
|
|
}
|
|
|
|
/**
|
|
* @param Collection<int, object> $periods
|
|
* @return list<array<string, mixed>>
|
|
*/
|
|
public function attachToPeriodRows(Collection $periods): array
|
|
{
|
|
$ids = $periods->pluck('id')->map(static fn ($id): int => (int) $id)->all();
|
|
$summaries = $this->summariesForPeriodIds($ids);
|
|
$pipelines = $this->pipelineService->countsForPeriods($periods);
|
|
$empty = [
|
|
'player_bills' => 0,
|
|
'agent_bills' => 0,
|
|
'adjustment_bills' => 0,
|
|
'pending_confirm' => 0,
|
|
'awaiting_payment' => 0,
|
|
'settled' => 0,
|
|
'total_unpaid' => 0,
|
|
];
|
|
$emptyPipeline = ['credit_ledger_count' => 0, 'share_ledger_count' => 0];
|
|
|
|
$items = [];
|
|
foreach ($periods as $period) {
|
|
$row = (array) $period;
|
|
$row['summary'] = $summaries[(int) $period->id] ?? $empty;
|
|
$row['pipeline'] = $pipelines[(int) $period->id] ?? $emptyPipeline;
|
|
$items[] = $row;
|
|
}
|
|
|
|
return $items;
|
|
}
|
|
}
|