- 在多个控制器中更新权限检查逻辑,确保管理员能够更灵活地管理代理和玩家。 - 在 AdminPlayerStoreController 中引入对玩家创建能力的验证,确保只有具备相应权限的管理员能够创建玩家。 - 更新请求验证逻辑,新增 credit_limit、rebate_rate 和 extra_rebate_rate 字段,以支持更细粒度的玩家管理。 - 在 AgentNodeProfileController 中添加对父代理能力授予的验证,确保子代理的权限在父代理范围内。 - 引入 AgentProfileFieldRules 以简化代理资料更新请求的规则定义,提升代码复用性。
160 lines
5.1 KiB
PHP
160 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Admin\AgentSettlement;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Support\AdminAgentSettlementScope;
|
|
use App\Support\ApiResponse;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
final class AgentSettlementBillIndexController extends Controller
|
|
{
|
|
public function __invoke(Request $request): JsonResponse
|
|
{
|
|
$admin = $request->lotteryAdmin();
|
|
abort_if($admin === null, 401);
|
|
|
|
$periodId = (int) $request->query('settlement_period_id', 0);
|
|
$adminSiteId = (int) $request->query('admin_site_id', 0);
|
|
|
|
$query = DB::table('settlement_bills as sb')
|
|
->leftJoin('settlement_periods as sp', 'sp.id', '=', 'sb.settlement_period_id')
|
|
->select([
|
|
'sb.*',
|
|
'sp.period_start',
|
|
'sp.period_end',
|
|
'sp.admin_site_id',
|
|
])
|
|
->orderByDesc('sb.id');
|
|
|
|
if ($periodId > 0) {
|
|
$query->where('sb.settlement_period_id', $periodId);
|
|
}
|
|
|
|
if ($adminSiteId > 0) {
|
|
$query->where('sp.admin_site_id', $adminSiteId);
|
|
}
|
|
|
|
$billType = (string) $request->query('bill_type', '');
|
|
if ($billType !== '') {
|
|
$query->where('sb.bill_type', $billType);
|
|
}
|
|
|
|
$scope = (string) $request->query('scope', '');
|
|
match ($scope) {
|
|
'pending_confirm' => $query->where('sb.status', 'pending_confirm'),
|
|
'awaiting_payment' => $query
|
|
->whereIn('sb.status', ['confirmed', 'partial_paid', 'overdue'])
|
|
->where('sb.unpaid_amount', '>', 0),
|
|
'settled' => $query->where('sb.status', 'settled'),
|
|
'adjustment' => $query->whereIn('sb.bill_type', ['adjustment', 'reversal']),
|
|
default => null,
|
|
};
|
|
|
|
AdminAgentSettlementScope::applyToBillsQuery($query, $admin, 'sb');
|
|
|
|
/** @var Collection<int, object> $items */
|
|
$items = $query->limit(200)->get();
|
|
|
|
return ApiResponse::success([
|
|
'items' => $this->enrichBillRows($items),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @param Collection<int, object> $items
|
|
* @return list<array<string, mixed>>
|
|
*/
|
|
private function enrichBillRows(Collection $items): array
|
|
{
|
|
if ($items->isEmpty()) {
|
|
return [];
|
|
}
|
|
|
|
$playerIds = [];
|
|
$agentIds = [];
|
|
foreach ($items as $row) {
|
|
if ((string) $row->owner_type === 'player') {
|
|
$playerIds[] = (int) $row->owner_id;
|
|
} elseif ((string) $row->owner_type === 'agent') {
|
|
$agentIds[] = (int) $row->owner_id;
|
|
}
|
|
if ((string) $row->counterparty_type === 'agent' && (int) $row->counterparty_id > 0) {
|
|
$agentIds[] = (int) $row->counterparty_id;
|
|
}
|
|
}
|
|
|
|
$players = $playerIds !== []
|
|
? DB::table('players')
|
|
->whereIn('id', array_unique($playerIds))
|
|
->select(['id', 'username', 'site_player_id', 'funding_mode', 'auth_source'])
|
|
->get()
|
|
->keyBy('id')
|
|
: collect();
|
|
$agents = $agentIds !== []
|
|
? DB::table('agent_nodes')->whereIn('id', array_unique($agentIds))->get()->keyBy('id')
|
|
: collect();
|
|
|
|
$out = [];
|
|
foreach ($items as $row) {
|
|
$item = (array) $row;
|
|
$item['owner_label'] = $this->resolvePartyLabel(
|
|
(string) $row->owner_type,
|
|
(int) $row->owner_id,
|
|
$players,
|
|
$agents,
|
|
);
|
|
$item['counterparty_label'] = $this->resolvePartyLabel(
|
|
(string) $row->counterparty_type,
|
|
(int) $row->counterparty_id,
|
|
$players,
|
|
$agents,
|
|
);
|
|
if ((string) $row->owner_type === 'player') {
|
|
$player = $players->get((int) $row->owner_id);
|
|
$item['owner_funding_mode'] = $player !== null ? (string) ($player->funding_mode ?? '') : null;
|
|
$item['owner_auth_source'] = $player !== null ? $player->auth_source : null;
|
|
}
|
|
$out[] = $item;
|
|
}
|
|
|
|
return $out;
|
|
}
|
|
|
|
/**
|
|
* @param Collection<int, object> $players
|
|
* @param Collection<int, object> $agents
|
|
*/
|
|
private function resolvePartyLabel(
|
|
string $type,
|
|
int $id,
|
|
Collection $players,
|
|
Collection $agents,
|
|
): string {
|
|
if ($type === 'platform' || $id <= 0) {
|
|
return 'platform';
|
|
}
|
|
|
|
if ($type === 'player') {
|
|
$player = $players->get($id);
|
|
|
|
return $player !== null
|
|
? (string) ($player->username ?: $player->site_player_id)
|
|
: "player#{$id}";
|
|
}
|
|
|
|
if ($type === 'agent') {
|
|
$agent = $agents->get($id);
|
|
|
|
return $agent !== null
|
|
? (string) ($agent->name ?: $agent->code)
|
|
: "agent#{$id}";
|
|
}
|
|
|
|
return "{$type}#{$id}";
|
|
}
|
|
}
|