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:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user