feat: 增强管理员功能与数据处理
- 在多个控制器中引入 agent_node_id,以支持基于代理节点的权限和数据过滤。 - 更新 AdminRole 和 AdminUser 模型,新增角色范围和代理节点相关功能,提升角色管理的灵活性。 - 在请求验证中添加 agent_node_id 字段,确保 API 接口支持代理节点的相关操作。 - 优化 LotterySettings 服务,支持批量写入设置,提升配置管理的效率。 - 更新仪表板和报告服务,增强数据统计功能,确保管理员能够获取更全面的统计信息。
This commit is contained in:
@@ -3,12 +3,16 @@
|
||||
namespace App\Http\Controllers\Api\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Middleware\RecordAdminApiAudit;
|
||||
use App\Http\Requests\Admin\AdminSettingBatchUpdateRequest;
|
||||
use App\Http\Requests\Admin\AdminSettingIndexRequest;
|
||||
use App\Http\Requests\Admin\AdminSettingUpdateRequest;
|
||||
use App\Models\LotterySetting;
|
||||
use App\Services\AuditLogger;
|
||||
use App\Support\ApiResponse;
|
||||
use App\Services\LotterySettings;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* 后台:运营配置(KV 设置)读写。
|
||||
@@ -54,4 +58,47 @@ final class AdminSettingController extends Controller
|
||||
'description' => $fresh->description_zh,
|
||||
]);
|
||||
}
|
||||
|
||||
public function batchUpdate(AdminSettingBatchUpdateRequest $request): JsonResponse
|
||||
{
|
||||
/** @var list<array{key: string, value: mixed}> $items */
|
||||
$items = $request->validated('items');
|
||||
|
||||
DB::transaction(static function () use ($items): void {
|
||||
LotterySettings::putMany($items);
|
||||
});
|
||||
|
||||
$keys = array_map(static fn (array $item): string => (string) $item['key'], $items);
|
||||
$rows = LotterySetting::query()
|
||||
->whereIn('setting_key', $keys)
|
||||
->orderBy('setting_key')
|
||||
->get();
|
||||
|
||||
$admin = $request->lotteryAdmin();
|
||||
if ($admin !== null) {
|
||||
AuditLogger::recordForAdmin(
|
||||
$admin,
|
||||
$request,
|
||||
moduleCode: 'settings',
|
||||
actionCode: 'batch_update',
|
||||
targetType: 'lottery_settings',
|
||||
targetId: 'batch',
|
||||
beforeJson: null,
|
||||
afterJson: [
|
||||
'keys' => $keys,
|
||||
'count' => count($keys),
|
||||
],
|
||||
);
|
||||
$request->attributes->set(RecordAdminApiAudit::ATTRIBUTE_AUDIT_RECORDED, true);
|
||||
}
|
||||
|
||||
return ApiResponse::success([
|
||||
'items' => $rows->map(fn (LotterySetting $s): array => [
|
||||
'key' => $s->setting_key,
|
||||
'value' => $s->value_json,
|
||||
'group' => $s->group_name,
|
||||
'description' => $s->description_zh,
|
||||
])->values()->all(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Agent;
|
||||
|
||||
use App\Models\AdminUser;
|
||||
use App\Support\ApiResponse;
|
||||
use App\Services\AuditLogger;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Agent\AgentAdminUserService;
|
||||
use App\Support\AdminAgentNodeAccess;
|
||||
use App\Support\AdminUserApiPresenter;
|
||||
use App\Http\Requests\Admin\AgentAdminUserRoleSyncRequest;
|
||||
|
||||
final class AgentAdminUserRoleSyncController extends Controller
|
||||
{
|
||||
public function __invoke(
|
||||
AgentAdminUserRoleSyncRequest $request,
|
||||
AdminUser $admin_user,
|
||||
AgentAdminUserService $service,
|
||||
): JsonResponse {
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$agent = $admin_user->primaryAgentNode();
|
||||
if ($agent === null) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$denied = AdminAgentNodeAccess::denyUnlessNodeVisible($admin, $agent);
|
||||
if ($denied !== null) {
|
||||
return $denied;
|
||||
}
|
||||
|
||||
if (! $admin->isSuperAdmin() && ! $admin->hasAdminPermission('prd.agent.user.manage')) {
|
||||
return AdminAgentNodeAccess::denyUnlessCanManageParent($admin, $agent);
|
||||
}
|
||||
|
||||
$before = AdminUserApiPresenter::listItem($admin_user);
|
||||
$user = $service->syncRoles($agent, $admin_user, $request->validated('role_ids'));
|
||||
$after = AdminUserApiPresenter::listItem($user);
|
||||
|
||||
AuditLogger::recordForAdmin(
|
||||
$admin,
|
||||
$request,
|
||||
'agent',
|
||||
'agent_admin_user.sync_roles',
|
||||
'admin_user',
|
||||
(string) $user->id,
|
||||
$before,
|
||||
$after,
|
||||
);
|
||||
|
||||
return ApiResponse::success($after);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Agent;
|
||||
|
||||
use App\Models\AdminUser;
|
||||
use App\Models\AgentNode;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\AdminAgentNodeAccess;
|
||||
use App\Support\AdminUserApiPresenter;
|
||||
|
||||
final class AgentNodeAdminUserIndexController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request, AgentNode $agent_node): JsonResponse
|
||||
{
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$denied = AdminAgentNodeAccess::denyUnlessNodeVisible($admin, $agent_node);
|
||||
if ($denied !== null) {
|
||||
return $denied;
|
||||
}
|
||||
|
||||
$userIds = DB::table('admin_user_agents')
|
||||
->where('agent_node_id', $agent_node->id)
|
||||
->pluck('admin_user_id');
|
||||
|
||||
$users = AdminUser::query()
|
||||
->whereIn('id', $userIds)
|
||||
->orderBy('username')
|
||||
->get();
|
||||
|
||||
return ApiResponse::success([
|
||||
'agent_node_id' => (int) $agent_node->id,
|
||||
'items' => $users->map(static fn (AdminUser $user): array => AdminUserApiPresenter::listItem($user))->all(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Agent;
|
||||
|
||||
use App\Models\AgentNode;
|
||||
use App\Support\ApiResponse;
|
||||
use App\Services\AuditLogger;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Agent\AgentAdminUserService;
|
||||
use App\Support\AdminAgentNodeAccess;
|
||||
use App\Support\AdminUserApiPresenter;
|
||||
use App\Http\Requests\Admin\AgentAdminUserStoreRequest;
|
||||
|
||||
final class AgentNodeAdminUserStoreController extends Controller
|
||||
{
|
||||
public function __invoke(
|
||||
AgentAdminUserStoreRequest $request,
|
||||
AgentNode $agent_node,
|
||||
AgentAdminUserService $service,
|
||||
): JsonResponse {
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$denied = AdminAgentNodeAccess::denyUnlessNodeVisible($admin, $agent_node);
|
||||
if ($denied !== null) {
|
||||
return $denied;
|
||||
}
|
||||
|
||||
if (! $admin->isSuperAdmin() && ! $admin->hasAdminPermission('prd.agent.user.manage')) {
|
||||
return AdminAgentNodeAccess::denyUnlessCanManageParent($admin, $agent_node);
|
||||
}
|
||||
|
||||
$user = $service->createUnderAgent($agent_node, $request->validated());
|
||||
|
||||
AuditLogger::recordForAdmin(
|
||||
$admin,
|
||||
$request,
|
||||
'agent',
|
||||
'agent_admin_user.create',
|
||||
'admin_user',
|
||||
(string) $user->id,
|
||||
null,
|
||||
AdminUserApiPresenter::listItem($user),
|
||||
);
|
||||
|
||||
return ApiResponse::success(AdminUserApiPresenter::listItem($user))->setStatusCode(201);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Agent;
|
||||
|
||||
use App\Models\AgentNode;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\AdminAgentNodeAccess;
|
||||
use App\Support\AgentNodePresenter;
|
||||
|
||||
final class AgentNodeChildrenController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request, AgentNode $agent_node): JsonResponse
|
||||
{
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$denied = AdminAgentNodeAccess::denyUnlessNodeVisible($admin, $agent_node);
|
||||
if ($denied !== null) {
|
||||
return $denied;
|
||||
}
|
||||
|
||||
$items = $agent_node->children()
|
||||
->orderBy('code')
|
||||
->get()
|
||||
->map(static fn (AgentNode $child): array => AgentNodePresenter::item($child))
|
||||
->all();
|
||||
|
||||
return ApiResponse::success(['items' => $items]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Agent;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AgentNode;
|
||||
use App\Services\Agent\AgentDelegationService;
|
||||
use App\Support\AdminAgentNodeAccess;
|
||||
use App\Support\AgentDelegationAuthorization;
|
||||
use App\Support\ApiMessage;
|
||||
use App\Support\ApiResponse;
|
||||
use App\Lottery\ErrorCode;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
final class AgentNodeDelegationGrantIndexController extends Controller
|
||||
{
|
||||
public function __invoke(
|
||||
Request $request,
|
||||
AgentNode $agent_node,
|
||||
AgentDelegationService $service,
|
||||
): JsonResponse {
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$denied = AdminAgentNodeAccess::denyUnlessNodeVisible($admin, $agent_node);
|
||||
if ($denied !== null) {
|
||||
return $denied;
|
||||
}
|
||||
|
||||
if ($agent_node->isRoot()) {
|
||||
return ApiMessage::errorResponse(
|
||||
$request,
|
||||
'admin.agent_delegation_root_denied',
|
||||
ErrorCode::ValidationFailed->value,
|
||||
null,
|
||||
422,
|
||||
);
|
||||
}
|
||||
|
||||
if (! AgentDelegationAuthorization::childIsManageableBy($admin, $agent_node)) {
|
||||
return ApiMessage::errorResponse(
|
||||
$request,
|
||||
'admin.agent_delegation_manage_denied',
|
||||
ErrorCode::AdminForbidden->value,
|
||||
null,
|
||||
403,
|
||||
);
|
||||
}
|
||||
|
||||
return ApiResponse::success([
|
||||
'child_agent_id' => (int) $agent_node->id,
|
||||
'grants' => $service->listForChild($agent_node, $admin),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Agent;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\AgentDelegationGrantSyncRequest;
|
||||
use App\Models\AgentNode;
|
||||
use App\Services\Agent\AgentDelegationService;
|
||||
use App\Services\AuditLogger;
|
||||
use App\Support\AdminAgentNodeAccess;
|
||||
use App\Support\AgentDelegationAuthorization;
|
||||
use App\Support\ApiMessage;
|
||||
use App\Support\ApiResponse;
|
||||
use App\Lottery\ErrorCode;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
final class AgentNodeDelegationGrantSyncController extends Controller
|
||||
{
|
||||
public function __invoke(
|
||||
AgentDelegationGrantSyncRequest $request,
|
||||
AgentNode $agent_node,
|
||||
AgentDelegationService $service,
|
||||
): JsonResponse {
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$denied = AdminAgentNodeAccess::denyUnlessNodeVisible($admin, $agent_node);
|
||||
if ($denied !== null) {
|
||||
return $denied;
|
||||
}
|
||||
|
||||
if ($agent_node->isRoot()) {
|
||||
return ApiMessage::errorResponse(
|
||||
$request,
|
||||
'admin.agent_delegation_root_denied',
|
||||
ErrorCode::ValidationFailed->value,
|
||||
null,
|
||||
422,
|
||||
);
|
||||
}
|
||||
|
||||
if (! AgentDelegationAuthorization::childIsManageableBy($admin, $agent_node)) {
|
||||
return ApiMessage::errorResponse(
|
||||
$request,
|
||||
'admin.agent_delegation_manage_denied',
|
||||
ErrorCode::AdminForbidden->value,
|
||||
null,
|
||||
403,
|
||||
);
|
||||
}
|
||||
|
||||
$before = $service->listForChild($agent_node);
|
||||
$grants = $request->validated('grants');
|
||||
$after = $service->syncGrants($admin, $agent_node, $grants);
|
||||
|
||||
AuditLogger::recordForAdmin(
|
||||
$admin,
|
||||
$request,
|
||||
'agent',
|
||||
'agent.delegation.sync',
|
||||
'agent_node',
|
||||
(string) $agent_node->id,
|
||||
['grants' => $before],
|
||||
['grants' => $after],
|
||||
);
|
||||
|
||||
return ApiResponse::success([
|
||||
'child_agent_id' => (int) $agent_node->id,
|
||||
'grants' => $after,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Agent;
|
||||
|
||||
use App\Lottery\ErrorCode;
|
||||
use App\Models\AgentNode;
|
||||
use App\Support\ApiMessage;
|
||||
use App\Support\ApiResponse;
|
||||
use App\Services\AuditLogger;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Agent\AgentNodeService;
|
||||
use App\Support\AdminAgentNodeAccess;
|
||||
use App\Support\AdminAgentScope;
|
||||
use App\Support\AgentNodePresenter;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
final class AgentNodeDestroyController extends Controller
|
||||
{
|
||||
public function __invoke(
|
||||
\Illuminate\Http\Request $request,
|
||||
AgentNode $agent_node,
|
||||
AgentNodeService $service,
|
||||
): JsonResponse {
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$denied = AdminAgentNodeAccess::denyUnlessNodeVisible($admin, $agent_node);
|
||||
if ($denied !== null) {
|
||||
return $denied;
|
||||
}
|
||||
|
||||
if (! AdminAgentScope::nodeManageableBy($admin, $agent_node)) {
|
||||
return AdminAgentNodeAccess::denyUnlessNodeVisible($admin, $agent_node)
|
||||
?? AdminAgentNodeAccess::denyUnlessCanManageParent($admin, $agent_node);
|
||||
}
|
||||
|
||||
if ($agent_node->isRoot()) {
|
||||
return ApiMessage::errorResponse($request, 'admin.agent_root_delete_denied', ErrorCode::ValidationFailed->value, null, 422);
|
||||
}
|
||||
|
||||
if ($agent_node->children()->exists()) {
|
||||
return ApiMessage::errorResponse($request, 'admin.agent_node_has_children_cannot_delete', ErrorCode::ValidationFailed->value, null, 422);
|
||||
}
|
||||
|
||||
if (DB::table('admin_user_agents')->where('agent_node_id', (int) $agent_node->id)->exists()) {
|
||||
return ApiMessage::errorResponse($request, 'admin.agent_node_has_users_cannot_delete', ErrorCode::ValidationFailed->value, null, 422);
|
||||
}
|
||||
|
||||
if (DB::table('admin_roles')->where('owner_agent_id', (int) $agent_node->id)->exists()) {
|
||||
return ApiMessage::errorResponse($request, 'admin.agent_node_has_roles_cannot_delete', ErrorCode::ValidationFailed->value, null, 422);
|
||||
}
|
||||
|
||||
$before = AgentNodePresenter::item($agent_node);
|
||||
$service->destroy($agent_node);
|
||||
|
||||
AuditLogger::recordForAdmin(
|
||||
$admin,
|
||||
$request,
|
||||
'system',
|
||||
'agent_node.destroy',
|
||||
'agent_node',
|
||||
(string) $agent_node->id,
|
||||
$before,
|
||||
null,
|
||||
);
|
||||
|
||||
return ApiResponse::success(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Agent;
|
||||
|
||||
use App\Models\AdminRole;
|
||||
use App\Models\AgentNode;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\AdminAgentNodeAccess;
|
||||
use App\Support\AdminRoleApiPresenter;
|
||||
|
||||
final class AgentNodeRoleIndexController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request, AgentNode $agent_node): JsonResponse
|
||||
{
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$denied = AdminAgentNodeAccess::denyUnlessNodeVisible($admin, $agent_node);
|
||||
if ($denied !== null) {
|
||||
return $denied;
|
||||
}
|
||||
|
||||
$roles = AdminRole::query()
|
||||
->where('scope_type', AdminRole::SCOPE_AGENT)
|
||||
->where('owner_agent_id', $agent_node->id)
|
||||
->orderBy('sort_order')
|
||||
->orderBy('id')
|
||||
->get();
|
||||
|
||||
return ApiResponse::success([
|
||||
'agent_node_id' => (int) $agent_node->id,
|
||||
'items' => $roles->map(static fn (AdminRole $role): array => AdminRoleApiPresenter::item($role))->all(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Agent;
|
||||
|
||||
use App\Models\AgentNode;
|
||||
use App\Support\ApiResponse;
|
||||
use App\Services\AuditLogger;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Agent\AgentRoleService;
|
||||
use App\Support\AdminAgentNodeAccess;
|
||||
use App\Support\AdminRoleApiPresenter;
|
||||
use App\Http\Requests\Admin\AgentRoleStoreRequest;
|
||||
|
||||
final class AgentNodeRoleStoreController extends Controller
|
||||
{
|
||||
public function __invoke(
|
||||
AgentRoleStoreRequest $request,
|
||||
AgentNode $agent_node,
|
||||
AgentRoleService $service,
|
||||
): JsonResponse {
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$denied = AdminAgentNodeAccess::denyUnlessNodeVisible($admin, $agent_node);
|
||||
if ($denied !== null) {
|
||||
return $denied;
|
||||
}
|
||||
|
||||
if (! $admin->isSuperAdmin() && ! $admin->hasAdminPermission('prd.agent.role.manage')) {
|
||||
return AdminAgentNodeAccess::denyUnlessCanManageParent($admin, $agent_node);
|
||||
}
|
||||
|
||||
$role = $service->createForAgent($admin, $agent_node, $request->validated());
|
||||
|
||||
AuditLogger::recordForAdmin(
|
||||
$admin,
|
||||
$request,
|
||||
'agent',
|
||||
'agent_role.create',
|
||||
'admin_role',
|
||||
(string) $role->id,
|
||||
null,
|
||||
AdminRoleApiPresenter::item($role),
|
||||
);
|
||||
|
||||
return ApiResponse::success(AdminRoleApiPresenter::item($role));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Agent;
|
||||
|
||||
use App\Models\AgentNode;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\AdminAgentNodeAccess;
|
||||
use App\Support\AgentNodePresenter;
|
||||
|
||||
final class AgentNodeShowController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request, AgentNode $agent_node): JsonResponse
|
||||
{
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$denied = AdminAgentNodeAccess::denyUnlessNodeVisible($admin, $agent_node);
|
||||
if ($denied !== null) {
|
||||
return $denied;
|
||||
}
|
||||
|
||||
return ApiResponse::success(AgentNodePresenter::item($agent_node));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Agent;
|
||||
|
||||
use App\Models\AgentNode;
|
||||
use App\Support\ApiResponse;
|
||||
use App\Services\AuditLogger;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Agent\AgentNodeService;
|
||||
use App\Support\AdminAgentNodeAccess;
|
||||
use App\Support\AgentNodePresenter;
|
||||
use App\Http\Requests\Admin\AgentNodeStoreRequest;
|
||||
|
||||
final class AgentNodeStoreController extends Controller
|
||||
{
|
||||
public function __invoke(AgentNodeStoreRequest $request, AgentNodeService $service): JsonResponse
|
||||
{
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$parent = AgentNode::query()->findOrFail((int) $request->validated('parent_id'));
|
||||
$denied = AdminAgentNodeAccess::denyUnlessCanManageParent($admin, $parent);
|
||||
if ($denied !== null) {
|
||||
return $denied;
|
||||
}
|
||||
|
||||
$node = $service->createChild($admin, $request->validated());
|
||||
|
||||
AuditLogger::recordForAdmin(
|
||||
$admin,
|
||||
$request,
|
||||
'system',
|
||||
'agent_node.create',
|
||||
'agent_node',
|
||||
(string) $node->id,
|
||||
null,
|
||||
AgentNodePresenter::item($node),
|
||||
);
|
||||
|
||||
return ApiResponse::success(AgentNodePresenter::item($node));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Agent;
|
||||
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\AdminAgentNodeAccess;
|
||||
use App\Support\AdminAgentScope;
|
||||
use App\Support\AgentNodePresenter;
|
||||
|
||||
final class AgentNodeTreeController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request): JsonResponse
|
||||
{
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$siteId = AdminAgentNodeAccess::resolveAdminSiteId(
|
||||
$admin,
|
||||
$request->integer('admin_site_id') ?: null,
|
||||
);
|
||||
|
||||
$denied = AdminAgentNodeAccess::denyUnlessSiteResolved($admin, $siteId);
|
||||
if ($denied !== null) {
|
||||
return $denied;
|
||||
}
|
||||
|
||||
$nodes = AdminAgentScope::visibleNodesQuery($admin, (int) $siteId)->get();
|
||||
|
||||
return ApiResponse::success([
|
||||
'admin_site_id' => (int) $siteId,
|
||||
'tree' => AgentNodePresenter::tree($nodes),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Agent;
|
||||
|
||||
use App\Models\AgentNode;
|
||||
use App\Support\ApiResponse;
|
||||
use App\Services\AuditLogger;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Agent\AgentNodeService;
|
||||
use App\Support\AdminAgentNodeAccess;
|
||||
use App\Support\AdminAgentScope;
|
||||
use App\Support\AgentNodePresenter;
|
||||
use App\Http\Requests\Admin\AgentNodeUpdateRequest;
|
||||
|
||||
final class AgentNodeUpdateController extends Controller
|
||||
{
|
||||
public function __invoke(
|
||||
AgentNodeUpdateRequest $request,
|
||||
AgentNode $agent_node,
|
||||
AgentNodeService $service,
|
||||
): JsonResponse {
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$denied = AdminAgentNodeAccess::denyUnlessNodeVisible($admin, $agent_node);
|
||||
if ($denied !== null) {
|
||||
return $denied;
|
||||
}
|
||||
|
||||
if (! AdminAgentScope::nodeManageableBy($admin, $agent_node)) {
|
||||
return AdminAgentNodeAccess::denyUnlessNodeVisible($admin, $agent_node)
|
||||
?? AdminAgentNodeAccess::denyUnlessCanManageParent($admin, $agent_node);
|
||||
}
|
||||
|
||||
if ($agent_node->isRoot() && ! $admin->isSuperAdmin()) {
|
||||
return AdminAgentNodeAccess::denyUnlessCanManageParent($admin, $agent_node);
|
||||
}
|
||||
|
||||
$before = AgentNodePresenter::item($agent_node);
|
||||
$node = $service->update($agent_node, $request->validated());
|
||||
$after = AgentNodePresenter::item($node);
|
||||
|
||||
AuditLogger::recordForAdmin(
|
||||
$admin,
|
||||
$request,
|
||||
'system',
|
||||
'agent_node.update',
|
||||
'agent_node',
|
||||
(string) $node->id,
|
||||
$before,
|
||||
$after,
|
||||
);
|
||||
|
||||
return ApiResponse::success($after);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Agent;
|
||||
|
||||
use App\Models\AdminRole;
|
||||
use App\Support\ApiResponse;
|
||||
use App\Services\AuditLogger;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Agent\AgentRoleService;
|
||||
use App\Support\AgentRoleAuthorization;
|
||||
use App\Support\AdminRoleApiPresenter;
|
||||
|
||||
final class AgentRoleDestroyController extends Controller
|
||||
{
|
||||
public function __invoke(
|
||||
\Illuminate\Http\Request $request,
|
||||
AdminRole $admin_role,
|
||||
AgentRoleService $service,
|
||||
): JsonResponse {
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
if (! $admin_role->isAgentScoped()) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$denied = AgentRoleAuthorization::denyUnlessRoleManageable($admin, $admin_role);
|
||||
if ($denied !== null) {
|
||||
return $denied;
|
||||
}
|
||||
|
||||
$before = AdminRoleApiPresenter::item($admin_role);
|
||||
$service->destroy($admin_role);
|
||||
|
||||
AuditLogger::recordForAdmin(
|
||||
$admin,
|
||||
$request,
|
||||
'agent',
|
||||
'agent_role.destroy',
|
||||
'admin_role',
|
||||
(string) $admin_role->id,
|
||||
$before,
|
||||
null,
|
||||
);
|
||||
|
||||
return ApiResponse::success(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Agent;
|
||||
|
||||
use App\Models\AdminRole;
|
||||
use App\Support\ApiResponse;
|
||||
use App\Services\AuditLogger;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Agent\AgentRoleService;
|
||||
use App\Support\AgentRoleAuthorization;
|
||||
use App\Support\AdminRoleApiPresenter;
|
||||
use App\Http\Requests\Admin\AgentRolePermissionSyncRequest;
|
||||
|
||||
final class AgentRolePermissionSyncController extends Controller
|
||||
{
|
||||
public function __invoke(
|
||||
AgentRolePermissionSyncRequest $request,
|
||||
AdminRole $admin_role,
|
||||
AgentRoleService $service,
|
||||
): JsonResponse {
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
if (! $admin_role->isAgentScoped()) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$denied = AgentRoleAuthorization::denyUnlessRoleManageable($admin, $admin_role);
|
||||
if ($denied !== null) {
|
||||
return $denied;
|
||||
}
|
||||
|
||||
if ($admin_role->isReadOnlyTemplate()) {
|
||||
return AgentRoleAuthorization::denyUnlessRoleManageable($admin, $admin_role);
|
||||
}
|
||||
|
||||
$slugs = array_values(array_unique($request->validated('permission_slugs')));
|
||||
$before = AdminRoleApiPresenter::item($admin_role);
|
||||
$role = $service->syncPermissions($admin, $admin_role, $slugs);
|
||||
|
||||
AuditLogger::recordForAdmin(
|
||||
$admin,
|
||||
$request,
|
||||
'agent',
|
||||
'agent_role.sync_permissions',
|
||||
'admin_role',
|
||||
(string) $role->id,
|
||||
$before,
|
||||
AdminRoleApiPresenter::item($role),
|
||||
);
|
||||
|
||||
return ApiResponse::success(AdminRoleApiPresenter::item($role));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Agent;
|
||||
|
||||
use App\Models\AdminRole;
|
||||
use App\Support\ApiResponse;
|
||||
use App\Services\AuditLogger;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Agent\AgentRoleService;
|
||||
use App\Support\AgentRoleAuthorization;
|
||||
use App\Support\AdminRoleApiPresenter;
|
||||
use App\Http\Requests\Admin\AgentRoleUpdateRequest;
|
||||
|
||||
final class AgentRoleUpdateController extends Controller
|
||||
{
|
||||
public function __invoke(
|
||||
AgentRoleUpdateRequest $request,
|
||||
AdminRole $admin_role,
|
||||
AgentRoleService $service,
|
||||
): JsonResponse {
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
if (! $admin_role->isAgentScoped()) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$denied = AgentRoleAuthorization::denyUnlessRoleManageable($admin, $admin_role);
|
||||
if ($denied !== null) {
|
||||
return $denied;
|
||||
}
|
||||
|
||||
if ($admin_role->isReadOnlyTemplate()) {
|
||||
return AgentRoleAuthorization::denyUnlessRoleManageable($admin, $admin_role);
|
||||
}
|
||||
|
||||
$before = AdminRoleApiPresenter::item($admin_role);
|
||||
$role = $service->update($admin_role, $request->validated());
|
||||
|
||||
AuditLogger::recordForAdmin(
|
||||
$admin,
|
||||
$request,
|
||||
'agent',
|
||||
'agent_role.update',
|
||||
'admin_role',
|
||||
(string) $role->id,
|
||||
$before,
|
||||
AdminRoleApiPresenter::item($role),
|
||||
);
|
||||
|
||||
return ApiResponse::success(AdminRoleApiPresenter::item($role));
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,12 @@
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Draw;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\AdminUser;
|
||||
use App\Models\Draw;
|
||||
use App\Models\TicketItem;
|
||||
use App\Models\TicketOrder;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Support\AdminSiteScope;
|
||||
use App\Support\AdminApiList;
|
||||
use App\Services\LotterySettings;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -20,9 +22,13 @@ final class AdminDrawIndexController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request): JsonResponse
|
||||
{
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$p = AdminApiList::readPaging($request);
|
||||
$drawNo = trim((string) $request->query('draw_no', ''));
|
||||
$status = trim((string) $request->query('status', ''));
|
||||
$agentNodeId = $request->integer('agent_node_id') ?: null;
|
||||
|
||||
$q = Draw::query()->orderByDesc('draw_time')->orderByDesc('id');
|
||||
|
||||
@@ -39,6 +45,8 @@ final class AdminDrawIndexController extends Controller
|
||||
|
||||
$statsByDrawId = $this->aggregateListStats(
|
||||
$paginator->getCollection()->pluck('id')->map(fn ($id) => (int) $id)->all(),
|
||||
$admin,
|
||||
$agentNodeId,
|
||||
);
|
||||
|
||||
return AdminApiList::jsonWith($paginator, fn (Draw $row) => $this->row($row, $statsByDrawId), [
|
||||
@@ -55,20 +63,22 @@ final class AdminDrawIndexController extends Controller
|
||||
* @param list<int> $drawIds
|
||||
* @return array<int, array{total_bet_minor: int, total_payout_minor: int, profit_loss_minor: int}>
|
||||
*/
|
||||
private function aggregateListStats(array $drawIds): array
|
||||
private function aggregateListStats(array $drawIds, AdminUser $admin, ?int $agentNodeId): array
|
||||
{
|
||||
if ($drawIds === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$betByDraw = TicketOrder::query()
|
||||
->whereIn('draw_id', $drawIds)
|
||||
$betQuery = TicketOrder::query()->whereIn('draw_id', $drawIds);
|
||||
$this->scopeOrdersToVisiblePlayers($betQuery, $admin, $agentNodeId);
|
||||
$betByDraw = $betQuery
|
||||
->groupBy('draw_id')
|
||||
->selectRaw('draw_id, COALESCE(SUM(total_actual_deduct), 0) AS total_bet')
|
||||
->pluck('total_bet', 'draw_id');
|
||||
|
||||
$payoutRows = TicketItem::query()
|
||||
->whereIn('draw_id', $drawIds)
|
||||
$payoutQuery = TicketItem::query()->whereIn('draw_id', $drawIds);
|
||||
$this->scopeTicketItemsToVisiblePlayers($payoutQuery, $admin, $agentNodeId);
|
||||
$payoutRows = $payoutQuery
|
||||
->groupBy('draw_id')
|
||||
->selectRaw(
|
||||
'draw_id, COALESCE(SUM(win_amount), 0) AS win, COALESCE(SUM(jackpot_win_amount), 0) AS jackpot',
|
||||
@@ -91,6 +101,44 @@ final class AdminDrawIndexController extends Controller
|
||||
return $stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder<TicketOrder> $query
|
||||
*/
|
||||
private function scopeOrdersToVisiblePlayers($query, AdminUser $admin, ?int $agentNodeId): void
|
||||
{
|
||||
if ($admin->isSuperAdmin() && ($agentNodeId === null || $agentNodeId <= 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query->whereHas('player', static function ($playerQuery) use ($admin, $agentNodeId): void {
|
||||
AdminSiteScope::applyPlayerFilters(
|
||||
$playerQuery,
|
||||
$admin,
|
||||
null,
|
||||
$agentNodeId !== null && $agentNodeId > 0 ? $agentNodeId : null,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder<TicketItem> $query
|
||||
*/
|
||||
private function scopeTicketItemsToVisiblePlayers($query, AdminUser $admin, ?int $agentNodeId): void
|
||||
{
|
||||
if ($admin->isSuperAdmin() && ($agentNodeId === null || $agentNodeId <= 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query->whereHas('player', static function ($playerQuery) use ($admin, $agentNodeId): void {
|
||||
AdminSiteScope::applyPlayerFilters(
|
||||
$playerQuery,
|
||||
$admin,
|
||||
null,
|
||||
$agentNodeId !== null && $agentNodeId > 0 ? $agentNodeId : null,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, array{total_bet_minor: int, total_payout_minor: int, profit_loss_minor: int}> $statsByDrawId
|
||||
* @return array<string, mixed>
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Support\AdminApiList;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Models\JackpotContribution;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\AdminDataScope;
|
||||
|
||||
/**
|
||||
* GET /api/v1/admin/jackpot/contributions — Jackpot 蓄水流水。
|
||||
@@ -15,6 +16,9 @@ final class AdminJackpotContributionIndexController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request): JsonResponse
|
||||
{
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$p = AdminApiList::readPaging($request);
|
||||
$drawNo = trim((string) $request->query('draw_no', ''));
|
||||
|
||||
@@ -26,6 +30,8 @@ final class AdminJackpotContributionIndexController extends Controller
|
||||
$q->whereHas('draw', fn ($d) => $d->where('draw_no', 'like', '%'.$drawNo.'%'));
|
||||
}
|
||||
|
||||
AdminDataScope::applyEloquentViaPlayer($q, $admin);
|
||||
|
||||
$paginator = $q->paginate($p['perPage'], ['*'], 'page', $p['page']);
|
||||
|
||||
return AdminApiList::json($paginator, fn (JackpotContribution $r) => [
|
||||
|
||||
@@ -23,15 +23,20 @@ final class AdminPlayerIndexController extends Controller
|
||||
$keyword = trim((string) $request->query('keyword', ''));
|
||||
$status = $request->query('status');
|
||||
$siteCode = $request->query('site_code');
|
||||
$agentNodeId = $request->integer('agent_node_id') ?: null;
|
||||
|
||||
$q = Player::query()
|
||||
->with(['wallets' => static fn ($wq) => $wq->orderBy('wallet_type')->orderBy('currency_code')])
|
||||
->with([
|
||||
'wallets' => static fn ($wq) => $wq->orderBy('wallet_type')->orderBy('currency_code'),
|
||||
'agentNode:id,code,name',
|
||||
])
|
||||
->orderByDesc('id');
|
||||
|
||||
AdminSiteScope::applyPlayerFilters(
|
||||
$q,
|
||||
$admin,
|
||||
is_string($siteCode) ? $siteCode : null,
|
||||
$agentNodeId,
|
||||
);
|
||||
|
||||
if ($keyword !== '') {
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Lottery\ErrorCode;
|
||||
use App\Support\ApiMessage;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Support\AdminAgentScope;
|
||||
use App\Support\AdminSiteScope;
|
||||
use App\Support\PlayerApiPresenter;
|
||||
use App\Http\Controllers\Controller;
|
||||
@@ -34,8 +35,30 @@ final class AdminPlayerStoreController extends Controller
|
||||
return ApiMessage::errorResponse($request, 'admin.player_already_registered', ErrorCode::ValidationFailed->value, null, 422);
|
||||
}
|
||||
|
||||
$agentNodeId = $admin->isSuperAdmin()
|
||||
? $this->resolveAgentNodeIdForSuperAdmin($request->validated('agent_node_id'), $siteCode)
|
||||
: $admin->primaryAgentNodeId();
|
||||
|
||||
if ($agentNodeId === null) {
|
||||
return ApiMessage::errorResponse(
|
||||
$request,
|
||||
'admin.player_create_agent_required',
|
||||
ErrorCode::ValidationFailed->value,
|
||||
null,
|
||||
422,
|
||||
);
|
||||
}
|
||||
|
||||
if (! $admin->isSuperAdmin()) {
|
||||
$agent = AdminAgentScope::primaryAgentNode($admin);
|
||||
if ($agent === null || (int) $agentNodeId !== (int) $agent->id) {
|
||||
return ApiMessage::errorResponse($request, 'admin.player_create_agent_forbidden', ErrorCode::AdminForbidden->value, null, 403);
|
||||
}
|
||||
}
|
||||
|
||||
$player = Player::query()->create([
|
||||
'site_code' => $request->validated('site_code'),
|
||||
'agent_node_id' => $agentNodeId,
|
||||
'site_player_id' => $request->validated('site_player_id'),
|
||||
'username' => $request->validated('username'),
|
||||
'nickname' => $request->validated('nickname'),
|
||||
@@ -45,4 +68,23 @@ final class AdminPlayerStoreController extends Controller
|
||||
|
||||
return ApiResponse::success(PlayerApiPresenter::listItem($player))->setStatusCode(201);
|
||||
}
|
||||
|
||||
private function resolveAgentNodeIdForSuperAdmin(mixed $requested, string $siteCode): ?int
|
||||
{
|
||||
if ($requested !== null && (int) $requested > 0) {
|
||||
return (int) $requested;
|
||||
}
|
||||
|
||||
$siteId = \App\Models\AdminSite::query()->where('code', $siteCode)->value('id');
|
||||
if ($siteId === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$rootId = \App\Models\AgentNode::query()
|
||||
->where('admin_site_id', (int) $siteId)
|
||||
->where('depth', 0)
|
||||
->value('id');
|
||||
|
||||
return $rootId !== null ? (int) $rootId : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ final class AdminReportDailyProfitController extends Controller
|
||||
{
|
||||
public function __invoke(AdminReportQueryRequest $request, AdminReportQueryService $service): JsonResponse
|
||||
{
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$validated = $request->validated();
|
||||
$p = AdminApiList::readPaging($request);
|
||||
$range = $service->resolveDateRange($validated);
|
||||
@@ -22,6 +25,7 @@ final class AdminReportDailyProfitController extends Controller
|
||||
$range['date_to'],
|
||||
$p['page'],
|
||||
$p['perPage'],
|
||||
$admin,
|
||||
);
|
||||
|
||||
return AdminApiList::json($paginator, static fn (array $row): array => $row);
|
||||
|
||||
@@ -13,6 +13,9 @@ final class AdminReportPlayDimensionController extends Controller
|
||||
{
|
||||
public function __invoke(AdminReportQueryRequest $request, AdminReportQueryService $service): JsonResponse
|
||||
{
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$validated = $request->validated();
|
||||
$p = AdminApiList::readPaging($request);
|
||||
$range = $service->resolveDateRange($validated);
|
||||
@@ -24,6 +27,7 @@ final class AdminReportPlayDimensionController extends Controller
|
||||
$range['date_to'],
|
||||
$p['page'],
|
||||
$p['perPage'],
|
||||
$admin,
|
||||
);
|
||||
|
||||
return AdminApiList::json($paginator, static function (object $row): array {
|
||||
|
||||
@@ -13,10 +13,14 @@ final class AdminReportPlayerWinLossController extends Controller
|
||||
{
|
||||
public function __invoke(AdminReportQueryRequest $request, AdminReportQueryService $service): JsonResponse
|
||||
{
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$validated = $request->validated();
|
||||
$p = AdminApiList::readPaging($request);
|
||||
$range = $service->resolveDateRange($validated);
|
||||
$playerId = isset($validated['player_id']) ? (int) $validated['player_id'] : null;
|
||||
$agentNodeId = isset($validated['agent_node_id']) ? (int) $validated['agent_node_id'] : null;
|
||||
|
||||
$paginator = $service->playerWinLossPaginated(
|
||||
$playerId,
|
||||
@@ -24,11 +28,16 @@ final class AdminReportPlayerWinLossController extends Controller
|
||||
$range['date_to'],
|
||||
$p['page'],
|
||||
$p['perPage'],
|
||||
$admin,
|
||||
$agentNodeId > 0 ? $agentNodeId : null,
|
||||
);
|
||||
|
||||
return AdminApiList::json($paginator, static function (object $row): array {
|
||||
return [
|
||||
'player_id' => (int) $row->player_id,
|
||||
'agent_node_id' => isset($row->agent_node_id) ? (int) $row->agent_node_id : null,
|
||||
'agent_code' => isset($row->agent_code) ? (string) $row->agent_code : null,
|
||||
'agent_name' => isset($row->agent_name) ? (string) $row->agent_name : null,
|
||||
'username' => $row->username !== null ? (string) $row->username : 'player#'.(int) $row->player_id,
|
||||
'total_bet_minor' => (int) $row->total_bet_minor,
|
||||
'total_payout_minor' => (int) $row->total_payout_minor,
|
||||
|
||||
@@ -13,6 +13,9 @@ final class AdminReportRebateCommissionController extends Controller
|
||||
{
|
||||
public function __invoke(AdminReportQueryRequest $request, AdminReportQueryService $service): JsonResponse
|
||||
{
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$validated = $request->validated();
|
||||
$p = AdminApiList::readPaging($request);
|
||||
$range = $service->resolveDateRange($validated);
|
||||
@@ -24,6 +27,7 @@ final class AdminReportRebateCommissionController extends Controller
|
||||
$range['date_to'],
|
||||
$p['page'],
|
||||
$p['perPage'],
|
||||
$admin,
|
||||
);
|
||||
|
||||
return AdminApiList::json($paginator, static function (object $row): array {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Reports;
|
||||
|
||||
use App\Models\AdminUser;
|
||||
use App\Models\ReportJob;
|
||||
use App\Services\Admin\AdminReportJobService;
|
||||
use App\Services\Admin\AdminReportQueryService;
|
||||
@@ -29,7 +30,8 @@ final class ReportJobDownloadController
|
||||
$dateTo,
|
||||
);
|
||||
$filename = $label.'_'.$pathSuffix.'.'.$report_job->export_format;
|
||||
$rows = $service->reportRows((string) $report_job->report_type, $filterJson);
|
||||
$scopedAdmin = AdminUser::query()->find((int) $report_job->admin_user_id);
|
||||
$rows = $service->reportRows((string) $report_job->report_type, $filterJson, $scopedAdmin);
|
||||
|
||||
if ((string) $report_job->export_format === 'xlsx') {
|
||||
return $spreadsheetExporter->streamDownload($rows, $filename);
|
||||
|
||||
@@ -4,6 +4,8 @@ namespace App\Http\Controllers\Api\V1\Admin\Settlement;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Support\AdminApiList;
|
||||
use App\Support\AdminSiteScope;
|
||||
use App\Support\AgentNodeApiPresenter;
|
||||
use App\Models\SettlementBatch;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
@@ -16,15 +18,33 @@ final class AdminSettlementBatchDetailsController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request, SettlementBatch $batch): JsonResponse
|
||||
{
|
||||
$p = AdminApiList::readPaging($request);
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$paginator = TicketSettlementDetail::query()
|
||||
$p = AdminApiList::readPaging($request);
|
||||
$agentNodeId = $request->integer('agent_node_id') ?: null;
|
||||
|
||||
$detailQuery = TicketSettlementDetail::query()
|
||||
->where('settlement_batch_id', $batch->id)
|
||||
->with([
|
||||
'ticketItem:id,ticket_no,play_code,player_id',
|
||||
'ticketItem.player:id,site_code,username,nickname,site_player_id',
|
||||
'ticketItem.player:id,site_code,username,nickname,site_player_id,agent_node_id',
|
||||
'ticketItem.player.agentNode:id,code,name',
|
||||
'ticketItem.order:id,currency_code',
|
||||
])
|
||||
]);
|
||||
|
||||
if (! $admin->isSuperAdmin() || ($agentNodeId !== null && $agentNodeId > 0)) {
|
||||
$detailQuery->whereHas('ticketItem.player', static function ($playerQuery) use ($admin, $agentNodeId): void {
|
||||
AdminSiteScope::applyPlayerFilters(
|
||||
$playerQuery,
|
||||
$admin,
|
||||
null,
|
||||
$agentNodeId !== null && $agentNodeId > 0 ? $agentNodeId : null,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
$paginator = $detailQuery
|
||||
->orderBy('id')
|
||||
->paginate($p['perPage'], ['*'], 'page', $p['page']);
|
||||
|
||||
@@ -37,6 +57,7 @@ final class AdminSettlementBatchDetailsController extends Controller
|
||||
return [
|
||||
'id' => (int) $row->id,
|
||||
'ticket_item_id' => (int) $row->ticket_item_id,
|
||||
...AgentNodeApiPresenter::embed($player?->agentNode),
|
||||
'ticket_no' => $item?->ticket_no,
|
||||
'play_code' => $item?->play_code,
|
||||
'currency_code' => $order?->currency_code,
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api\V1\Admin\Settlement;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Support\AdminApiList;
|
||||
use App\Support\AdminSiteScope;
|
||||
use App\Models\SettlementBatch;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
@@ -16,14 +17,29 @@ final class AdminSettlementBatchIndexController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request): JsonResponse
|
||||
{
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$p = AdminApiList::readPaging($request);
|
||||
$drawNo = trim((string) $request->query('draw_no', ''));
|
||||
$status = trim((string) $request->query('status', ''));
|
||||
$agentNodeId = $request->integer('agent_node_id') ?: null;
|
||||
|
||||
$q = SettlementBatch::query()
|
||||
->with(['draw:id,draw_no'])
|
||||
->orderByDesc('id');
|
||||
|
||||
if (! $admin->isSuperAdmin() || ($agentNodeId !== null && $agentNodeId > 0)) {
|
||||
$q->whereHas('details.ticketItem.player', static function ($playerQuery) use ($admin, $agentNodeId): void {
|
||||
AdminSiteScope::applyPlayerFilters(
|
||||
$playerQuery,
|
||||
$admin,
|
||||
null,
|
||||
$agentNodeId !== null && $agentNodeId > 0 ? $agentNodeId : null,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if ($drawNo !== '') {
|
||||
$q->whereHas('draw', fn ($d) => $d->where('draw_no', 'like', '%'.$drawNo.'%'));
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Support\ApiResponse;
|
||||
use App\Support\CurrencyFormatter;
|
||||
use App\Support\PaginationTrait;
|
||||
use App\Support\AdminSiteScope;
|
||||
use App\Support\AgentNodeApiPresenter;
|
||||
use App\Support\TicketItemListFilters;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -44,7 +45,8 @@ final class AdminTicketItemIndexController extends Controller
|
||||
->with([
|
||||
'draw:id,draw_no,business_date',
|
||||
'order:id,order_no,currency_code,created_at',
|
||||
'player:id,site_code,site_player_id,username,nickname',
|
||||
'player:id,site_code,site_player_id,username,nickname,agent_node_id',
|
||||
'player.agentNode:id,code,name',
|
||||
])
|
||||
->orderByDesc('ticket_items.id');
|
||||
|
||||
@@ -86,10 +88,14 @@ final class AdminTicketItemIndexController extends Controller
|
||||
is_string($validated['end_date'] ?? null) ? $validated['end_date'] : null,
|
||||
);
|
||||
|
||||
$agentNodeId = isset($validated['agent_node_id']) ? (int) $validated['agent_node_id'] : null;
|
||||
|
||||
AdminSiteScope::applyViaPlayerRelationWithSiteCode(
|
||||
$query,
|
||||
$admin,
|
||||
is_string($validated['site_code'] ?? null) ? $validated['site_code'] : null,
|
||||
'player',
|
||||
$agentNodeId > 0 ? $agentNodeId : null,
|
||||
);
|
||||
|
||||
$paginator = $query->paginate(perPage: $perPage, page: $page, columns: ['*']);
|
||||
@@ -103,6 +109,7 @@ final class AdminTicketItemIndexController extends Controller
|
||||
return [
|
||||
'id' => $row->id,
|
||||
'ticket_no' => $row->ticket_no,
|
||||
...AgentNodeApiPresenter::embed($row->player?->agentNode),
|
||||
'player_id' => $row->player_id,
|
||||
'site_code' => $row->player?->site_code,
|
||||
'site_player_id' => $row->player?->site_player_id,
|
||||
|
||||
@@ -12,7 +12,11 @@ final class AdminRoleIndexController extends Controller
|
||||
{
|
||||
public function __invoke(): JsonResponse
|
||||
{
|
||||
$roles = AdminRole::query()->orderBy('sort_order')->orderBy('id')->get();
|
||||
$roles = AdminRole::query()
|
||||
->where('scope_type', AdminRole::SCOPE_SYSTEM)
|
||||
->orderBy('sort_order')
|
||||
->orderBy('id')
|
||||
->get();
|
||||
|
||||
return ApiResponse::success([
|
||||
'items' => $roles->map(static fn (AdminRole $role): array => AdminRoleApiPresenter::item($role))->values()->all(),
|
||||
|
||||
@@ -26,6 +26,9 @@ final class AdminRoleStoreController extends Controller
|
||||
'status' => $request->validated('status', 1),
|
||||
'is_system' => false,
|
||||
'sort_order' => 0,
|
||||
'scope_type' => AdminRole::SCOPE_SYSTEM,
|
||||
'owner_agent_id' => null,
|
||||
'delegated_from_role_id' => null,
|
||||
]);
|
||||
$role->syncLegacyPermissionSlugs($permissionSlugs);
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Models\TransferOrder;
|
||||
use App\Support\PaginationTrait;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Support\AdminSiteScope;
|
||||
use App\Support\AgentNodeApiPresenter;
|
||||
use App\Support\CurrencyFormatter;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\TransferOrderListRequest;
|
||||
@@ -44,7 +45,10 @@ final class TransferOrderListController extends Controller
|
||||
$page = $this->page($request);
|
||||
|
||||
$query = TransferOrder::query()
|
||||
->with(['player:id,site_code,site_player_id,username,nickname'])
|
||||
->with([
|
||||
'player:id,site_code,site_player_id,username,nickname,agent_node_id',
|
||||
'player.agentNode:id,code,name',
|
||||
])
|
||||
->orderByDesc('id');
|
||||
|
||||
if (! empty($validated['player_id'])) {
|
||||
@@ -85,10 +89,14 @@ final class TransferOrderListController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$agentNodeId = isset($validated['agent_node_id']) ? (int) $validated['agent_node_id'] : null;
|
||||
|
||||
AdminSiteScope::applyViaPlayerRelationWithSiteCode(
|
||||
$query,
|
||||
$admin,
|
||||
is_string($validated['site_code'] ?? null) ? $validated['site_code'] : null,
|
||||
'player',
|
||||
$agentNodeId > 0 ? $agentNodeId : null,
|
||||
);
|
||||
|
||||
$paginator = $query->paginate($perPage, ['*'], 'page', $page);
|
||||
@@ -119,6 +127,7 @@ final class TransferOrderListController extends Controller
|
||||
return [
|
||||
'id' => $o->id,
|
||||
'transfer_no' => $o->transfer_no,
|
||||
...AgentNodeApiPresenter::embed($p?->agentNode),
|
||||
'player_id' => $o->player_id,
|
||||
'site_code' => $p?->site_code,
|
||||
'site_player_id' => $p?->site_player_id,
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Support\ApiResponse;
|
||||
use App\Support\PaginationTrait;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Support\AdminSiteScope;
|
||||
use App\Support\AgentNodeApiPresenter;
|
||||
use App\Support\CurrencyFormatter;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\WalletTransactionListRequest;
|
||||
@@ -43,7 +44,10 @@ final class WalletTransactionListController extends Controller
|
||||
$page = $this->page($request);
|
||||
|
||||
$query = WalletTxn::query()
|
||||
->with(['player:id,site_code,site_player_id,username,nickname'])
|
||||
->with([
|
||||
'player:id,site_code,site_player_id,username,nickname,agent_node_id',
|
||||
'player.agentNode:id,code,name',
|
||||
])
|
||||
->orderByDesc('id');
|
||||
|
||||
if (! empty($validated['player_id'])) {
|
||||
@@ -88,10 +92,14 @@ final class WalletTransactionListController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$agentNodeId = isset($validated['agent_node_id']) ? (int) $validated['agent_node_id'] : null;
|
||||
|
||||
AdminSiteScope::applyViaPlayerRelationWithSiteCode(
|
||||
$query,
|
||||
$admin,
|
||||
is_string($validated['site_code'] ?? null) ? $validated['site_code'] : null,
|
||||
'player',
|
||||
$agentNodeId > 0 ? $agentNodeId : null,
|
||||
);
|
||||
|
||||
$paginator = $query->paginate($perPage, ['*'], 'page', $page);
|
||||
@@ -118,6 +126,7 @@ final class WalletTransactionListController extends Controller
|
||||
return [
|
||||
'id' => $t->id,
|
||||
'txn_no' => $t->txn_no,
|
||||
...AgentNodeApiPresenter::embed($p?->agentNode),
|
||||
'player_id' => $t->player_id,
|
||||
'site_code' => $p?->site_code,
|
||||
'site_player_id' => $p?->site_player_id,
|
||||
|
||||
Reference in New Issue
Block a user