feat: 增强代理节点和代理资料管理功能

- 在 AgentNodeProfileController 中添加对父代理能力授予的验证,确保子代理的权限在父代理范围内。
- 更新多个请求类,统一代理资料字段的验证逻辑,提升代码复用性。
- 引入 AgentProfileFieldRules 以简化代理资料更新请求的规则定义。
- 在 AgentProfile 模型中设置主键为 agent_node_id,确保与代理节点的关联性。
- 更新错误信息,增加对授信额度和占成比例的验证,确保数据一致性。
This commit is contained in:
2026-06-04 10:15:10 +08:00
parent e3ffffad9c
commit 96545f87f6
17 changed files with 565 additions and 22 deletions

View File

@@ -41,7 +41,12 @@ final class AgentNodeProfileController extends Controller
? AgentNode::query()->find($agent_node->parent_id)
: null;
$profile = $service->upsertForNode($agent_node, $request->validated(), $parent);
$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));

View File

@@ -15,6 +15,11 @@ final class AdminAgentLineStoreRequest extends ApiFormRequest
return true;
}
protected function prepareForValidation(): void
{
$this->prepareAgentProfileFieldsForValidation();
}
/** @return array<string, mixed> */
public function rules(): array
{

View File

@@ -2,25 +2,26 @@
namespace App\Http\Requests\Admin;
use App\Http\Requests\Admin\Concerns\AgentProfileFieldRules;
use App\Http\Requests\ApiFormRequest;
final class AdminAgentProfileUpdateRequest extends ApiFormRequest
{
use AgentProfileFieldRules;
public function authorize(): bool
{
return true;
}
protected function prepareForValidation(): void
{
$this->prepareAgentProfileFieldsForValidation();
}
/** @return array<string, mixed> */
public function rules(): array
{
return [
'total_share_rate' => ['sometimes', 'numeric', 'min:0', 'max:100'],
'credit_limit' => ['sometimes', 'integer', 'min:0'],
'rebate_limit' => ['sometimes', 'numeric', 'min:0', 'max:1'],
'default_player_rebate' => ['sometimes', 'numeric', 'min:0', 'max:1'],
'settlement_cycle' => ['sometimes', 'string', 'in:daily,weekly,monthly'],
'can_grant_extra_rebate' => ['sometimes', 'boolean'],
];
return $this->agentProfileFieldRules();
}
}

View File

@@ -14,6 +14,11 @@ final class AgentNodeStoreRequest extends ApiFormRequest
return true;
}
protected function prepareForValidation(): void
{
$this->prepareAgentProfileFieldsForValidation();
}
/** @return array<string, mixed> */
public function rules(): array
{

View File

@@ -2,6 +2,8 @@
namespace App\Http\Requests\Admin\Concerns;
use App\Support\AgentSettlementCycle;
trait AgentProfileFieldRules
{
/** @return array<string, mixed> */
@@ -12,10 +14,21 @@ trait AgentProfileFieldRules
'credit_limit' => ['sometimes', 'integer', 'min:0'],
'rebate_limit' => ['sometimes', 'numeric', 'min:0', 'max:1'],
'default_player_rebate' => ['sometimes', 'numeric', 'min:0', 'max:1'],
'settlement_cycle' => ['sometimes', 'string', 'in:daily,weekly,monthly'],
'settlement_cycle' => ['sometimes', 'string', 'in:'.implode(',', AgentSettlementCycle::VALUES)],
'can_grant_extra_rebate' => ['sometimes', 'boolean'],
'can_create_child_agent' => ['sometimes', 'boolean'],
'can_create_player' => ['sometimes', 'boolean'],
];
}
protected function prepareAgentProfileFieldsForValidation(): void
{
if (! $this->has('settlement_cycle')) {
return;
}
$this->merge([
'settlement_cycle' => AgentSettlementCycle::normalize($this->input('settlement_cycle')),
]);
}
}