Files
lotteryLaravel/app/Http/Controllers/Api/V1/Admin/Agent/AgentNodeProfileController.php
kang 96545f87f6 feat: 增强代理节点和代理资料管理功能
- 在 AgentNodeProfileController 中添加对父代理能力授予的验证,确保子代理的权限在父代理范围内。
- 更新多个请求类,统一代理资料字段的验证逻辑,提升代码复用性。
- 引入 AgentProfileFieldRules 以简化代理资料更新请求的规则定义。
- 在 AgentProfile 模型中设置主键为 agent_node_id,确保与代理节点的关联性。
- 更新错误信息,增加对授信额度和占成比例的验证,确保数据一致性。
2026-06-04 10:15:10 +08:00

55 lines
1.9 KiB
PHP

<?php
namespace App\Http\Controllers\Api\V1\Admin\Agent;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\AdminAgentProfileUpdateRequest;
use App\Models\AgentNode;
use App\Models\AgentProfile;
use App\Services\Agent\AgentNodeService;
use App\Services\Agent\AgentProfileService;
use App\Support\AdminAgentScope;
use App\Support\ApiResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
/** GET/PUT /api/v1/admin/agent-nodes/{agent_node}/profile */
final class AgentNodeProfileController extends Controller
{
public function show(Request $request, AgentNode $agent_node): JsonResponse
{
$admin = $request->lotteryAdmin();
abort_if($admin === null, 401);
abort_if(! AdminAgentScope::nodeVisibleTo($admin, $agent_node), 403);
$profile = AgentProfile::query()->firstOrNew(['agent_node_id' => $agent_node->id]);
return ApiResponse::success(app(AgentProfileService::class)->present($profile));
}
public function update(
AdminAgentProfileUpdateRequest $request,
AgentNode $agent_node,
AgentProfileService $service,
AgentNodeService $agentNodeService,
): JsonResponse {
$admin = $request->lotteryAdmin();
abort_if($admin === null, 401);
abort_if(! AdminAgentScope::nodeVisibleTo($admin, $agent_node), 403);
$parent = $agent_node->parent_id !== null
? AgentNode::query()->find($agent_node->parent_id)
: null;
$payload = $request->validated();
if ($parent !== null) {
$service->assertChildCapabilityGrantsWithinParent($parent, $payload, $admin);
}
$profile = $service->upsertForNode($agent_node, $payload, $parent);
$agentNodeService->syncPrimaryOwnerRoleFromProfile($agent_node, $profile);
return ApiResponse::success($service->present($profile));
}
}