- 在多个控制器中更新权限检查逻辑,确保管理员能够更灵活地管理代理和玩家。 - 在 AdminPlayerStoreController 中引入对玩家创建能力的验证,确保只有具备相应权限的管理员能够创建玩家。 - 更新请求验证逻辑,新增 credit_limit、rebate_rate 和 extra_rebate_rate 字段,以支持更细粒度的玩家管理。 - 在 AgentNodeProfileController 中添加对父代理能力授予的验证,确保子代理的权限在父代理范围内。 - 引入 AgentProfileFieldRules 以简化代理资料更新请求的规则定义,提升代码复用性。
66 lines
2.3 KiB
PHP
66 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services\AgentSettlement;
|
|
|
|
use App\Support\PlayerFundingMode;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
/** 账期窗口内信用流水与占成流水笔数(关账前诊断)。 */
|
|
final class AgentSettlementPeriodPipelineService
|
|
{
|
|
/**
|
|
* @param Collection<int, object> $periods settlement_periods 行,须含 id、period_start、period_end、admin_site_id
|
|
* @return array<int, array{credit_ledger_count: int, share_ledger_count: int}>
|
|
*/
|
|
public function countsForPeriods(Collection $periods): array
|
|
{
|
|
if ($periods->isEmpty()) {
|
|
return [];
|
|
}
|
|
|
|
$siteIds = $periods->pluck('admin_site_id')->map(static fn ($id): int => (int) $id)->unique()->all();
|
|
$siteCodes = DB::table('admin_sites')
|
|
->whereIn('id', $siteIds)
|
|
->pluck('code', 'id');
|
|
|
|
$out = [];
|
|
foreach ($periods as $period) {
|
|
$periodId = (int) $period->id;
|
|
$siteCode = (string) ($siteCodes[(int) $period->admin_site_id] ?? '');
|
|
if ($siteCode === '') {
|
|
$out[$periodId] = ['credit_ledger_count' => 0, 'share_ledger_count' => 0];
|
|
|
|
continue;
|
|
}
|
|
|
|
$start = Carbon::parse($period->period_start)->startOfDay();
|
|
$end = Carbon::parse($period->period_end)->endOfDay();
|
|
|
|
$creditCount = (int) DB::table('credit_ledger as cl')
|
|
->join('players as p', function ($join): void {
|
|
$join->on('p.id', '=', 'cl.owner_id')
|
|
->where('cl.owner_type', '=', 'player');
|
|
})
|
|
->where('p.site_code', $siteCode)
|
|
->where('p.funding_mode', PlayerFundingMode::CREDIT)
|
|
->whereBetween('cl.created_at', [$start, $end])
|
|
->count();
|
|
|
|
$shareCount = (int) DB::table('share_ledger as sl')
|
|
->join('players as p', 'p.id', '=', 'sl.player_id')
|
|
->where('p.site_code', $siteCode)
|
|
->whereBetween('sl.settled_at', [$start, $end])
|
|
->count();
|
|
|
|
$out[$periodId] = [
|
|
'credit_ledger_count' => $creditCount,
|
|
'share_ledger_count' => $shareCount,
|
|
];
|
|
}
|
|
|
|
return $out;
|
|
}
|
|
}
|