feat(agents, validation): enhance agent profile and player management with input validation
Added input validation for admin login and player creation forms, ensuring usernames and passwords meet specified criteria. Introduced new components for numeric input handling in agent profile fields, improving user experience. Updated agent line detail and provision wizard to reflect these changes, enhancing overall data integrity and user interaction.
This commit is contained in:
@@ -29,7 +29,13 @@ This version has breaking changes — APIs, conventions, and file structure may
|
||||
|
||||
新增涉及玩家资金的页面时,先读 `src/lib/admin-player-display.ts`。
|
||||
|
||||
## Learned User Preferences
|
||||
|
||||
- 占成/授信/回水/上限等数值字段用 `AdminNumericStepper`(± 步进 + 可手输),勿单独裸 `input[type=number]`。
|
||||
|
||||
## Learned Workspace Facts
|
||||
|
||||
- 无接入站时依赖站点的页面展示 `<AdminNoIntegrationSiteState />`;仅 `profile.is_super_admin` 显示创建入口。
|
||||
- 超管判定用登录态 `is_super_admin`,勿用站点角色或 `admin_user_site_roles` 绑定推断。
|
||||
- 站点管理员(`profile.site != null`)代理 UI 绕过选中代理的 `can_create_*` 门控,按自身 manage 权限展示 Tab/操作。
|
||||
- 站点管理员在代理下创建玩家须传 `agent_node_id`(与超管同逻辑),勿默认挂根代理。
|
||||
|
||||
180
src/components/admin/admin-numeric-stepper.tsx
Normal file
180
src/components/admin/admin-numeric-stepper.tsx
Normal file
@@ -0,0 +1,180 @@
|
||||
"use client";
|
||||
|
||||
import { Minus, Plus } from "lucide-react";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export type AdminNumericStepperProps = {
|
||||
id?: string;
|
||||
value: string;
|
||||
onValueChange: (value: string) => void;
|
||||
min?: number;
|
||||
max?: number;
|
||||
step?: number;
|
||||
/** 整数模式(授信额度等);默认 false 支持小数(比例 %) */
|
||||
integer?: boolean;
|
||||
disabled?: boolean;
|
||||
/** 失焦时超出 max 是否保留原输入(供保存前校验报错),默认 clamp */
|
||||
preserveOverMaxOnBlur?: boolean;
|
||||
className?: string;
|
||||
suffix?: string;
|
||||
};
|
||||
|
||||
function parseNumeric(value: string, integer: boolean): number {
|
||||
const parsed = integer ? Number.parseInt(value, 10) : Number.parseFloat(value);
|
||||
return Number.isFinite(parsed) ? parsed : 0;
|
||||
}
|
||||
|
||||
function formatNumeric(value: number, integer: boolean, step: number): string {
|
||||
if (integer) {
|
||||
return String(Math.trunc(value));
|
||||
}
|
||||
|
||||
const decimals = step < 1 ? 2 : step < 0.1 ? 3 : 1;
|
||||
const fixed = value.toFixed(decimals);
|
||||
return fixed.replace(/\.?0+$/, "") || "0";
|
||||
}
|
||||
|
||||
function clamp(value: number, min?: number, max?: number): number {
|
||||
let next = value;
|
||||
if (min !== undefined) {
|
||||
next = Math.max(min, next);
|
||||
}
|
||||
if (max !== undefined) {
|
||||
next = Math.min(max, next);
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
function isPartialInput(text: string, integer: boolean): boolean {
|
||||
const trimmed = text.trim();
|
||||
if (trimmed === "" || trimmed === "-" || trimmed === ".") {
|
||||
return true;
|
||||
}
|
||||
if (!integer && trimmed.endsWith(".")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function AdminNumericStepper({
|
||||
id,
|
||||
value,
|
||||
onValueChange,
|
||||
min = 0,
|
||||
max,
|
||||
step = 1,
|
||||
integer = false,
|
||||
disabled = false,
|
||||
preserveOverMaxOnBlur = false,
|
||||
className,
|
||||
suffix,
|
||||
}: AdminNumericStepperProps): React.ReactElement {
|
||||
const current = parseNumeric(value, integer);
|
||||
const atMin = min !== undefined && current <= min;
|
||||
const atMax = max !== undefined && current >= max;
|
||||
const outOfRange =
|
||||
!disabled &&
|
||||
Number.isFinite(current) &&
|
||||
((min !== undefined && current < min) || (max !== undefined && current > max));
|
||||
|
||||
const applyDelta = (delta: number) => {
|
||||
const next = clamp(current + delta, min, max);
|
||||
onValueChange(formatNumeric(next, integer, step));
|
||||
};
|
||||
|
||||
const commitInput = (raw: string) => {
|
||||
if (isPartialInput(raw, integer)) {
|
||||
onValueChange(formatNumeric(min ?? 0, integer, step));
|
||||
return;
|
||||
}
|
||||
|
||||
const parsed = parseNumeric(raw, integer);
|
||||
if (!Number.isFinite(parsed)) {
|
||||
onValueChange(formatNumeric(min ?? 0, integer, step));
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
preserveOverMaxOnBlur &&
|
||||
max !== undefined &&
|
||||
parsed > max
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
onValueChange(formatNumeric(clamp(parsed, min, max), integer, step));
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex h-10 items-stretch overflow-hidden rounded-md border bg-background/50 shadow-xs",
|
||||
outOfRange ? "border-destructive/80 ring-1 ring-destructive/25" : "border-input",
|
||||
disabled && "pointer-events-none opacity-50",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
className="h-auto shrink-0 rounded-none border-r border-input/80 px-3 hover:bg-muted/60"
|
||||
disabled={disabled || atMin}
|
||||
aria-label="减少"
|
||||
onClick={() => applyDelta(-step)}
|
||||
>
|
||||
<Minus className="size-4" aria-hidden />
|
||||
</Button>
|
||||
<div className="flex min-w-0 flex-1 items-center justify-center gap-1 px-2">
|
||||
<input
|
||||
id={id}
|
||||
type="text"
|
||||
inputMode={integer ? "numeric" : "decimal"}
|
||||
value={value}
|
||||
disabled={disabled}
|
||||
aria-valuemin={min}
|
||||
aria-valuemax={max}
|
||||
aria-invalid={outOfRange || undefined}
|
||||
className={cn(
|
||||
"h-full w-full min-w-0 border-0 bg-transparent text-center text-sm font-medium tabular-nums outline-none",
|
||||
"focus:ring-0",
|
||||
)}
|
||||
onBlur={(e) => {
|
||||
commitInput(e.target.value);
|
||||
}}
|
||||
onChange={(e) => {
|
||||
const next = e.target.value;
|
||||
if (integer && next !== "" && !/^-?\d*$/.test(next)) {
|
||||
return;
|
||||
}
|
||||
if (!integer && next !== "" && !/^-?\d*\.?\d*$/.test(next)) {
|
||||
return;
|
||||
}
|
||||
onValueChange(next);
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") {
|
||||
e.currentTarget.blur();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{suffix ? (
|
||||
<span className="shrink-0 text-sm text-muted-foreground">{suffix}</span>
|
||||
) : null}
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
className="h-auto shrink-0 rounded-none border-l border-input/80 px-3 hover:bg-muted/60"
|
||||
disabled={disabled || atMax}
|
||||
aria-label="增加"
|
||||
onClick={() => applyDelta(step)}
|
||||
>
|
||||
<Plus className="size-4" aria-hidden />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -17,6 +17,10 @@ import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { getAdminCaptcha, postAdminLogin } from "@/api";
|
||||
import { verifyStoredAdminSession } from "@/lib/admin-session-verify";
|
||||
import {
|
||||
validateAdminLoginAccount,
|
||||
validateAdminPassword,
|
||||
} from "@/lib/admin-input-validation";
|
||||
import { readToken } from "@/stores/admin-token";
|
||||
import { authModuleMeta } from "@/modules/auth/meta";
|
||||
import { useAdminSessionStore } from "@/stores/admin-session";
|
||||
@@ -101,6 +105,24 @@ export function LoginForm() {
|
||||
return;
|
||||
}
|
||||
|
||||
const accountIssue = validateAdminLoginAccount(account);
|
||||
if (accountIssue === "invalid_charset") {
|
||||
toast.error(
|
||||
t("accountInvalidCharset", {
|
||||
defaultValue: "登录账号只能使用字母、数字、点(.)、下划线和连字符",
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const passwordIssue = validateAdminPassword(password);
|
||||
if (passwordIssue === "too_short") {
|
||||
toast.error(
|
||||
t("passwordMinLength", { defaultValue: "密码至少需要 8 个字符" }),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const result = await postAdminLogin({
|
||||
|
||||
74
src/components/admin/player-credit-limit-field.tsx
Normal file
74
src/components/admin/player-credit-limit-field.tsx
Normal file
@@ -0,0 +1,74 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { AdminNumericStepper } from "@/components/admin/admin-numeric-stepper";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { isNumericStepperOutOfRange } from "@/lib/agent-profile-caps";
|
||||
import { formatCredit } from "@/modules/agents/agent-line-sidebar";
|
||||
|
||||
export type PlayerCreditLimitFieldProps = {
|
||||
id: string;
|
||||
value: string;
|
||||
onValueChange: (value: string) => void;
|
||||
parentAvailableCredit: number | null;
|
||||
/** 编辑已有玩家时传入当前授信,用于计算可上调上限 */
|
||||
baselineCreditLimit?: number;
|
||||
};
|
||||
|
||||
export function PlayerCreditLimitField({
|
||||
id,
|
||||
value,
|
||||
onValueChange,
|
||||
parentAvailableCredit,
|
||||
baselineCreditLimit = 0,
|
||||
}: PlayerCreditLimitFieldProps): React.ReactElement {
|
||||
const { t } = useTranslation(["agents"]);
|
||||
|
||||
const maxCredit = useMemo(() => {
|
||||
if (parentAvailableCredit === null) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return baselineCreditLimit + parentAvailableCredit;
|
||||
}, [baselineCreditLimit, parentAvailableCredit]);
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor={id} className="text-muted-foreground">
|
||||
{t("playersPanel.creditLimit", { defaultValue: "授信额度" })}
|
||||
</Label>
|
||||
<AdminNumericStepper
|
||||
id={id}
|
||||
value={value}
|
||||
onValueChange={onValueChange}
|
||||
min={0}
|
||||
max={maxCredit}
|
||||
step={1000}
|
||||
integer
|
||||
preserveOverMaxOnBlur
|
||||
/>
|
||||
{parentAvailableCredit !== null ? (
|
||||
<p className="text-[11px] text-muted-foreground/80">
|
||||
{t("playersPanel.availableToGrant", {
|
||||
defaultValue: "代理剩余可下发:{{amount}}",
|
||||
amount: formatCredit(parentAvailableCredit),
|
||||
})}
|
||||
</p>
|
||||
) : null}
|
||||
{parentAvailableCredit !== null &&
|
||||
isNumericStepperOutOfRange(value, {
|
||||
min: 0,
|
||||
max: maxCredit,
|
||||
integer: true,
|
||||
}) ? (
|
||||
<p className="text-[11px] text-destructive">
|
||||
{t("playersPanel.creditLimitExceeded", {
|
||||
defaultValue: "授信额度不能超过当前代理可下发额度",
|
||||
})}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
42
src/lib/admin-input-validation.ts
Normal file
42
src/lib/admin-input-validation.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
/** 后台/彩票端登录账号:字母、数字、点、下划线、连字符。 */
|
||||
export const ADMIN_ACCOUNT_PATTERN = /^[a-zA-Z0-9._-]+$/;
|
||||
|
||||
export const ADMIN_PASSWORD_MIN_LENGTH = 8;
|
||||
export const NATIVE_PLAYER_PASSWORD_MIN_LENGTH = 6;
|
||||
|
||||
export type AccountValidationIssue = "empty" | "invalid_charset";
|
||||
export type PasswordValidationIssue = "empty" | "too_short";
|
||||
|
||||
export function validateAdminLoginAccount(value: string): AccountValidationIssue | null {
|
||||
const trimmed = value.trim();
|
||||
if (trimmed === "") {
|
||||
return "empty";
|
||||
}
|
||||
if (!ADMIN_ACCOUNT_PATTERN.test(trimmed)) {
|
||||
return "invalid_charset";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function validateAdminPassword(
|
||||
value: string,
|
||||
minLength: number = ADMIN_PASSWORD_MIN_LENGTH,
|
||||
): PasswordValidationIssue | null {
|
||||
if (value === "") {
|
||||
return "empty";
|
||||
}
|
||||
if (value.length < minLength) {
|
||||
return "too_short";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function validateNativePlayerUsername(value: string): AccountValidationIssue | null {
|
||||
return validateAdminLoginAccount(value);
|
||||
}
|
||||
|
||||
export function validateNativePlayerPassword(value: string): PasswordValidationIssue | null {
|
||||
return validateAdminPassword(value, NATIVE_PLAYER_PASSWORD_MIN_LENGTH);
|
||||
}
|
||||
205
src/lib/agent-profile-caps.ts
Normal file
205
src/lib/agent-profile-caps.ts
Normal file
@@ -0,0 +1,205 @@
|
||||
import type { AgentParentCaps } from "@/types/api/admin-agent";
|
||||
|
||||
/** 是否为站点一级代理(根节点)。 */
|
||||
export function isLineRootAgentNode(
|
||||
node: { is_root?: boolean; depth?: number } | null | undefined,
|
||||
): boolean {
|
||||
return node != null && (node.is_root === true || node.depth === 0);
|
||||
}
|
||||
|
||||
/** 一级代理占成/授信/回水仅超管可改;下级代理仍由上级维护。 */
|
||||
export function isRootProfileEditableByActor(
|
||||
node: { is_root?: boolean; depth?: number } | null | undefined,
|
||||
isSuperAdmin: boolean,
|
||||
): boolean {
|
||||
return isSuperAdmin || !isLineRootAgentNode(node);
|
||||
}
|
||||
|
||||
/** 百分比字段硬顶(0–100)。 */
|
||||
export const AGENT_PERCENT_HARD_MAX = 100;
|
||||
|
||||
/** 有上级时:回水上限不得超过上级回水上限与 100% 的较小值。 */
|
||||
export function maxRebatePercentFromParent(parentCaps: AgentParentCaps | null): number {
|
||||
if (parentCaps === null) {
|
||||
return AGENT_PERCENT_HARD_MAX;
|
||||
}
|
||||
|
||||
const parentLimit = Number(parentCaps.rebate_limit);
|
||||
if (!Number.isFinite(parentLimit) || parentLimit < 0) {
|
||||
return AGENT_PERCENT_HARD_MAX;
|
||||
}
|
||||
|
||||
return Math.min(AGENT_PERCENT_HARD_MAX, parentLimit);
|
||||
}
|
||||
|
||||
/** 默认玩家回水不得超过本节点回水上限与上级顶。 */
|
||||
export function maxDefaultRebatePercent(
|
||||
rebateLimitText: string,
|
||||
parentCaps: AgentParentCaps | null,
|
||||
): number {
|
||||
const rebateCap = maxRebatePercentFromParent(parentCaps);
|
||||
const ownLimit = Number.parseFloat(rebateLimitText);
|
||||
if (!Number.isFinite(ownLimit) || ownLimit < 0) {
|
||||
return rebateCap;
|
||||
}
|
||||
|
||||
return Math.min(rebateCap, ownLimit);
|
||||
}
|
||||
|
||||
/**
|
||||
* 授信额度上限:已有 baseline + 上级当前可下发(编辑下级时)。
|
||||
* 无上级(根代理)时不设顶,仅由业务校验 ≥ 已下发。
|
||||
*/
|
||||
export function maxCreditLimitFromParent(
|
||||
parentCaps: AgentParentCaps | null,
|
||||
baselineCreditLimit: number,
|
||||
): number | undefined {
|
||||
if (parentCaps === null) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const baseline = Number.isFinite(baselineCreditLimit) ? Math.max(0, baselineCreditLimit) : 0;
|
||||
const parentAvailable = Number(parentCaps.available_credit);
|
||||
const extra = Number.isFinite(parentAvailable) ? Math.max(0, parentAvailable) : 0;
|
||||
|
||||
return baseline + extra;
|
||||
}
|
||||
|
||||
/** 相对占成(占上级 %)换算后的实际占成,不得超过上级总占成。 */
|
||||
export function actualShareRateFromRelative(
|
||||
relativePercent: number,
|
||||
parentCaps: AgentParentCaps | null,
|
||||
): number | null {
|
||||
if (parentCaps === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const parentRate = Number(parentCaps.total_share_rate);
|
||||
if (!Number.isFinite(parentRate) || parentRate < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const relative = Number.isFinite(relativePercent) ? relativePercent : 0;
|
||||
return Number(((parentRate * relative) / 100).toFixed(2));
|
||||
}
|
||||
|
||||
export type AgentProfileValidationIssue =
|
||||
| { code: "share_range" }
|
||||
| { code: "share_exceeds_parent"; max: number }
|
||||
| { code: "credit_invalid" }
|
||||
| { code: "credit_exceeds_parent"; max: number }
|
||||
| { code: "credit_below_allocated"; min: number }
|
||||
| { code: "rebate_limit_range" }
|
||||
| { code: "default_rebate_range" }
|
||||
| { code: "default_exceeds_limit"; max: number }
|
||||
| { code: "rebate_exceeds_parent"; max: number };
|
||||
|
||||
export type AgentProfileScalarValidationInput = {
|
||||
shareRateText: string;
|
||||
creditLimitText: string;
|
||||
rebateLimitText: string;
|
||||
defaultRebateText: string;
|
||||
parentCaps: AgentParentCaps | null;
|
||||
baselineCreditLimit: number;
|
||||
minCreditLimit: number;
|
||||
usesRelativeShare: boolean;
|
||||
validateCredit: boolean;
|
||||
};
|
||||
|
||||
function parsePercentField(value: string): number | null {
|
||||
const trimmed = value.trim();
|
||||
if (trimmed === "") {
|
||||
return null;
|
||||
}
|
||||
const parsed = Number.parseFloat(trimmed);
|
||||
return Number.isFinite(parsed) ? parsed : null;
|
||||
}
|
||||
|
||||
/** 保存前校验占成/授信/回水是否在上级与已下发约束内。 */
|
||||
export function validateAgentProfileScalars(
|
||||
input: AgentProfileScalarValidationInput,
|
||||
): AgentProfileValidationIssue | null {
|
||||
const shareRate = Number.parseFloat(input.shareRateText);
|
||||
const creditLimit = Number.parseInt(input.creditLimitText, 10);
|
||||
const rebateLimit = parsePercentField(input.rebateLimitText);
|
||||
const defaultRebate = parsePercentField(input.defaultRebateText);
|
||||
|
||||
if (Number.isNaN(shareRate) || shareRate < 0 || shareRate > AGENT_PERCENT_HARD_MAX) {
|
||||
return { code: "share_range" };
|
||||
}
|
||||
|
||||
if (input.usesRelativeShare && input.parentCaps) {
|
||||
const actualShare = actualShareRateFromRelative(shareRate, input.parentCaps);
|
||||
const parentShare = Number(input.parentCaps.total_share_rate);
|
||||
if (
|
||||
actualShare !== null &&
|
||||
Number.isFinite(parentShare) &&
|
||||
actualShare > parentShare + 1e-9
|
||||
) {
|
||||
return { code: "share_exceeds_parent", max: parentShare };
|
||||
}
|
||||
} else if (!input.usesRelativeShare && shareRate > AGENT_PERCENT_HARD_MAX) {
|
||||
return { code: "share_range" };
|
||||
}
|
||||
|
||||
if (input.validateCredit) {
|
||||
if (Number.isNaN(creditLimit) || creditLimit < 0 || !Number.isInteger(creditLimit)) {
|
||||
return { code: "credit_invalid" };
|
||||
}
|
||||
|
||||
const maxCredit = maxCreditLimitFromParent(input.parentCaps, input.baselineCreditLimit);
|
||||
if (maxCredit !== undefined && creditLimit > maxCredit) {
|
||||
return { code: "credit_exceeds_parent", max: maxCredit };
|
||||
}
|
||||
|
||||
if (creditLimit < input.minCreditLimit) {
|
||||
return { code: "credit_below_allocated", min: input.minCreditLimit };
|
||||
}
|
||||
}
|
||||
|
||||
if (rebateLimit === null || rebateLimit < 0 || rebateLimit > AGENT_PERCENT_HARD_MAX) {
|
||||
return { code: "rebate_limit_range" };
|
||||
}
|
||||
|
||||
if (defaultRebate === null || defaultRebate < 0 || defaultRebate > AGENT_PERCENT_HARD_MAX) {
|
||||
return { code: "default_rebate_range" };
|
||||
}
|
||||
|
||||
const parentRebateMax = maxRebatePercentFromParent(input.parentCaps);
|
||||
if (rebateLimit > parentRebateMax) {
|
||||
return { code: "rebate_exceeds_parent", max: parentRebateMax };
|
||||
}
|
||||
|
||||
const defaultCap = maxDefaultRebatePercent(input.rebateLimitText, input.parentCaps);
|
||||
if (defaultRebate > defaultCap) {
|
||||
return { code: "default_exceeds_limit", max: defaultCap };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function isNumericStepperOutOfRange(
|
||||
value: string,
|
||||
options: { min?: number; max?: number; integer?: boolean },
|
||||
): boolean {
|
||||
const trimmed = value.trim();
|
||||
if (trimmed === "") {
|
||||
return false;
|
||||
}
|
||||
|
||||
const parsed = options.integer
|
||||
? Number.parseInt(trimmed, 10)
|
||||
: Number.parseFloat(trimmed);
|
||||
if (!Number.isFinite(parsed)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (options.min !== undefined && parsed < options.min) {
|
||||
return true;
|
||||
}
|
||||
if (options.max !== undefined && parsed > options.max) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import type { ComponentType } from "react";
|
||||
import { ChevronRight, Network, Pencil, Plus, Trash2, Users } from "lucide-react";
|
||||
import { Pencil, Plus, Trash2, Network } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { AdminSubnav, AdminSubnavButton } from "@/components/admin/admin-subnav";
|
||||
@@ -22,9 +21,10 @@ import { AgentProfileFields, type AgentProfileFieldsProps } from "@/modules/agen
|
||||
import { formatCredit } from "@/modules/agents/agent-line-sidebar";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { percentValueToUi } from "@/lib/admin-rate-percent";
|
||||
import { isLineRootAgentNode } from "@/lib/agent-profile-caps";
|
||||
import { resolveRoleStatusTone } from "@/lib/admin-status-tone";
|
||||
import { cn } from "@/lib/utils";
|
||||
import type { AgentNodeProfileSummary, AgentNodeRow, AgentProfileRow } from "@/types/api/admin-agent";
|
||||
import type { AgentNodeRow, AgentProfileRow } from "@/types/api/admin-agent";
|
||||
|
||||
function relativeShareRate(totalShareRate: number | undefined, parentShareRate: number | undefined): string | null {
|
||||
if (
|
||||
@@ -254,12 +254,6 @@ export function AgentLineDetailPanel({
|
||||
profile={profile}
|
||||
profileLoading={profileLoading}
|
||||
profileReadOnly={profileReadOnly}
|
||||
canViewDownlineTab={canViewDownlineTab}
|
||||
canViewPlayersTab={canViewPlayersTab}
|
||||
playersTabHint={playersTabHint}
|
||||
childCount={childAgents.length}
|
||||
onGoToDownline={() => onDetailTabChange("downline")}
|
||||
onGoToPlayers={() => onDetailTabChange("players")}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
@@ -273,9 +267,14 @@ export function AgentLineDetailPanel({
|
||||
</CardTitle>
|
||||
<p className="text-sm font-normal text-muted-foreground">
|
||||
{profileReadOnly
|
||||
? t("lineUi.profileReadOnlyHint", {
|
||||
defaultValue: "占成、授信与回水由上级配置,如需调整请联系上级代理或平台。",
|
||||
})
|
||||
? isLineRootAgentNode(node)
|
||||
? t("lineUi.lineRootProfileReadOnlyHint", {
|
||||
defaultValue:
|
||||
"一级代理的占成、站点授信总额与回水由平台超管配置;您可向直属下级代理与玩家下放额度。",
|
||||
})
|
||||
: t("lineUi.profileReadOnlyHint", {
|
||||
defaultValue: "占成、授信与回水由上级配置,如需调整请联系上级代理或平台。",
|
||||
})
|
||||
: t("lineUi.profileTabHint", {
|
||||
defaultValue:
|
||||
"占成、授信、回水与风控标签在此维护;登录名、密码与启停状态请用「编辑代理」。",
|
||||
@@ -321,7 +320,7 @@ export function AgentLineDetailPanel({
|
||||
<AgentsPlayersPanel
|
||||
siteCode={siteCode}
|
||||
agentNodeId={node.id}
|
||||
allowCreatePlayer={profile?.can_create_player === true}
|
||||
allowCreatePlayer={canCreatePlayerAction}
|
||||
embedded
|
||||
createRequestKey={playerCreateRequestKey}
|
||||
/>
|
||||
@@ -335,22 +334,10 @@ function OverviewTab({
|
||||
profile,
|
||||
profileLoading,
|
||||
profileReadOnly,
|
||||
canViewDownlineTab,
|
||||
canViewPlayersTab,
|
||||
playersTabHint,
|
||||
childCount,
|
||||
onGoToDownline,
|
||||
onGoToPlayers,
|
||||
}: {
|
||||
profile: AgentProfileRow | null;
|
||||
profileLoading: boolean;
|
||||
profileReadOnly: boolean;
|
||||
canViewDownlineTab: boolean;
|
||||
canViewPlayersTab: boolean;
|
||||
playersTabHint?: string | null;
|
||||
childCount: number;
|
||||
onGoToDownline: () => void;
|
||||
onGoToPlayers: () => void;
|
||||
}): React.ReactElement {
|
||||
const { t } = useTranslation(["agents", "common"]);
|
||||
|
||||
@@ -361,197 +348,119 @@ function OverviewTab({
|
||||
profile?.parent_caps?.total_share_rate,
|
||||
);
|
||||
|
||||
const yesLabel = t("common:states.yes", { defaultValue: "是" });
|
||||
const noLabel = t("common:states.no", { defaultValue: "否" });
|
||||
|
||||
return (
|
||||
<div className="mx-auto max-w-5xl space-y-6">
|
||||
{profileReadOnly ? (
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-3">
|
||||
<MetricCard
|
||||
label={t("profile.creditLimit", { defaultValue: "授信额度" })}
|
||||
value={profileLoading ? "…" : formatCredit(profile?.credit_limit ?? 0)}
|
||||
/>
|
||||
<MetricCard
|
||||
label={t("lineUi.allocatedCredit", { defaultValue: "已下发" })}
|
||||
value={profileLoading ? "…" : formatCredit(profile?.allocated_credit ?? 0)}
|
||||
/>
|
||||
<MetricCard
|
||||
label={t("lineUi.availableCredit", { defaultValue: "可下发" })}
|
||||
value={profileLoading ? "…" : formatCredit(profile?.available_credit ?? 0)}
|
||||
highlight
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-2 gap-3 lg:grid-cols-4">
|
||||
<MetricCard
|
||||
label={t("profile.totalShareRate", { defaultValue: "占成比例" })}
|
||||
value={profileLoading ? "…" : `${profile?.total_share_rate ?? 0}%`}
|
||||
subtitle={
|
||||
parentRelativeShare
|
||||
? t("profile.relativeShareRateValue", {
|
||||
defaultValue: "占上级 {{rate}}%",
|
||||
rate: parentRelativeShare,
|
||||
})
|
||||
: rebateCap !== null
|
||||
? t("lineUi.shareRebateCap", {
|
||||
defaultValue: "回水上限 {{rate}}%",
|
||||
rate: rebateCap,
|
||||
})
|
||||
: undefined
|
||||
}
|
||||
accent
|
||||
/>
|
||||
<MetricCard
|
||||
label={t("profile.creditLimit", { defaultValue: "授信额度" })}
|
||||
value={profileLoading ? "…" : formatCredit(profile?.credit_limit ?? 0)}
|
||||
/>
|
||||
<MetricCard
|
||||
label={t("lineUi.allocatedCredit", { defaultValue: "已下发" })}
|
||||
value={profileLoading ? "…" : formatCredit(profile?.allocated_credit ?? 0)}
|
||||
/>
|
||||
<MetricCard
|
||||
label={t("lineUi.availableCredit", { defaultValue: "可下发" })}
|
||||
value={profileLoading ? "…" : formatCredit(profile?.available_credit ?? 0)}
|
||||
highlight
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!profileReadOnly && !profileLoading && profile ? (
|
||||
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
||||
<MetricCard
|
||||
label={t("profile.rebateLimit", { defaultValue: "回水上限 (%)" })}
|
||||
value={`${percentValueToUi(profile.rebate_limit ?? 0)}%`}
|
||||
/>
|
||||
<MetricCard
|
||||
label={t("profile.defaultPlayerRebate", { defaultValue: "默认玩家回水 (%)" })}
|
||||
value={`${percentValueToUi(profile.default_player_rebate ?? 0)}%`}
|
||||
/>
|
||||
<MetricCard
|
||||
label={t("profile.riskTags", { defaultValue: "风控标签" })}
|
||||
value={
|
||||
(profile.risk_tags?.length ?? 0) > 0
|
||||
? profile.risk_tags!.join(", ")
|
||||
: t("common:states.none", { defaultValue: "无" })
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{profileReadOnly ? (
|
||||
<p className="rounded-lg border border-border/60 bg-card px-4 py-3 text-sm text-muted-foreground">
|
||||
{t("lineUi.selfAgentOverviewHint", {
|
||||
defaultValue:
|
||||
"以下为上级为您分配的授信额度,占成与回水由上级在后台维护,本账号不可查看或修改。",
|
||||
"以下为上级为您分配的占成与授信;如需调整请联系上级代理或平台。",
|
||||
})}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
{canViewDownlineTab || canViewPlayersTab || playersTabHint ? (
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
{canViewDownlineTab ? (
|
||||
<OverviewLinkCard
|
||||
icon={Network}
|
||||
title={t("lineUi.tabDownline", { defaultValue: "直属下级" })}
|
||||
summary={t("lineUi.overviewDownlineCount", {
|
||||
defaultValue: "{{count}} 个",
|
||||
count: childCount,
|
||||
})}
|
||||
description={t("lineUi.overviewDownlineHint", {
|
||||
defaultValue: "直属下级 {{count}} 个,可在对应 Tab 管理下级代理。",
|
||||
count: childCount,
|
||||
})}
|
||||
actionLabel={t("lineUi.viewDownline", { defaultValue: "查看直属下级" })}
|
||||
onAction={onGoToDownline}
|
||||
<div className="grid grid-cols-2 gap-3 lg:grid-cols-4">
|
||||
<MetricCard
|
||||
label={t("profile.totalShareRate", { defaultValue: "占成比例" })}
|
||||
value={profileLoading ? "…" : `${profile?.total_share_rate ?? 0}%`}
|
||||
subtitle={
|
||||
parentRelativeShare
|
||||
? t("profile.relativeShareRateValue", {
|
||||
defaultValue: "占上级 {{rate}}%",
|
||||
rate: parentRelativeShare,
|
||||
})
|
||||
: undefined
|
||||
}
|
||||
accent
|
||||
/>
|
||||
<MetricCard
|
||||
label={t("profile.creditLimit", { defaultValue: "授信额度" })}
|
||||
value={profileLoading ? "…" : formatCredit(profile?.credit_limit ?? 0)}
|
||||
/>
|
||||
<MetricCard
|
||||
label={t("lineUi.allocatedCredit", { defaultValue: "已下发" })}
|
||||
value={profileLoading ? "…" : formatCredit(profile?.allocated_credit ?? 0)}
|
||||
/>
|
||||
<MetricCard
|
||||
label={t("lineUi.availableCredit", { defaultValue: "可下发" })}
|
||||
value={profileLoading ? "…" : formatCredit(profile?.available_credit ?? 0)}
|
||||
highlight
|
||||
/>
|
||||
</div>
|
||||
|
||||
{!profileLoading && profile ? (
|
||||
<>
|
||||
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
||||
<MetricCard
|
||||
label={t("profile.rebateLimit", { defaultValue: "回水上限 (%)" })}
|
||||
value={`${rebateCap ?? "0"}%`}
|
||||
/>
|
||||
) : null}
|
||||
{canViewPlayersTab ? (
|
||||
<OverviewLinkCard
|
||||
icon={Users}
|
||||
title={t("lineUi.tabPlayers", { defaultValue: "直属玩家" })}
|
||||
summary={t("lineUi.overviewPlayersSummary", {
|
||||
defaultValue: "玩家管理",
|
||||
})}
|
||||
description={t("lineUi.overviewPlayersHint", {
|
||||
defaultValue: "直属玩家请在「直属玩家」Tab 维护。",
|
||||
})}
|
||||
actionLabel={t("lineUi.viewPlayers", { defaultValue: "查看直属玩家" })}
|
||||
onAction={onGoToPlayers}
|
||||
<MetricCard
|
||||
label={t("profile.defaultPlayerRebate", { defaultValue: "默认玩家回水 (%)" })}
|
||||
value={`${percentValueToUi(profile.default_player_rebate ?? 0)}%`}
|
||||
/>
|
||||
) : null}
|
||||
{!canViewPlayersTab && playersTabHint ? (
|
||||
<Card className="border-border/70 shadow-sm">
|
||||
<CardContent className="flex items-start gap-3 pt-5">
|
||||
<div className="flex size-10 shrink-0 items-center justify-center rounded-xl bg-muted text-muted-foreground">
|
||||
<Users className="size-5" aria-hidden />
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<p className="font-medium text-foreground">
|
||||
{t("lineUi.tabPlayers", { defaultValue: "直属玩家" })}
|
||||
</p>
|
||||
<p className="mt-1 text-sm text-muted-foreground">{playersTabHint}</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : null}
|
||||
</div>
|
||||
<MetricCard
|
||||
label={t("profile.riskTags", { defaultValue: "风控标签" })}
|
||||
value={
|
||||
(profile.risk_tags?.length ?? 0) > 0
|
||||
? profile.risk_tags!.join(", ")
|
||||
: t("common:states.none", { defaultValue: "无" })
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-3 sm:grid-cols-3">
|
||||
<CapabilityMetric
|
||||
label={t("profile.canGrantExtraRebate", { defaultValue: "允许额外回水" })}
|
||||
enabled={profile.can_grant_extra_rebate === true}
|
||||
yesLabel={yesLabel}
|
||||
noLabel={noLabel}
|
||||
/>
|
||||
<CapabilityMetric
|
||||
label={t("profile.canCreatePlayer", { defaultValue: "允许创建玩家" })}
|
||||
enabled={profile.can_create_player !== false}
|
||||
yesLabel={yesLabel}
|
||||
noLabel={noLabel}
|
||||
/>
|
||||
<CapabilityMetric
|
||||
label={t("profile.canCreateChildAgent", { defaultValue: "允许创建下级代理" })}
|
||||
enabled={profile.can_create_child_agent === true}
|
||||
yesLabel={yesLabel}
|
||||
noLabel={noLabel}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function OverviewLinkCard({
|
||||
icon: Icon,
|
||||
title,
|
||||
summary,
|
||||
description,
|
||||
actionLabel,
|
||||
onAction,
|
||||
function CapabilityMetric({
|
||||
label,
|
||||
enabled,
|
||||
yesLabel,
|
||||
noLabel,
|
||||
}: {
|
||||
icon: ComponentType<{ className?: string }>;
|
||||
title: string;
|
||||
summary: string;
|
||||
description: string;
|
||||
actionLabel: string;
|
||||
onAction: () => void;
|
||||
label: string;
|
||||
enabled: boolean;
|
||||
yesLabel: string;
|
||||
noLabel: string;
|
||||
}): React.ReactElement {
|
||||
return (
|
||||
<Card
|
||||
className="group relative cursor-pointer overflow-hidden border-border/70 shadow-sm transition-all hover:border-primary/40 hover:shadow-md"
|
||||
onClick={onAction}
|
||||
>
|
||||
<CardContent className="flex flex-col p-5">
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex size-11 shrink-0 items-center justify-center rounded-xl bg-primary/10 text-primary transition-colors group-hover:bg-primary group-hover:text-primary-foreground">
|
||||
<Icon className="size-5.5" aria-hidden />
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="shrink-0 text-primary -mr-2"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onAction();
|
||||
}}
|
||||
>
|
||||
{actionLabel}
|
||||
<ChevronRight className="ml-0.5 size-4" aria-hidden />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="mt-4">
|
||||
<p className="text-sm font-medium text-muted-foreground">{title}</p>
|
||||
<p className={cn(
|
||||
"mt-1 font-semibold tracking-tight text-foreground",
|
||||
summary.length > 5 ? "text-xl" : "text-2xl tabular-nums"
|
||||
)}>
|
||||
{summary}
|
||||
</p>
|
||||
<p className="mt-2 text-sm leading-relaxed text-muted-foreground">
|
||||
{description}
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<div className="rounded-xl border border-border/70 bg-card px-4 py-4 shadow-sm">
|
||||
<p className="text-xs font-medium text-muted-foreground">{label}</p>
|
||||
<p
|
||||
className={cn(
|
||||
"mt-1.5 text-lg font-semibold",
|
||||
enabled ? "text-foreground" : "text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{enabled ? yesLabel : noLabel}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,10 @@ import {
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { useAsyncEffect } from "@/hooks/use-async-effect";
|
||||
import { adminSiteCodeLabel } from "@/lib/admin-select-display";
|
||||
import {
|
||||
validateAdminLoginAccount,
|
||||
validateAdminPassword,
|
||||
} from "@/lib/admin-input-validation";
|
||||
import { LotteryApiBizError } from "@/types/api/errors";
|
||||
import type { AdminIntegrationSiteRow } from "@/types/api/admin-integration-site";
|
||||
import type { AdminAgentLineProvisionResult } from "@/types/api/admin-agent-line";
|
||||
@@ -90,11 +94,21 @@ export function AgentLineProvisionWizard({
|
||||
toast.error(t("agents:usernameRequired", { defaultValue: "请填写登录名" }));
|
||||
return;
|
||||
}
|
||||
const usernameIssue = validateAdminLoginAccount(form.username);
|
||||
if (usernameIssue === "invalid_charset") {
|
||||
toast.error(
|
||||
t("agents:usernameInvalidCharset", {
|
||||
defaultValue: "登录名只能使用字母、数字、点(.)、下划线和连字符",
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!form.password.trim()) {
|
||||
toast.error(t("agents:passwordRequired", { defaultValue: "请填写密码" }));
|
||||
return;
|
||||
}
|
||||
if (form.password.trim().length < 8) {
|
||||
const passwordIssue = validateAdminPassword(form.password);
|
||||
if (passwordIssue === "too_short") {
|
||||
toast.error(t("agents:passwordMinLength", { defaultValue: "密码至少 8 位" }));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,17 @@ import type { AgentParentCaps } from "@/types/api/admin-agent";
|
||||
|
||||
import { Info } from "lucide-react";
|
||||
|
||||
import { AdminNumericStepper } from "@/components/admin/admin-numeric-stepper";
|
||||
import { AdminStatusBadge } from "@/components/admin/admin-status-badge";
|
||||
import {
|
||||
AGENT_PERCENT_HARD_MAX,
|
||||
actualShareRateFromRelative,
|
||||
isNumericStepperOutOfRange,
|
||||
maxCreditLimitFromParent,
|
||||
maxDefaultRebatePercent,
|
||||
maxRebatePercentFromParent,
|
||||
} from "@/lib/agent-profile-caps";
|
||||
|
||||
export type AgentProfileFieldsProps = {
|
||||
disabled?: boolean;
|
||||
loading?: boolean;
|
||||
@@ -43,6 +54,12 @@ export type AgentProfileFieldsProps = {
|
||||
onRiskTagsChange: (value: string) => void;
|
||||
idPrefix?: string;
|
||||
currencyCode?: string;
|
||||
/** 打开表单时的授信 baseline,用于计算相对上级的上调空间 */
|
||||
baselineCreditLimit?: number;
|
||||
/** 已下发额度下限(编辑时不可低于 allocated) */
|
||||
minCreditLimit?: number;
|
||||
/** 一级代理占成/授信/回水仅超管可改(false 时整表只读) */
|
||||
profileScalarsEditable?: boolean;
|
||||
/** card:用于代理线路详情 Tab 内的卡片表单 */
|
||||
variant?: "default" | "card";
|
||||
};
|
||||
@@ -72,12 +89,22 @@ export function AgentProfileFields({
|
||||
onRiskTagsChange,
|
||||
idPrefix = "agent-profile",
|
||||
currencyCode = "NPR",
|
||||
baselineCreditLimit = 0,
|
||||
minCreditLimit = 0,
|
||||
profileScalarsEditable = true,
|
||||
variant = "default",
|
||||
}: AgentProfileFieldsProps): React.ReactElement {
|
||||
const { t } = useTranslation(["agents", "common"]);
|
||||
const fieldDisabled = disabled || loading;
|
||||
const showReadOnlyDisplay = !loading && (!profileScalarsEditable || fieldDisabled);
|
||||
const isCard = variant === "card";
|
||||
|
||||
const maxSharePercent = AGENT_PERCENT_HARD_MAX;
|
||||
const maxRebatePercent = maxRebatePercentFromParent(parentCaps);
|
||||
const maxDefaultRebate = maxDefaultRebatePercent(rebateLimit, parentCaps);
|
||||
const maxCreditLimit = maxCreditLimitFromParent(parentCaps, baselineCreditLimit);
|
||||
const actualShare = actualShareRateFromRelative(Number.parseFloat(shareRate) || 0, parentCaps);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{(parentCaps || availableCredit !== null) && !loading ? (
|
||||
@@ -113,122 +140,243 @@ export function AgentProfileFields({
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div
|
||||
className={cn(
|
||||
"grid gap-x-6 gap-y-5 sm:grid-cols-2",
|
||||
fieldDisabled ? "pointer-events-none opacity-50" : "",
|
||||
)}
|
||||
>
|
||||
{!profileScalarsEditable && !loading ? (
|
||||
<p className="rounded-lg border border-amber-200/80 bg-amber-50 px-3 py-2.5 text-sm text-amber-950 dark:border-amber-900/50 dark:bg-amber-950/40 dark:text-amber-100">
|
||||
{t("profile.lineRootScalarsReadOnlyHint", {
|
||||
defaultValue:
|
||||
"一级代理的占成、站点授信总额与回水由平台超管配置;如需调整请联系平台管理员。",
|
||||
})}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div className="grid gap-x-6 gap-y-5 sm:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor={`${idPrefix}-share-rate`} className="text-muted-foreground">
|
||||
<Label
|
||||
htmlFor={`${idPrefix}-share-rate`}
|
||||
className={showReadOnlyDisplay ? "text-foreground/85" : "text-muted-foreground"}
|
||||
>
|
||||
{parentCaps
|
||||
? t("profile.relativeShareRate", { defaultValue: "占成比例(占上级 %)" })
|
||||
: t("profile.totalShareRate", { defaultValue: "占成比例 (%)" })}
|
||||
</Label>
|
||||
<Input
|
||||
id={`${idPrefix}-share-rate`}
|
||||
type="number"
|
||||
min={0}
|
||||
max={100}
|
||||
step="0.01"
|
||||
className="h-10 bg-background/50 transition-colors focus:bg-background"
|
||||
value={shareRate}
|
||||
onChange={(e) => onShareRateChange(e.target.value)}
|
||||
/>
|
||||
{parentCaps && shareRate ? (
|
||||
{showReadOnlyDisplay ? (
|
||||
<ReadOnlyScalar id={`${idPrefix}-share-rate`} value={shareRate} suffix="%" />
|
||||
) : (
|
||||
<AdminNumericStepper
|
||||
id={`${idPrefix}-share-rate`}
|
||||
value={shareRate}
|
||||
onValueChange={onShareRateChange}
|
||||
min={0}
|
||||
max={maxSharePercent}
|
||||
step={0.5}
|
||||
suffix="%"
|
||||
preserveOverMaxOnBlur
|
||||
/>
|
||||
)}
|
||||
{parentCaps ? (
|
||||
<p className="text-xs text-muted-foreground/80">
|
||||
{t("profile.relativeShareCapHint", {
|
||||
defaultValue: "占上级比例最高 100%(上级总占成 {{parent}}%)",
|
||||
parent: parentCaps.total_share_rate,
|
||||
})}
|
||||
</p>
|
||||
) : (
|
||||
<p className="text-xs text-muted-foreground/80">
|
||||
{t("profile.totalShareCapHint", { defaultValue: "占成比例最高 100%" })}
|
||||
</p>
|
||||
)}
|
||||
{parentCaps && shareRate && actualShare !== null ? (
|
||||
<p className="text-xs text-muted-foreground/80">
|
||||
{t("profile.actualShareRate", {
|
||||
defaultValue: "实际占成 {{rate}}%",
|
||||
rate: Number((Number(parentCaps.total_share_rate) * Number(shareRate) / 100).toFixed(2)),
|
||||
rate: actualShare,
|
||||
})}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor={`${idPrefix}-credit-limit`} className="text-muted-foreground">
|
||||
<Label
|
||||
htmlFor={`${idPrefix}-credit-limit`}
|
||||
className={showReadOnlyDisplay ? "text-foreground/85" : "text-muted-foreground"}
|
||||
>
|
||||
{t("profile.creditLimit", { defaultValue: "授信额度" })}
|
||||
</Label>
|
||||
<Input
|
||||
id={`${idPrefix}-credit-limit`}
|
||||
type="number"
|
||||
min={0}
|
||||
className="h-10 bg-background/50 transition-colors focus:bg-background"
|
||||
value={creditLimit}
|
||||
onChange={(e) => onCreditLimitChange(e.target.value)}
|
||||
/>
|
||||
{showReadOnlyDisplay ? (
|
||||
<ReadOnlyScalar id={`${idPrefix}-credit-limit`} value={creditLimit} />
|
||||
) : (
|
||||
<AdminNumericStepper
|
||||
id={`${idPrefix}-credit-limit`}
|
||||
value={creditLimit}
|
||||
onValueChange={onCreditLimitChange}
|
||||
min={minCreditLimit}
|
||||
max={maxCreditLimit}
|
||||
step={1000}
|
||||
integer
|
||||
preserveOverMaxOnBlur
|
||||
/>
|
||||
)}
|
||||
{parentCaps && maxCreditLimit !== undefined && profileScalarsEditable ? (
|
||||
<p className="text-xs text-muted-foreground/80">
|
||||
{t("profile.creditParentCapHint", {
|
||||
defaultValue: "最高 {{max}}(上级可再下发 {{available}})",
|
||||
max: formatAdminCreditMajorDecimal(maxCreditLimit, currencyCode),
|
||||
available: formatAdminCreditMajorDecimal(parentCaps.available_credit, currencyCode),
|
||||
})}
|
||||
</p>
|
||||
) : null}
|
||||
{profileScalarsEditable &&
|
||||
isNumericStepperOutOfRange(creditLimit, {
|
||||
min: minCreditLimit,
|
||||
max: maxCreditLimit,
|
||||
integer: true,
|
||||
}) ? (
|
||||
<p className="text-xs text-destructive">
|
||||
{t("profile.validation.creditExceedsParentWithMax", {
|
||||
defaultValue: "授信额度不能超过 {{max}}",
|
||||
max:
|
||||
maxCreditLimit !== undefined
|
||||
? formatAdminCreditMajorDecimal(maxCreditLimit, currencyCode)
|
||||
: creditLimit,
|
||||
})}
|
||||
</p>
|
||||
) : null}
|
||||
{minCreditLimit > 0 ? (
|
||||
<p className="text-xs text-muted-foreground/80">
|
||||
{t("profile.creditAllocatedFloorHint", {
|
||||
defaultValue: "不可低于已下发 {{amount}}",
|
||||
amount: formatAdminCreditMajorDecimal(minCreditLimit, currencyCode),
|
||||
})}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor={`${idPrefix}-rebate-limit`} className="text-muted-foreground">
|
||||
<Label
|
||||
htmlFor={`${idPrefix}-rebate-limit`}
|
||||
className={showReadOnlyDisplay ? "text-foreground/85" : "text-muted-foreground"}
|
||||
>
|
||||
{t("profile.rebateLimit", { defaultValue: "回水上限 (%)" })}
|
||||
</Label>
|
||||
<Input
|
||||
id={`${idPrefix}-rebate-limit`}
|
||||
type="number"
|
||||
min={0}
|
||||
max={100}
|
||||
step="0.01"
|
||||
className="h-10 bg-background/50 transition-colors focus:bg-background"
|
||||
value={rebateLimit}
|
||||
onChange={(e) => onRebateLimitChange(e.target.value)}
|
||||
placeholder="50"
|
||||
/>
|
||||
{showReadOnlyDisplay ? (
|
||||
<ReadOnlyScalar id={`${idPrefix}-rebate-limit`} value={rebateLimit} suffix="%" />
|
||||
) : (
|
||||
<AdminNumericStepper
|
||||
id={`${idPrefix}-rebate-limit`}
|
||||
value={rebateLimit}
|
||||
onValueChange={onRebateLimitChange}
|
||||
min={0}
|
||||
max={maxRebatePercent}
|
||||
step={0.5}
|
||||
suffix="%"
|
||||
preserveOverMaxOnBlur
|
||||
/>
|
||||
)}
|
||||
{parentCaps ? (
|
||||
<p className="text-xs text-muted-foreground/80">
|
||||
{t("profile.rebateParentCapHint", {
|
||||
defaultValue: "不得超过上级回水上限 {{max}}%",
|
||||
max: maxRebatePercent,
|
||||
})}
|
||||
</p>
|
||||
) : (
|
||||
<p className="text-xs text-muted-foreground/80">
|
||||
{t("profile.rebateHardCapHint", { defaultValue: "回水上限最高 100%" })}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor={`${idPrefix}-default-rebate`} className="text-muted-foreground">
|
||||
<Label
|
||||
htmlFor={`${idPrefix}-default-rebate`}
|
||||
className={showReadOnlyDisplay ? "text-foreground/85" : "text-muted-foreground"}
|
||||
>
|
||||
{t("profile.defaultPlayerRebate", { defaultValue: "默认玩家回水 (%)" })}
|
||||
</Label>
|
||||
<Input
|
||||
id={`${idPrefix}-default-rebate`}
|
||||
type="number"
|
||||
min={0}
|
||||
max={100}
|
||||
step="0.01"
|
||||
className="h-10 bg-background/50 transition-colors focus:bg-background"
|
||||
value={defaultRebate}
|
||||
onChange={(e) => onDefaultRebateChange(e.target.value)}
|
||||
placeholder="50"
|
||||
/>
|
||||
{showReadOnlyDisplay ? (
|
||||
<ReadOnlyScalar id={`${idPrefix}-default-rebate`} value={defaultRebate} suffix="%" />
|
||||
) : (
|
||||
<AdminNumericStepper
|
||||
id={`${idPrefix}-default-rebate`}
|
||||
value={defaultRebate}
|
||||
onValueChange={onDefaultRebateChange}
|
||||
min={0}
|
||||
max={maxDefaultRebate}
|
||||
step={0.5}
|
||||
suffix="%"
|
||||
preserveOverMaxOnBlur
|
||||
/>
|
||||
)}
|
||||
<p className="text-xs text-muted-foreground/80">
|
||||
{t("profile.defaultRebateCapHint", {
|
||||
defaultValue: "不得超过本节点回水上限 {{max}}%",
|
||||
max: maxDefaultRebate,
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
<div className="space-y-2 sm:col-span-2">
|
||||
<Label htmlFor={`${idPrefix}-risk-tags`} className="text-muted-foreground">
|
||||
<Label
|
||||
htmlFor={`${idPrefix}-risk-tags`}
|
||||
className={showReadOnlyDisplay ? "text-foreground/85" : "text-muted-foreground"}
|
||||
>
|
||||
{t("profile.riskTags", { defaultValue: "风控标签" })}
|
||||
</Label>
|
||||
<Input
|
||||
id={`${idPrefix}-risk-tags`}
|
||||
className="h-10 bg-background/50 transition-colors focus:bg-background"
|
||||
value={riskTags}
|
||||
onChange={(e) => onRiskTagsChange(e.target.value)}
|
||||
placeholder={t("profile.riskTagsPlaceholder", {
|
||||
defaultValue: "逗号分隔,如 overdue, high_turnover",
|
||||
})}
|
||||
/>
|
||||
{showReadOnlyDisplay ? (
|
||||
<ReadOnlyScalar
|
||||
id={`${idPrefix}-risk-tags`}
|
||||
value={riskTags.trim() === "" ? "—" : riskTags}
|
||||
className="justify-start font-normal"
|
||||
/>
|
||||
) : (
|
||||
<Input
|
||||
id={`${idPrefix}-risk-tags`}
|
||||
className="h-10 bg-background/50 transition-colors focus:bg-background"
|
||||
value={riskTags}
|
||||
onChange={(e) => onRiskTagsChange(e.target.value)}
|
||||
placeholder={t("profile.riskTagsPlaceholder", {
|
||||
defaultValue: "逗号分隔,如 overdue, high_turnover",
|
||||
})}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className={cn(
|
||||
"pt-2",
|
||||
fieldDisabled ? "pointer-events-none opacity-50" : "",
|
||||
)}
|
||||
>
|
||||
<div className="rounded-xl border border-border/70 bg-card overflow-hidden shadow-sm">
|
||||
<SwitchRow
|
||||
checked={extraRebate}
|
||||
onCheckedChange={onExtraRebateChange}
|
||||
label={t("profile.canGrantExtraRebate", { defaultValue: "允许额外回水" })}
|
||||
/>
|
||||
<SwitchRow
|
||||
checked={canCreatePlayer}
|
||||
onCheckedChange={onCanCreatePlayerChange}
|
||||
label={t("profile.canCreatePlayer", { defaultValue: "允许创建玩家" })}
|
||||
/>
|
||||
<SwitchRow
|
||||
checked={canCreateChild}
|
||||
onCheckedChange={onCanCreateChildChange}
|
||||
disabled={!canCreateChildAgent && !isSuperAdmin}
|
||||
label={t("profile.canCreateChildAgent", { defaultValue: "允许创建下级代理" })}
|
||||
isLast
|
||||
/>
|
||||
<div className="pt-2">
|
||||
<div className="rounded-xl border border-border/80 bg-muted/20 overflow-hidden shadow-sm">
|
||||
{showReadOnlyDisplay ? (
|
||||
<>
|
||||
<ReadOnlySwitchRow
|
||||
label={t("profile.canGrantExtraRebate", { defaultValue: "允许额外回水" })}
|
||||
checked={extraRebate}
|
||||
/>
|
||||
<ReadOnlySwitchRow
|
||||
label={t("profile.canCreatePlayer", { defaultValue: "允许创建玩家" })}
|
||||
checked={canCreatePlayer}
|
||||
/>
|
||||
<ReadOnlySwitchRow
|
||||
label={t("profile.canCreateChildAgent", { defaultValue: "允许创建下级代理" })}
|
||||
checked={canCreateChild}
|
||||
isLast
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<SwitchRow
|
||||
checked={extraRebate}
|
||||
onCheckedChange={onExtraRebateChange}
|
||||
label={t("profile.canGrantExtraRebate", { defaultValue: "允许额外回水" })}
|
||||
/>
|
||||
<SwitchRow
|
||||
checked={canCreatePlayer}
|
||||
onCheckedChange={onCanCreatePlayerChange}
|
||||
label={t("profile.canCreatePlayer", { defaultValue: "允许创建玩家" })}
|
||||
/>
|
||||
<SwitchRow
|
||||
checked={canCreateChild}
|
||||
onCheckedChange={onCanCreateChildChange}
|
||||
disabled={!canCreateChildAgent && !isSuperAdmin}
|
||||
label={t("profile.canCreateChildAgent", { defaultValue: "允许创建下级代理" })}
|
||||
isLast
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{!isCard ? (
|
||||
<p className="mt-3 px-1 text-xs text-muted-foreground/80">
|
||||
@@ -243,6 +391,61 @@ export function AgentProfileFields({
|
||||
);
|
||||
}
|
||||
|
||||
function ReadOnlyScalar({
|
||||
id,
|
||||
value,
|
||||
suffix,
|
||||
className,
|
||||
}: {
|
||||
id?: string;
|
||||
value: string;
|
||||
suffix?: string;
|
||||
className?: string;
|
||||
}): React.ReactElement {
|
||||
return (
|
||||
<div
|
||||
id={id}
|
||||
className={cn(
|
||||
"flex h-10 items-center justify-center rounded-md border border-border/80 bg-muted/35 px-3 text-sm font-semibold tabular-nums text-foreground shadow-xs",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<span>
|
||||
{value}
|
||||
{suffix ? <span className="ml-0.5 font-medium text-foreground/80">{suffix}</span> : null}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ReadOnlySwitchRow({
|
||||
label,
|
||||
checked,
|
||||
isLast = false,
|
||||
}: {
|
||||
label: string;
|
||||
checked: boolean;
|
||||
isLast?: boolean;
|
||||
}): React.ReactElement {
|
||||
const { t } = useTranslation(["agents", "common"]);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-center justify-between gap-4 bg-background/60 px-4 py-3.5",
|
||||
!isLast && "border-b border-border/60",
|
||||
)}
|
||||
>
|
||||
<span className="font-medium text-foreground">{label}</span>
|
||||
<AdminStatusBadge tone={checked ? "success" : "neutral"}>
|
||||
{checked
|
||||
? t("common:status.enabled", { defaultValue: "已开启" })
|
||||
: t("common:status.disabled", { defaultValue: "已关闭" })}
|
||||
</AdminStatusBadge>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SwitchRow({
|
||||
checked,
|
||||
onCheckedChange,
|
||||
@@ -261,7 +464,12 @@ function SwitchRow({
|
||||
"flex items-center justify-between gap-4 px-4 py-3.5 bg-background/50 transition-colors hover:bg-muted/30",
|
||||
!isLast && "border-b border-border/50"
|
||||
)}>
|
||||
<Label className={cn("font-medium cursor-pointer", disabled && "opacity-50")} onClick={() => !disabled && onCheckedChange(!checked)}>{label}</Label>
|
||||
<Label
|
||||
className={cn("font-medium", disabled ? "cursor-default text-muted-foreground" : "cursor-pointer")}
|
||||
onClick={() => !disabled && onCheckedChange(!checked)}
|
||||
>
|
||||
{label}
|
||||
</Label>
|
||||
<Switch checked={checked} onCheckedChange={onCheckedChange} disabled={disabled} />
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -40,6 +40,16 @@ import {
|
||||
percentValueToUi,
|
||||
parsePercentUi,
|
||||
} from "@/lib/admin-rate-percent";
|
||||
import {
|
||||
isLineRootAgentNode,
|
||||
isRootProfileEditableByActor,
|
||||
validateAgentProfileScalars,
|
||||
type AgentProfileValidationIssue,
|
||||
} from "@/lib/agent-profile-caps";
|
||||
import {
|
||||
validateAdminLoginAccount,
|
||||
validateAdminPassword,
|
||||
} from "@/lib/admin-input-validation";
|
||||
import { adminHasAnyPermission } from "@/lib/admin-permissions";
|
||||
import {
|
||||
PRD_AGENT_MANAGE,
|
||||
@@ -139,6 +149,8 @@ export function AgentsConsole(): React.ReactElement {
|
||||
const [profileLoaded, setProfileLoaded] = useState(true);
|
||||
const [profileParentCaps, setProfileParentCaps] = useState<AgentParentCaps | null>(null);
|
||||
const [profileAvailableCredit, setProfileAvailableCredit] = useState<number | null>(null);
|
||||
const [profileBaselineCreditLimit, setProfileBaselineCreditLimit] = useState(0);
|
||||
const [profileMinCreditLimit, setProfileMinCreditLimit] = useState(0);
|
||||
const [editingNodeNeedsPrimaryAccount, setEditingNodeNeedsPrimaryAccount] = useState(false);
|
||||
|
||||
/** 登录账号是否可向子代理下放「允许创建下级」 */
|
||||
@@ -161,6 +173,8 @@ export function AgentsConsole(): React.ReactElement {
|
||||
setProfileRiskTags("");
|
||||
setProfileParentCaps(null);
|
||||
setProfileAvailableCredit(null);
|
||||
setProfileBaselineCreditLimit(0);
|
||||
setProfileMinCreditLimit(0);
|
||||
};
|
||||
|
||||
const applyProfileRowToForm = (row: AgentProfileRow) => {
|
||||
@@ -179,13 +193,18 @@ export function AgentsConsole(): React.ReactElement {
|
||||
setProfileCanCreatePlayer(row.can_create_player !== false);
|
||||
setProfileParentCaps(row.parent_caps ?? null);
|
||||
setProfileAvailableCredit(row.available_credit ?? null);
|
||||
setProfileBaselineCreditLimit(row.credit_limit ?? 0);
|
||||
setProfileMinCreditLimit(row.allocated_credit ?? 0);
|
||||
setProfileRiskTags((row.risk_tags ?? []).join(", "));
|
||||
};
|
||||
|
||||
const profilePayload = () => {
|
||||
const profilePayload = (creditNode: AgentNodeRow | null = selectedNode) => {
|
||||
const shareRate = Number.parseFloat(profileShareRate) || 0;
|
||||
const creditEditable = isRootProfileEditableByActor(creditNode, isSuperAdmin);
|
||||
const base = {
|
||||
credit_limit: Number.parseInt(profileCreditLimit, 10) || 0,
|
||||
...(creditEditable
|
||||
? { credit_limit: Number.parseInt(profileCreditLimit, 10) || 0 }
|
||||
: {}),
|
||||
rebate_limit: Number.parseFloat(profileRebateLimit) || 0,
|
||||
default_player_rebate: Number.parseFloat(profileDefaultRebate) || 0,
|
||||
can_grant_extra_rebate: profileExtraRebate,
|
||||
@@ -199,40 +218,69 @@ export function AgentsConsole(): React.ReactElement {
|
||||
return { ...base, total_share_rate: shareRate };
|
||||
};
|
||||
|
||||
const validateProfileFields = (): string | null => {
|
||||
const shareRate = Number.parseFloat(profileShareRate);
|
||||
const creditLimit = Number.parseInt(profileCreditLimit, 10);
|
||||
const rebateLimit = parsePercentUi(profileRebateLimit);
|
||||
const defaultRebate = parsePercentUi(profileDefaultRebate);
|
||||
|
||||
if (Number.isNaN(shareRate) || shareRate < 0 || shareRate > 100) {
|
||||
return t("profile.validation.shareRange", {
|
||||
defaultValue: "占成比例须在 0–100 之间",
|
||||
});
|
||||
const profileValidationMessage = (issue: AgentProfileValidationIssue): string => {
|
||||
switch (issue.code) {
|
||||
case "share_range":
|
||||
return t("profile.validation.shareRange", {
|
||||
defaultValue: "占成比例须在 0–100 之间",
|
||||
});
|
||||
case "share_exceeds_parent":
|
||||
return t("profile.validation.shareExceedsParent", {
|
||||
defaultValue: "实际占成不能超过上级(最高 {{max}}%)",
|
||||
max: issue.max,
|
||||
});
|
||||
case "credit_invalid":
|
||||
return t("profile.validation.creditInvalid", {
|
||||
defaultValue: "授信额度须为不小于 0 的整数",
|
||||
});
|
||||
case "credit_exceeds_parent":
|
||||
return t("profile.validation.creditExceedsParentWithMax", {
|
||||
defaultValue: "授信额度不能超过 {{max}}",
|
||||
max: issue.max,
|
||||
});
|
||||
case "credit_below_allocated":
|
||||
return t("profile.validation.creditBelowAllocated", {
|
||||
defaultValue: "授信额度不能低于已下发给下级/玩家的总额(当前至少 {{min}})",
|
||||
min: issue.min,
|
||||
});
|
||||
case "rebate_limit_range":
|
||||
return t("profile.validation.rebateLimitRange", {
|
||||
defaultValue: "回水上限须在 0–100% 之间",
|
||||
});
|
||||
case "default_rebate_range":
|
||||
return t("profile.validation.defaultRebateRange", {
|
||||
defaultValue: "默认玩家回水须在 0–100% 之间",
|
||||
});
|
||||
case "default_exceeds_limit":
|
||||
return t("profile.validation.defaultExceedsLimitWithMax", {
|
||||
defaultValue: "默认玩家回水不能超过 {{max}}%",
|
||||
max: issue.max,
|
||||
});
|
||||
case "rebate_exceeds_parent":
|
||||
return t("profile.validation.rebateExceedsParent", {
|
||||
defaultValue: "回水上限不能超过上级(最高 {{max}}%)",
|
||||
max: issue.max,
|
||||
});
|
||||
default:
|
||||
return t("profile.validation.invalid", { defaultValue: "配置数值不合法" });
|
||||
}
|
||||
};
|
||||
|
||||
if (Number.isNaN(creditLimit) || creditLimit < 0) {
|
||||
return t("profile.validation.creditInvalid", {
|
||||
defaultValue: "授信额度不能为负数",
|
||||
});
|
||||
}
|
||||
const validateProfileFields = (creditNode: AgentNodeRow | null = selectedNode): string | null => {
|
||||
const issue = validateAgentProfileScalars({
|
||||
shareRateText: profileShareRate,
|
||||
creditLimitText: profileCreditLimit,
|
||||
rebateLimitText: profileRebateLimit,
|
||||
defaultRebateText: profileDefaultRebate,
|
||||
parentCaps: profileParentCaps,
|
||||
baselineCreditLimit: profileBaselineCreditLimit,
|
||||
minCreditLimit: profileMinCreditLimit,
|
||||
usesRelativeShare: profileParentCaps !== null,
|
||||
validateCredit: isRootProfileEditableByActor(creditNode, isSuperAdmin),
|
||||
});
|
||||
|
||||
if (rebateLimit === null || rebateLimit < 0 || rebateLimit > 100) {
|
||||
return t("profile.validation.rebateLimitRange", {
|
||||
defaultValue: "回水上限须在 0–100% 之间",
|
||||
});
|
||||
}
|
||||
|
||||
if (defaultRebate === null || defaultRebate < 0 || defaultRebate > 100) {
|
||||
return t("profile.validation.defaultRebateRange", {
|
||||
defaultValue: "默认玩家回水须在 0–100% 之间",
|
||||
});
|
||||
}
|
||||
|
||||
if (rebateLimit > 0 && defaultRebate > rebateLimit) {
|
||||
return t("profile.validation.defaultExceedsLimit", {
|
||||
defaultValue: "默认玩家回水不能超过回水上限",
|
||||
});
|
||||
if (issue !== null) {
|
||||
return profileValidationMessage(issue);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -282,11 +330,29 @@ export function AgentsConsole(): React.ReactElement {
|
||||
[flatNodes, selectedNodeId],
|
||||
);
|
||||
|
||||
const lineRootProfileLocked = useMemo(
|
||||
() => isLineRootAgentNode(selectedNode) && !isSuperAdmin,
|
||||
[isSuperAdmin, selectedNode],
|
||||
);
|
||||
|
||||
const isOwnAgentNode =
|
||||
boundAgent !== null && selectedNodeId !== null && selectedNodeId === boundAgent.id;
|
||||
|
||||
const canViewProfileTab =
|
||||
canManageProfile && selectedNode !== null && !isOwnAgentNode;
|
||||
|
||||
const canEditSelectedProfile =
|
||||
canManageProfile && selectedNode !== null && (isSuperAdmin || !isOwnAgentNode);
|
||||
canViewProfileTab && isRootProfileEditableByActor(selectedNode, isSuperAdmin);
|
||||
|
||||
const editingDialogNode = useMemo(
|
||||
() =>
|
||||
editingNodeId !== null
|
||||
? (flatNodes.find((node) => node.id === editingNodeId) ?? null)
|
||||
: null,
|
||||
[editingNodeId, flatNodes],
|
||||
);
|
||||
|
||||
const dialogProfileEditable = isRootProfileEditableByActor(editingDialogNode, isSuperAdmin);
|
||||
|
||||
const selectedChildAgents = useMemo(() => {
|
||||
if (selectedNode === null) {
|
||||
@@ -390,24 +456,30 @@ export function AgentsConsole(): React.ReactElement {
|
||||
.catch(() => setRootProfile(null));
|
||||
}, [rootNode?.id]);
|
||||
|
||||
/** 仅上级/平台维护下级占成授信;代理查看自己时不展示配置 Tab */
|
||||
const canShowProfileTab = canEditSelectedProfile;
|
||||
/** 代理看自己,或站点方看一级代理:占成授信 Tab 只读 */
|
||||
const profileReadOnly = isOwnAgentNode || lineRootProfileLocked;
|
||||
|
||||
const isSiteAdmin = isSiteAdminOperator(profile);
|
||||
|
||||
const canShowDownlineTab = useMemo(
|
||||
() =>
|
||||
selectedNode !== null &&
|
||||
!selectedProfileLoading &&
|
||||
selectedProfile?.can_create_child_agent === true,
|
||||
[selectedNode, selectedProfile, selectedProfileLoading],
|
||||
(isSiteAdmin ||
|
||||
isSuperAdmin ||
|
||||
selectedProfile?.can_create_child_agent === true),
|
||||
[isSiteAdmin, isSuperAdmin, selectedNode, selectedProfile, selectedProfileLoading],
|
||||
);
|
||||
|
||||
const canShowPlayersTab = useMemo(
|
||||
() =>
|
||||
selectedNode !== null &&
|
||||
!selectedProfileLoading &&
|
||||
selectedProfile?.can_create_player === true &&
|
||||
hasUsersManagePermission,
|
||||
[hasUsersManagePermission, selectedNode, selectedProfile, selectedProfileLoading],
|
||||
hasUsersManagePermission &&
|
||||
(isSiteAdmin ||
|
||||
isSuperAdmin ||
|
||||
selectedProfile?.can_create_player === true),
|
||||
[hasUsersManagePermission, isSiteAdmin, isSuperAdmin, selectedNode, selectedProfile, selectedProfileLoading],
|
||||
);
|
||||
|
||||
const playersTabHint = useMemo(() => {
|
||||
@@ -431,8 +503,12 @@ export function AgentsConsole(): React.ReactElement {
|
||||
}, [hasUsersManagePermission, selectedNode, selectedProfile, selectedProfileLoading, t]);
|
||||
|
||||
const canCreateChildOnSelected = useMemo(
|
||||
() => canManageNode && selectedProfile?.can_create_child_agent === true,
|
||||
[canManageNode, selectedProfile?.can_create_child_agent],
|
||||
() =>
|
||||
canManageNode &&
|
||||
(isSiteAdmin ||
|
||||
isSuperAdmin ||
|
||||
selectedProfile?.can_create_child_agent === true),
|
||||
[canManageNode, isSiteAdmin, isSuperAdmin, selectedProfile?.can_create_child_agent],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -440,7 +516,7 @@ export function AgentsConsole(): React.ReactElement {
|
||||
return;
|
||||
}
|
||||
|
||||
if (detailTab === "profile" && !canShowProfileTab) {
|
||||
if (detailTab === "profile" && !canViewProfileTab) {
|
||||
setDetailTab("overview");
|
||||
} else if (detailTab === "downline" && !canShowDownlineTab) {
|
||||
setDetailTab(canShowPlayersTab ? "players" : "overview");
|
||||
@@ -450,7 +526,7 @@ export function AgentsConsole(): React.ReactElement {
|
||||
}, [
|
||||
canShowDownlineTab,
|
||||
canShowPlayersTab,
|
||||
canShowProfileTab,
|
||||
canViewProfileTab,
|
||||
detailTab,
|
||||
selectedNode,
|
||||
selectedProfileLoading,
|
||||
@@ -618,12 +694,12 @@ export function AgentsConsole(): React.ReactElement {
|
||||
};
|
||||
|
||||
const inlineProfileFields = useMemo(() => {
|
||||
if (!canShowProfileTab) {
|
||||
if (!canViewProfileTab) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
disabled: !canEditSelectedProfile,
|
||||
disabled: profileReadOnly || !canEditSelectedProfile,
|
||||
loading: selectedProfileLoading,
|
||||
parentCaps: profileParentCaps,
|
||||
availableCredit: profileAvailableCredit,
|
||||
@@ -645,18 +721,25 @@ export function AgentsConsole(): React.ReactElement {
|
||||
onCanCreateChildChange: setProfileCanCreateChild,
|
||||
riskTags: profileRiskTags,
|
||||
onRiskTagsChange: setProfileRiskTags,
|
||||
baselineCreditLimit: profileBaselineCreditLimit,
|
||||
minCreditLimit: profileMinCreditLimit,
|
||||
profileScalarsEditable: isRootProfileEditableByActor(selectedNode, isSuperAdmin),
|
||||
};
|
||||
}, [
|
||||
canCreateChildAgent,
|
||||
canEditSelectedProfile,
|
||||
canShowProfileTab,
|
||||
canViewProfileTab,
|
||||
isSuperAdmin,
|
||||
profileReadOnly,
|
||||
selectedNode,
|
||||
profileAvailableCredit,
|
||||
profileCanCreateChild,
|
||||
profileCanCreatePlayer,
|
||||
profileCreditLimit,
|
||||
profileDefaultRebate,
|
||||
profileExtraRebate,
|
||||
profileBaselineCreditLimit,
|
||||
profileMinCreditLimit,
|
||||
profileParentCaps,
|
||||
profileRebateLimit,
|
||||
profileRiskTags,
|
||||
@@ -684,6 +767,16 @@ export function AgentsConsole(): React.ReactElement {
|
||||
return;
|
||||
}
|
||||
|
||||
const usernameIssue = validateAdminLoginAccount(nodeUsername);
|
||||
if (usernameIssue === "invalid_charset") {
|
||||
toast.error(
|
||||
t("usernameInvalidCharset", {
|
||||
defaultValue: "登录名只能使用字母、数字、点(.)、下划线和连字符",
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nodeDialogMode === "create") {
|
||||
if (targetParentId === null) {
|
||||
return;
|
||||
@@ -692,13 +785,17 @@ export function AgentsConsole(): React.ReactElement {
|
||||
toast.error(t("passwordRequired", { defaultValue: "请填写密码" }));
|
||||
return;
|
||||
}
|
||||
if (nodePassword.trim().length < 8) {
|
||||
const passwordIssue = validateAdminPassword(nodePassword);
|
||||
if (passwordIssue === "too_short") {
|
||||
toast.error(t("passwordMinLength", { defaultValue: "密码至少 8 位" }));
|
||||
return;
|
||||
}
|
||||
} else if (nodePassword.trim()) {
|
||||
const passwordIssue = validateAdminPassword(nodePassword);
|
||||
if (passwordIssue === "too_short") {
|
||||
toast.error(t("passwordMinLength", { defaultValue: "密码至少 8 位" }));
|
||||
return;
|
||||
}
|
||||
} else if (nodePassword.trim() && nodePassword.trim().length < 8) {
|
||||
toast.error(t("passwordMinLength", { defaultValue: "密码至少 8 位" }));
|
||||
return;
|
||||
} else if (nodeDialogMode === "edit" && editingNodeNeedsPrimaryAccount && !nodePassword.trim()) {
|
||||
toast.error(
|
||||
t("bindAccountPasswordRequired", {
|
||||
@@ -711,7 +808,9 @@ export function AgentsConsole(): React.ReactElement {
|
||||
const includeProfileInDialog =
|
||||
canManageProfile &&
|
||||
(nodeDialogMode === "create" ||
|
||||
(editingNodeId !== null && boundAgent?.id !== editingNodeId));
|
||||
(editingNodeId !== null &&
|
||||
boundAgent?.id !== editingNodeId &&
|
||||
dialogProfileEditable));
|
||||
|
||||
if (includeProfileInDialog) {
|
||||
if (nodeDialogMode === "edit" && !profileLoaded) {
|
||||
@@ -723,7 +822,7 @@ export function AgentsConsole(): React.ReactElement {
|
||||
return;
|
||||
}
|
||||
|
||||
const profileError = validateProfileFields();
|
||||
const profileError = validateProfileFields(editingDialogNode);
|
||||
if (profileError !== null) {
|
||||
toast.error(profileError);
|
||||
return;
|
||||
@@ -739,7 +838,7 @@ export function AgentsConsole(): React.ReactElement {
|
||||
username: nodeUsername.trim(),
|
||||
password: nodePassword,
|
||||
status: nodeStatus,
|
||||
...(canManageProfile ? profilePayload() : {}),
|
||||
...(canManageProfile ? profilePayload(null) : {}),
|
||||
});
|
||||
toast.success(t("createSuccess", { name: nodeName.trim() }));
|
||||
} else if (nodeDialogMode === "edit" && editingNodeId !== null) {
|
||||
@@ -752,7 +851,7 @@ export function AgentsConsole(): React.ReactElement {
|
||||
status: nodeStatus,
|
||||
});
|
||||
if (includeProfileInDialog) {
|
||||
await putAgentNodeProfile(editingNodeId, profilePayload());
|
||||
await putAgentNodeProfile(editingNodeId, profilePayload(editingDialogNode));
|
||||
}
|
||||
toast.success(t("updateSuccess", { name: nodeName.trim() }));
|
||||
}
|
||||
@@ -905,9 +1004,9 @@ export function AgentsConsole(): React.ReactElement {
|
||||
}
|
||||
detailTab={detailTab}
|
||||
onDetailTabChange={setDetailTab}
|
||||
canViewProfileTab={canShowProfileTab}
|
||||
canViewProfileTab={canViewProfileTab}
|
||||
canEditProfileTab={canEditSelectedProfile}
|
||||
profileReadOnly={isOwnAgentNode}
|
||||
profileReadOnly={profileReadOnly}
|
||||
canViewDownlineTab={canShowDownlineTab}
|
||||
canViewPlayersTab={canShowPlayersTab}
|
||||
playersTabHint={playersTabHint}
|
||||
@@ -916,6 +1015,7 @@ export function AgentsConsole(): React.ReactElement {
|
||||
canCreateChildAgent={canCreateChildAgent}
|
||||
canCreatePlayerAction={
|
||||
isSuperAdmin ||
|
||||
isSiteAdmin ||
|
||||
(selectedProfile?.can_create_player === true &&
|
||||
adminHasAnyPermission(profile?.permissions, [PRD_USERS_MANAGE]))
|
||||
}
|
||||
@@ -1024,12 +1124,15 @@ export function AgentsConsole(): React.ReactElement {
|
||||
|
||||
{canManageProfile &&
|
||||
(nodeDialogMode === "create" ||
|
||||
(editingNodeId !== null && boundAgent?.id !== editingNodeId)) ? (
|
||||
(editingNodeId !== null &&
|
||||
boundAgent?.id !== editingNodeId &&
|
||||
dialogProfileEditable)) ? (
|
||||
<div className="space-y-4 border-t border-border/60 pt-5 mt-1">
|
||||
<h3 className="text-sm font-semibold tracking-tight">
|
||||
{t("profile.section", { defaultValue: "占成与授信配置" })}
|
||||
</h3>
|
||||
<AgentProfileFields
|
||||
disabled={nodeDialogMode === "edit" && !dialogProfileEditable}
|
||||
loading={profileLoading}
|
||||
parentCaps={profileParentCaps}
|
||||
availableCredit={profileAvailableCredit}
|
||||
@@ -1051,6 +1154,9 @@ export function AgentsConsole(): React.ReactElement {
|
||||
onCanCreateChildChange={setProfileCanCreateChild}
|
||||
riskTags={profileRiskTags}
|
||||
onRiskTagsChange={setProfileRiskTags}
|
||||
baselineCreditLimit={nodeDialogMode === "create" ? 0 : profileBaselineCreditLimit}
|
||||
minCreditLimit={nodeDialogMode === "create" ? 0 : profileMinCreditLimit}
|
||||
profileScalarsEditable={dialogProfileEditable}
|
||||
idPrefix="dialog-agent-profile"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -20,7 +20,8 @@ import {
|
||||
postAdminPlayer,
|
||||
putAdminPlayer,
|
||||
} from "@/api/admin-player";
|
||||
import { formatCredit } from "@/modules/agents/agent-line-sidebar";
|
||||
import { AdminNumericStepper } from "@/components/admin/admin-numeric-stepper";
|
||||
import { PlayerCreditLimitField } from "@/components/admin/player-credit-limit-field";
|
||||
import { AdminRowActionsMenu } from "@/components/admin/admin-row-actions-menu";
|
||||
import { AdminTableNoResourceRow } from "@/components/admin/admin-no-resource-state";
|
||||
import { AdminListPaginationFooter } from "@/components/admin/admin-list-pagination-footer";
|
||||
@@ -55,12 +56,18 @@ import { useAsyncEffect } from "@/hooks/use-async-effect";
|
||||
import { useConfirmAction } from "@/hooks/use-confirm-action";
|
||||
import { useAdminDateTimeFormatter } from "@/hooks/use-admin-datetime-formatter";
|
||||
import { PlayerFundingModeBadge } from "@/components/admin/player-funding-badges";
|
||||
import { formatPlayerCreditAmount, playerBalanceCells } from "@/lib/admin-player-display";
|
||||
import { playerBalanceCells } from "@/lib/admin-player-display";
|
||||
import { formatAdminMinorDecimal, formatAdminMinorUnits, parseAdminMajorToMinor } from "@/lib/money";
|
||||
import { parsePercentUi, percentValueToUi } from "@/lib/admin-rate-percent";
|
||||
import { adminPlayerDetailPath } from "@/lib/admin-player-paths";
|
||||
import { AGENT_PERCENT_HARD_MAX } from "@/lib/agent-profile-caps";
|
||||
import {
|
||||
validateNativePlayerPassword,
|
||||
validateNativePlayerUsername,
|
||||
} from "@/lib/admin-input-validation";
|
||||
import { adminHasAnyPermission } from "@/lib/admin-permissions";
|
||||
import { PRD_USERS_MANAGE } from "@/lib/admin-prd";
|
||||
import { isSiteAdminOperator } from "@/lib/admin-session-variants";
|
||||
import { resolveRoleStatusTone } from "@/lib/admin-status-tone";
|
||||
import { useAdminProfile } from "@/stores/admin-session";
|
||||
import { LotteryApiBizError } from "@/types/api/errors";
|
||||
@@ -86,15 +93,6 @@ function playerStatusLabel(
|
||||
return String(status);
|
||||
}
|
||||
|
||||
function creditAdjustModeLabel(
|
||||
mode: "increase" | "decrease",
|
||||
t: (key: string, opts?: { defaultValue?: string }) => string,
|
||||
): string {
|
||||
return mode === "increase"
|
||||
? t("playersPanel.creditIncrease", { defaultValue: "增加授信" })
|
||||
: t("playersPanel.creditDecrease", { defaultValue: "减少授信" });
|
||||
}
|
||||
|
||||
function resolvePlayerRebateRate(row: AdminPlayerRow): number | null {
|
||||
if (row.rebate_rate != null) {
|
||||
return row.rebate_rate;
|
||||
@@ -171,6 +169,7 @@ export function AgentsPlayersPanel({
|
||||
const profile = useAdminProfile();
|
||||
const boundAgent = profile?.agent ?? null;
|
||||
const isSuperAdmin = profile?.is_super_admin === true;
|
||||
const isSiteAdmin = isSiteAdminOperator(profile);
|
||||
const { request: requestConfirm, ConfirmDialog, busy: confirmBusy } = useConfirmAction();
|
||||
|
||||
const profileAllowsCreate =
|
||||
@@ -206,6 +205,15 @@ export function AgentsPlayersPanel({
|
||||
const [creditLimit, setCreditLimit] = useState("");
|
||||
const [rebateRate, setRebateRate] = useState("");
|
||||
const [parentAvailableCredit, setParentAvailableCredit] = useState<number | null>(null);
|
||||
const [agentRebateLimitPercent, setAgentRebateLimitPercent] = useState<number | null>(null);
|
||||
|
||||
const maxPlayerRebatePercent = useMemo(() => {
|
||||
if (agentRebateLimitPercent === null || !Number.isFinite(agentRebateLimitPercent)) {
|
||||
return AGENT_PERCENT_HARD_MAX;
|
||||
}
|
||||
return Math.min(AGENT_PERCENT_HARD_MAX, Math.max(0, agentRebateLimitPercent));
|
||||
}, [agentRebateLimitPercent]);
|
||||
|
||||
const [editDialogOpen, setEditDialogOpen] = useState(false);
|
||||
const [editSaving, setEditSaving] = useState(false);
|
||||
const [editingPlayer, setEditingPlayer] = useState<Awaited<ReturnType<typeof getAdminPlayers>>["items"][number] | null>(null);
|
||||
@@ -213,9 +221,7 @@ export function AgentsPlayersPanel({
|
||||
const [editNickname, setEditNickname] = useState("");
|
||||
const [editDefaultCurrency, setEditDefaultCurrency] = useState("");
|
||||
const [editStatus, setEditStatus] = useState(0);
|
||||
const [editCreditBase, setEditCreditBase] = useState(0);
|
||||
const [editCreditAdjustMode, setEditCreditAdjustMode] = useState<"increase" | "decrease">("increase");
|
||||
const [editCreditDelta, setEditCreditDelta] = useState("");
|
||||
const [editCreditLimit, setEditCreditLimit] = useState("");
|
||||
const [editRebateRate, setEditRebateRate] = useState("");
|
||||
const [editRiskTags, setEditRiskTags] = useState("");
|
||||
const [editDetailLoading, setEditDetailLoading] = useState(false);
|
||||
@@ -273,9 +279,19 @@ export function AgentsPlayersPanel({
|
||||
toast.error(t("playersPanel.loginRequired", { defaultValue: "请填写登录账号与初始密码" }));
|
||||
return;
|
||||
}
|
||||
if (password.trim().length < 8) {
|
||||
const usernameIssue = validateNativePlayerUsername(username);
|
||||
if (usernameIssue === "invalid_charset") {
|
||||
toast.error(
|
||||
t("playersPanel.passwordMinLength", { defaultValue: "初始密码至少 8 位" }),
|
||||
t("playersPanel.usernameInvalidCharset", {
|
||||
defaultValue: "登录账号只能使用字母、数字、点(.)、下划线和连字符",
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
const passwordIssue = validateNativePlayerPassword(password);
|
||||
if (passwordIssue === "too_short") {
|
||||
toast.error(
|
||||
t("playersPanel.passwordMinLength", { defaultValue: "初始密码至少 6 位" }),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -314,6 +330,16 @@ export function AgentsPlayersPanel({
|
||||
return;
|
||||
}
|
||||
|
||||
if (parsedRebateRate !== null && parsedRebateRate > maxPlayerRebatePercent) {
|
||||
toast.error(
|
||||
t("playersPanel.rebateRateExceedsAgent", {
|
||||
defaultValue: "回水比例不能超过代理回水上限 {{max}}%",
|
||||
max: maxPlayerRebatePercent,
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
setSaving(true);
|
||||
try {
|
||||
await postAdminPlayer({
|
||||
@@ -321,7 +347,9 @@ export function AgentsPlayersPanel({
|
||||
username: username.trim(),
|
||||
password: password,
|
||||
nickname: nickname.trim() || null,
|
||||
...(isSuperAdmin && effectiveAgentId ? { agent_node_id: effectiveAgentId } : {}),
|
||||
...(effectiveAgentId != null && (isSuperAdmin || isSiteAdmin || boundAgent !== null)
|
||||
? { agent_node_id: effectiveAgentId }
|
||||
: {}),
|
||||
credit_limit: parsedCreditLimit,
|
||||
...(parsedRebateRate !== null
|
||||
? { rebate_rate: parsedRebateRate }
|
||||
@@ -356,10 +384,18 @@ export function AgentsPlayersPanel({
|
||||
setRebateRate("");
|
||||
if (effectiveAgentId !== null) {
|
||||
void getAgentNodeProfile(effectiveAgentId)
|
||||
.then((p) => setParentAvailableCredit(p.available_credit ?? null))
|
||||
.catch(() => setParentAvailableCredit(null));
|
||||
.then((p) => {
|
||||
setParentAvailableCredit(p.available_credit ?? null);
|
||||
const rebate = Number(p.rebate_limit);
|
||||
setAgentRebateLimitPercent(Number.isFinite(rebate) ? rebate : null);
|
||||
})
|
||||
.catch(() => {
|
||||
setParentAvailableCredit(null);
|
||||
setAgentRebateLimitPercent(null);
|
||||
});
|
||||
} else {
|
||||
setParentAvailableCredit(null);
|
||||
setAgentRebateLimitPercent(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,9 +415,7 @@ export function AgentsPlayersPanel({
|
||||
setEditNickname(form.nickname);
|
||||
setEditDefaultCurrency(form.currency);
|
||||
setEditStatus(form.status);
|
||||
setEditCreditBase(form.creditLimit);
|
||||
setEditCreditAdjustMode("increase");
|
||||
setEditCreditDelta("");
|
||||
setEditCreditLimit(String(form.creditLimit));
|
||||
setEditRebateRate(form.rebateRate);
|
||||
setEditRiskTags(form.riskTags);
|
||||
};
|
||||
@@ -391,6 +425,18 @@ export function AgentsPlayersPanel({
|
||||
applyEditForm(row);
|
||||
setEditDialogOpen(true);
|
||||
setEditDetailLoading(true);
|
||||
if (effectiveAgentId !== null) {
|
||||
void getAgentNodeProfile(effectiveAgentId)
|
||||
.then((p) => {
|
||||
setParentAvailableCredit(p.available_credit ?? null);
|
||||
const rebate = Number(p.rebate_limit);
|
||||
setAgentRebateLimitPercent(Number.isFinite(rebate) ? rebate : null);
|
||||
})
|
||||
.catch(() => {
|
||||
setParentAvailableCredit(null);
|
||||
setAgentRebateLimitPercent(null);
|
||||
});
|
||||
}
|
||||
void getAdminPlayer(row.id)
|
||||
.then((full) => {
|
||||
setEditingPlayer(full);
|
||||
@@ -418,6 +464,15 @@ export function AgentsPlayersPanel({
|
||||
|
||||
const body: Parameters<typeof putAdminPlayer>[1] = {};
|
||||
if (editUsername.trim() !== "" && editUsername.trim() !== (editingPlayer.username ?? "")) {
|
||||
const usernameIssue = validateNativePlayerUsername(editUsername);
|
||||
if (usernameIssue === "invalid_charset") {
|
||||
toast.error(
|
||||
t("playersPanel.usernameInvalidCharset", {
|
||||
defaultValue: "登录账号只能使用字母、数字、点(.)、下划线和连字符",
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
body.username = editUsername.trim();
|
||||
}
|
||||
if (editNickname.trim() !== (editingPlayer.nickname ?? "")) {
|
||||
@@ -430,17 +485,56 @@ export function AgentsPlayersPanel({
|
||||
if (editStatus !== editingPlayer.status) {
|
||||
body.status = editStatus;
|
||||
}
|
||||
const creditDelta = editCreditDelta.trim() === "" ? 0 : Number.parseInt(editCreditDelta, 10);
|
||||
if (!Number.isNaN(creditDelta) && creditDelta > 0) {
|
||||
const signedDelta = editCreditAdjustMode === "increase" ? creditDelta : -creditDelta;
|
||||
const nextCredit = Math.max(0, (editingPlayer.credit_limit ?? 0) + signedDelta);
|
||||
if (nextCredit !== (editingPlayer.credit_limit ?? 0)) {
|
||||
body.credit_limit = nextCredit;
|
||||
}
|
||||
const baselineCredit = editingPlayer.credit_limit ?? 0;
|
||||
const parsedCreditLimit =
|
||||
editCreditLimit.trim() === "" ? baselineCredit : Number.parseInt(editCreditLimit, 10);
|
||||
if (
|
||||
Number.isNaN(parsedCreditLimit) ||
|
||||
parsedCreditLimit < 0 ||
|
||||
!Number.isInteger(parsedCreditLimit)
|
||||
) {
|
||||
toast.error(
|
||||
t("playersPanel.creditLimitInvalid", { defaultValue: "授信额度必须为不小于 0 的整数" }),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (
|
||||
parentAvailableCredit !== null &&
|
||||
parsedCreditLimit > baselineCredit + parentAvailableCredit
|
||||
) {
|
||||
toast.error(
|
||||
t("playersPanel.creditLimitExceeded", {
|
||||
defaultValue: "授信额度不能超过当前代理可下发额度",
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (parsedCreditLimit !== baselineCredit) {
|
||||
body.credit_limit = parsedCreditLimit;
|
||||
}
|
||||
const prevRebate = resolvePlayerRebateRate(editingPlayer);
|
||||
const nextPercent = parsePercentUi(editRebateRate);
|
||||
const nextRebate = nextPercent === null ? null : nextPercent;
|
||||
if (
|
||||
nextRebate !== null &&
|
||||
(nextRebate < 0 || nextRebate > AGENT_PERCENT_HARD_MAX)
|
||||
) {
|
||||
toast.error(
|
||||
t("playersPanel.rebateRateInvalid", {
|
||||
defaultValue: "回水比例须在 0–100% 之间",
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (nextRebate !== null && nextRebate > maxPlayerRebatePercent) {
|
||||
toast.error(
|
||||
t("playersPanel.rebateRateExceedsAgent", {
|
||||
defaultValue: "回水比例不能超过代理回水上限 {{max}}%",
|
||||
max: maxPlayerRebatePercent,
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (nextRebate !== null && nextRebate !== (prevRebate ?? 0)) {
|
||||
body.rebate_rate = nextRebate;
|
||||
}
|
||||
@@ -505,13 +599,6 @@ export function AgentsPlayersPanel({
|
||||
);
|
||||
const billingCurrency =
|
||||
selectedBill?.currency_code ?? billingPlayer?.default_currency ?? "NPR";
|
||||
const projectedCreditLimit = useMemo(() => {
|
||||
const delta = editCreditDelta.trim() === "" ? 0 : Number.parseInt(editCreditDelta, 10);
|
||||
if (Number.isNaN(delta) || delta <= 0) {
|
||||
return editCreditBase;
|
||||
}
|
||||
return Math.max(0, editCreditBase + (editCreditAdjustMode === "increase" ? delta : -delta));
|
||||
}, [editCreditAdjustMode, editCreditBase, editCreditDelta]);
|
||||
|
||||
function resetBillingForm(): void {
|
||||
setPayAmount("");
|
||||
@@ -957,44 +1044,33 @@ export function AgentsPlayersPanel({
|
||||
</div>
|
||||
|
||||
<div className="grid gap-x-4 gap-y-5 sm:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="agent-player-credit" className="text-muted-foreground">
|
||||
{t("playersPanel.creditLimit", { defaultValue: "授信额度" })}
|
||||
</Label>
|
||||
<Input
|
||||
id="agent-player-credit"
|
||||
type="number"
|
||||
min={0}
|
||||
value={creditLimit}
|
||||
onChange={(e) => setCreditLimit(e.target.value)}
|
||||
className="bg-background/50 transition-colors focus:bg-background"
|
||||
/>
|
||||
{parentAvailableCredit !== null ? (
|
||||
<p className="text-[11px] text-muted-foreground/80">
|
||||
{t("playersPanel.availableToGrant", {
|
||||
defaultValue: "代理剩余可下发:{{amount}}",
|
||||
amount: formatCredit(parentAvailableCredit),
|
||||
})}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
<PlayerCreditLimitField
|
||||
id="agent-player-credit"
|
||||
value={creditLimit}
|
||||
onValueChange={setCreditLimit}
|
||||
parentAvailableCredit={parentAvailableCredit}
|
||||
/>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="agent-player-rebate" className="text-muted-foreground">
|
||||
{t("playersPanel.rebateRate", { defaultValue: "回水比例 (%)" })}
|
||||
</Label>
|
||||
<Input
|
||||
<AdminNumericStepper
|
||||
id="agent-player-rebate"
|
||||
type="number"
|
||||
min={0}
|
||||
max={100}
|
||||
step="0.01"
|
||||
value={rebateRate}
|
||||
placeholder="0"
|
||||
onChange={(e) => setRebateRate(e.target.value)}
|
||||
className="bg-background/50 transition-colors focus:bg-background"
|
||||
onValueChange={setRebateRate}
|
||||
min={0}
|
||||
max={maxPlayerRebatePercent}
|
||||
step={0.5}
|
||||
suffix="%"
|
||||
preserveOverMaxOnBlur
|
||||
/>
|
||||
<p className="text-[11px] text-muted-foreground/80">
|
||||
{t("playersPanel.rebateRateHint", { defaultValue: "填写百分比,如 5 表示 5%" })}
|
||||
{agentRebateLimitPercent !== null
|
||||
? t("playersPanel.rebateAgentCapHint", {
|
||||
defaultValue: "不得超过代理回水上限 {{max}}%",
|
||||
max: maxPlayerRebatePercent,
|
||||
})
|
||||
: t("playersPanel.rebateRateStepHint", { defaultValue: "使用 +/- 调整回水比例" })}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1160,14 +1236,14 @@ export function AgentsPlayersPanel({
|
||||
</Dialog>
|
||||
|
||||
<Dialog open={editDialogOpen} onOpenChange={handleEditDialogOpenChange}>
|
||||
<DialogContent>
|
||||
<DialogContent className="sm:max-w-[460px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t("players:editDialogTitle", { defaultValue: "编辑玩家" })}</DialogTitle>
|
||||
</DialogHeader>
|
||||
{editDetailLoading ? <AdminLoadingState minHeight="6rem" /> : null}
|
||||
<div className={editDetailLoading ? "hidden" : "space-y-3"}>
|
||||
<div className={editDetailLoading ? "hidden" : "grid gap-5 py-2"}>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="agent-player-edit-username">
|
||||
<Label htmlFor="agent-player-edit-username" className="text-muted-foreground">
|
||||
{t("players:username", { defaultValue: "用户名" })}
|
||||
</Label>
|
||||
<Input
|
||||
@@ -1175,10 +1251,11 @@ export function AgentsPlayersPanel({
|
||||
value={editUsername}
|
||||
onChange={(e) => setEditUsername(e.target.value)}
|
||||
autoComplete="off"
|
||||
className="bg-background/50 transition-colors focus:bg-background"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="agent-player-edit-nickname">
|
||||
<Label htmlFor="agent-player-edit-nickname" className="text-muted-foreground">
|
||||
{t("players:nickname", { defaultValue: "昵称" })}
|
||||
</Label>
|
||||
<Input
|
||||
@@ -1186,10 +1263,11 @@ export function AgentsPlayersPanel({
|
||||
value={editNickname}
|
||||
onChange={(e) => setEditNickname(e.target.value)}
|
||||
autoComplete="off"
|
||||
className="bg-background/50 transition-colors focus:bg-background"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="agent-player-edit-currency">
|
||||
<Label htmlFor="agent-player-edit-currency" className="text-muted-foreground">
|
||||
{t("players:defaultCurrency", { defaultValue: "默认币种" })}
|
||||
</Label>
|
||||
<Input
|
||||
@@ -1197,87 +1275,41 @@ export function AgentsPlayersPanel({
|
||||
value={editDefaultCurrency}
|
||||
onChange={(e) => setEditDefaultCurrency(e.target.value)}
|
||||
autoComplete="off"
|
||||
className="bg-background/50 transition-colors focus:bg-background"
|
||||
/>
|
||||
</div>
|
||||
<PlayerCreditLimitField
|
||||
id="agent-player-edit-credit"
|
||||
value={editCreditLimit}
|
||||
onValueChange={setEditCreditLimit}
|
||||
parentAvailableCredit={parentAvailableCredit}
|
||||
baselineCreditLimit={editingPlayer?.credit_limit ?? 0}
|
||||
/>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="agent-player-edit-credit">
|
||||
{t("playersPanel.creditLimit", { defaultValue: "授信额度" })}
|
||||
</Label>
|
||||
<div className="rounded-xl border border-border/70 bg-muted/20 p-3">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 text-sm">
|
||||
<span className="text-muted-foreground">
|
||||
{t("playersPanel.currentCredit", { defaultValue: "当前授信" })}
|
||||
</span>
|
||||
<span className="font-semibold">
|
||||
{formatPlayerCreditAmount(editCreditBase, editDefaultCurrency || "NPR")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-3 grid gap-3 sm:grid-cols-[9rem_minmax(0,1fr)]">
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="agent-player-edit-credit-mode">
|
||||
{t("playersPanel.creditAdjustType", { defaultValue: "调整方式" })}
|
||||
</Label>
|
||||
<Select
|
||||
value={editCreditAdjustMode}
|
||||
onValueChange={(value) => setEditCreditAdjustMode(value as "increase" | "decrease")}
|
||||
>
|
||||
<SelectTrigger id="agent-player-edit-credit-mode">
|
||||
<SelectValue>
|
||||
{creditAdjustModeLabel(editCreditAdjustMode, t)}
|
||||
</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="increase">
|
||||
{creditAdjustModeLabel("increase", t)}
|
||||
</SelectItem>
|
||||
<SelectItem value="decrease">
|
||||
{creditAdjustModeLabel("decrease", t)}
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="agent-player-edit-credit-delta">
|
||||
{t("playersPanel.creditAdjustAmount", { defaultValue: "调整额度" })}
|
||||
</Label>
|
||||
<Input
|
||||
id="agent-player-edit-credit-delta"
|
||||
type="number"
|
||||
min={0}
|
||||
value={editCreditDelta}
|
||||
onChange={(e) => setEditCreditDelta(e.target.value)}
|
||||
placeholder="0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<p className="mt-3 text-xs text-muted-foreground">
|
||||
{t("playersPanel.creditProjected", {
|
||||
defaultValue: "调整后授信:{{amount}}",
|
||||
amount: formatPlayerCreditAmount(projectedCreditLimit, editDefaultCurrency || "NPR"),
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="agent-player-edit-rebate">
|
||||
<Label htmlFor="agent-player-edit-rebate" className="text-muted-foreground">
|
||||
{t("playersPanel.rebateRate", { defaultValue: "回水比例 (%)" })}
|
||||
</Label>
|
||||
<Input
|
||||
<AdminNumericStepper
|
||||
id="agent-player-edit-rebate"
|
||||
type="number"
|
||||
min={0}
|
||||
max={100}
|
||||
step="0.01"
|
||||
value={editRebateRate}
|
||||
onChange={(e) => setEditRebateRate(e.target.value)}
|
||||
placeholder="0"
|
||||
onValueChange={setEditRebateRate}
|
||||
min={0}
|
||||
max={maxPlayerRebatePercent}
|
||||
step={0.5}
|
||||
suffix="%"
|
||||
preserveOverMaxOnBlur
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t("playersPanel.rebateRateHint", { defaultValue: "填写百分比,如 5 表示 5%" })}
|
||||
<p className="text-[11px] text-muted-foreground/80">
|
||||
{agentRebateLimitPercent !== null
|
||||
? t("playersPanel.rebateAgentCapHint", {
|
||||
defaultValue: "不得超过代理回水上限 {{max}}%",
|
||||
max: maxPlayerRebatePercent,
|
||||
})
|
||||
: t("playersPanel.rebateRateStepHint", { defaultValue: "使用 +/- 调整回水比例" })}
|
||||
</p>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="agent-player-edit-risk-tags">
|
||||
<Label htmlFor="agent-player-edit-risk-tags" className="text-muted-foreground">
|
||||
{t("playersPanel.riskTags", { defaultValue: "风控标签" })}
|
||||
</Label>
|
||||
<Input
|
||||
@@ -1287,10 +1319,11 @@ export function AgentsPlayersPanel({
|
||||
placeholder={t("playersPanel.riskTagsPlaceholder", {
|
||||
defaultValue: "逗号分隔",
|
||||
})}
|
||||
className="bg-background/50 transition-colors focus:bg-background"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="agent-player-edit-status">
|
||||
<Label htmlFor="agent-player-edit-status" className="text-muted-foreground">
|
||||
{t("players:status", { defaultValue: "状态" })}
|
||||
</Label>
|
||||
<Select value={String(editStatus)} onValueChange={(value) => setEditStatus(Number(value))}>
|
||||
@@ -1311,7 +1344,7 @@ export function AgentsPlayersPanel({
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<DialogFooter className="mt-2">
|
||||
<Button type="button" variant="outline" onClick={() => setEditDialogOpen(false)}>
|
||||
{t("common:actions.cancel", { defaultValue: "取消" })}
|
||||
</Button>
|
||||
|
||||
@@ -44,7 +44,7 @@ import { Label } from "@/components/ui/label";
|
||||
import { AdminTableLoadingRow } from "@/components/admin/admin-loading-state";
|
||||
import { adminHasAnyPermission } from "@/lib/admin-permissions";
|
||||
import { PRD_PLAYER_FREEZE_MANAGE, PRD_USERS_MANAGE } from "@/lib/admin-prd";
|
||||
import { useAdminProfile } from "@/stores/admin-session";
|
||||
import { isSiteAdminOperator } from "@/lib/admin-session-variants";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
@@ -62,6 +62,7 @@ import {
|
||||
} from "@/components/ui/table";
|
||||
import { useAdminCurrencyCatalog } from "@/hooks/use-admin-currency-catalog";
|
||||
import { adminPlayerDetailPath } from "@/lib/admin-player-paths";
|
||||
import { useAdminProfile } from "@/stores/admin-session";
|
||||
import { PlayerFundingModeBadge } from "@/components/admin/player-funding-badges";
|
||||
import { playerBalanceCells } from "@/lib/admin-player-display";
|
||||
import { ADMIN_SELECT_FILTER_ALL, adminSiteSelectLabel } from "@/lib/admin-select-display";
|
||||
@@ -101,6 +102,7 @@ export function PlayersConsole(): React.ReactElement {
|
||||
const exportLabels = useExportLabels("players");
|
||||
const profile = useAdminProfile();
|
||||
const isSuperAdmin = profile?.is_super_admin === true;
|
||||
const isSiteAdmin = isSiteAdminOperator(profile);
|
||||
const boundAgent = profile?.agent ?? null;
|
||||
const { sites: siteOptions, canChooseSite } = useAdminSiteCodeOptions();
|
||||
const router = useRouter();
|
||||
@@ -109,6 +111,7 @@ export function PlayersConsole(): React.ReactElement {
|
||||
const keywordFromUrl = (searchParams.get("keyword") ?? "").trim();
|
||||
useAdminCurrencyCatalog();
|
||||
const canManagePlayers = adminHasAnyPermission(profile?.permissions, [PRD_USERS_MANAGE]);
|
||||
const canPickAgentOnCreate = isSuperAdmin || isSiteAdmin;
|
||||
const canFreezePlayers = adminHasAnyPermission(profile?.permissions, [PRD_PLAYER_FREEZE_MANAGE]);
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
@@ -212,10 +215,13 @@ export function PlayersConsole(): React.ReactElement {
|
||||
setAccountMode("create");
|
||||
setEditingAccountId(null);
|
||||
const agentSite = boundAgent?.site_code?.trim() ?? "";
|
||||
const siteAdminSite = profile?.site?.code?.trim() ?? "";
|
||||
const defaultSite =
|
||||
agentSite !== ""
|
||||
? agentSite
|
||||
: siteOptions[0]?.code ?? "";
|
||||
: siteAdminSite !== ""
|
||||
? siteAdminSite
|
||||
: siteOptions[0]?.code ?? "";
|
||||
setFormSiteCode(defaultSite);
|
||||
setFormAgentNodeId(boundAgent?.id);
|
||||
setFormSitePlayerId("");
|
||||
@@ -228,7 +234,7 @@ export function PlayersConsole(): React.ReactElement {
|
||||
}
|
||||
|
||||
useAsyncEffect(() => {
|
||||
if (!accountOpen || accountMode !== "create" || !isSuperAdmin) {
|
||||
if (!accountOpen || accountMode !== "create" || !canPickAgentOnCreate) {
|
||||
return;
|
||||
}
|
||||
const siteCode = formSiteCode.trim();
|
||||
@@ -271,7 +277,7 @@ export function PlayersConsole(): React.ReactElement {
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [accountOpen, accountMode, formSiteCode, isSuperAdmin, siteOptions]);
|
||||
}, [accountOpen, accountMode, canPickAgentOnCreate, formSiteCode, siteOptions]);
|
||||
|
||||
function openEditAccount(row: AdminPlayerRow): void {
|
||||
setAccountMode("edit");
|
||||
@@ -295,7 +301,7 @@ export function PlayersConsole(): React.ReactElement {
|
||||
|
||||
async function submitAccount(): Promise<void> {
|
||||
if (accountMode === "create") {
|
||||
if (!isSuperAdmin && !boundAgent) {
|
||||
if (!isSuperAdmin && !boundAgent && !isSiteAdmin) {
|
||||
toast.error(t("createAgentRequired"));
|
||||
return;
|
||||
}
|
||||
@@ -307,7 +313,7 @@ export function PlayersConsole(): React.ReactElement {
|
||||
toast.error(t("sitePlayerIdRequired"));
|
||||
return;
|
||||
}
|
||||
if (isSuperAdmin && (formAgentNodeId === undefined || formAgentNodeId <= 0)) {
|
||||
if (canPickAgentOnCreate && (formAgentNodeId === undefined || formAgentNodeId <= 0)) {
|
||||
toast.error(t("createAgentRequired"));
|
||||
return;
|
||||
}
|
||||
@@ -320,7 +326,7 @@ export function PlayersConsole(): React.ReactElement {
|
||||
nickname: formNickname.trim() || null,
|
||||
default_currency: formDefaultCurrency,
|
||||
status: formStatus,
|
||||
...(isSuperAdmin && formAgentNodeId
|
||||
...(canPickAgentOnCreate && formAgentNodeId
|
||||
? { agent_node_id: formAgentNodeId }
|
||||
: {}),
|
||||
});
|
||||
@@ -738,7 +744,7 @@ export function PlayersConsole(): React.ReactElement {
|
||||
code: boundAgent.code,
|
||||
})}
|
||||
</p>
|
||||
) : isSuperAdmin ? (
|
||||
) : canPickAgentOnCreate ? (
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="player-agent-node">{t("createAgentNode")}</Label>
|
||||
<Select
|
||||
|
||||
@@ -39,7 +39,6 @@ import {
|
||||
REPORT_UI_TO_JOB_TYPE,
|
||||
type ReportUiKey,
|
||||
} from "@/lib/report-export-map";
|
||||
import { ReportJobsPanel } from "@/modules/reports/report-jobs-panel";
|
||||
import { getAdminRiskPoolDetail, getAdminRiskPools } from "@/api/admin-risk";
|
||||
import { getAdminUsers } from "@/api/admin-users";
|
||||
import { getAdminTransferOrders } from "@/api/admin-wallet";
|
||||
@@ -662,7 +661,6 @@ export function ReportsConsole({ initialCategory }: { initialCategory?: ReportCa
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(20);
|
||||
const [exporting, setExporting] = useState<ExportFormat | null>(null);
|
||||
const [jobRefreshToken, setJobRefreshToken] = useState(0);
|
||||
const [search, setSearch] = useState<SearchState>(emptySearch);
|
||||
const playOptions = useCachedPlayTypeOptions();
|
||||
const tRef = useTranslationRef(["reports", "common"]);
|
||||
@@ -1180,7 +1178,6 @@ export function ReportsConsole({ initialCategory }: { initialCategory?: ReportCa
|
||||
export_format: format === "excel" ? "xlsx" : "csv",
|
||||
parameters,
|
||||
});
|
||||
setJobRefreshToken((n) => n + 1);
|
||||
const { blob, filename } = await downloadAdminReportJob(job.id);
|
||||
const ext = job.export_format === "xlsx" ? "xlsx" : "csv";
|
||||
downloadBlob(blob, filename ?? `${exportFileBase}.${ext}`);
|
||||
@@ -1789,12 +1786,6 @@ export function ReportsConsole({ initialCategory }: { initialCategory?: ReportCa
|
||||
) : null}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<ReportJobsPanel
|
||||
canExport={canExportReports}
|
||||
refreshToken={jobRefreshToken}
|
||||
reportType={REPORT_UI_TO_JOB_TYPE[selectedReport.key as ReportUiKey]}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const files = [
|
||||
"reports/report-jobs-panel.tsx",
|
||||
"risk/risk-pools-console.tsx",
|
||||
"risk/risk-index-console.tsx",
|
||||
"admin-roles/admin-roles-console.tsx",
|
||||
|
||||
Reference in New Issue
Block a user