feat: 增强代理和玩家管理功能

- 在多个控制器中更新权限检查逻辑,确保管理员能够更灵活地管理代理和玩家。
- 在 AdminPlayerStoreController 中引入对玩家创建能力的验证,确保只有具备相应权限的管理员能够创建玩家。
- 更新请求验证逻辑,新增 credit_limit、rebate_rate 和 extra_rebate_rate 字段,以支持更细粒度的玩家管理。
- 在 AgentNodeProfileController 中添加对父代理能力授予的验证,确保子代理的权限在父代理范围内。
- 引入 AgentProfileFieldRules 以简化代理资料更新请求的规则定义,提升代码复用性。
This commit is contained in:
2026-06-04 18:00:50 +08:00
parent 96545f87f6
commit a44679665d
183 changed files with 10054 additions and 857 deletions

View File

@@ -0,0 +1,72 @@
<?php
namespace App\Services\AgentSettlement;
use Illuminate\Support\Facades\DB;
/**
* 账期汇总尾差归平台§21.8)。
*/
final class PlatformRoundingAdjuster
{
/**
* @param array{players: array<int, array<string, mixed>>, agent_edges: array<string, int>, agent_subtrees: array<int, array<string, mixed>>} $aggregate
*/
public function apply(int $periodId, array $aggregate): int
{
$playerNet = 0;
foreach ($aggregate['players'] as $row) {
$playerNet += (int) $row['net_amount'];
}
$shareProfitTotal = 0;
foreach ($aggregate['agent_subtrees'] as $subtree) {
$shareProfitTotal += (int) ($subtree['share_profit'] ?? 0);
}
$shareProfitTotal += (int) ($aggregate['platform_share_profit'] ?? 0);
$diff = $playerNet - $shareProfitTotal;
if ($diff === 0) {
return 0;
}
$platformBill = DB::table('settlement_bills')
->where('settlement_period_id', $periodId)
->where('bill_type', 'agent')
->where('counterparty_type', 'platform')
->orderBy('id')
->first();
if ($platformBill === null) {
return 0;
}
$net = (int) $platformBill->net_amount + $diff;
DB::table('settlement_bills')->where('id', (int) $platformBill->id)->update([
'platform_rounding_adjustment' => $diff,
'net_amount' => $net,
'unpaid_amount' => abs($net),
'meta_json' => json_encode(array_merge(
$this->decodeMeta($platformBill->meta_json),
['platform_rounding_adjustment' => $diff],
)),
'updated_at' => now(),
]);
return $diff;
}
/**
* @return array<string, mixed>
*/
private function decodeMeta(mixed $raw): array
{
if ($raw === null || $raw === '') {
return [];
}
$decoded = is_string($raw) ? json_decode($raw, true) : $raw;
return is_array($decoded) ? $decoded : [];
}
}