Some checks failed
lotteryadmin CI / build (push) Has been cancelled
- 各角色仪表盘:KPI 可点击跳转、快捷入口、去重冗余区块,代理/站点降级 analytics - 代理线路:创建玩家权限、侧栏搜索、深链 URL、档案保存与删除预检等修复 - 统一密码最短 6 位;代理模块表格/侧栏背景色一致(admin-table-inset) - 报表、钱包、对账、开奖、结算、配置等模块结构与 i18n 同步更新
115 lines
3.2 KiB
TypeScript
115 lines
3.2 KiB
TypeScript
import type { SettlementBillListScope } from "@/api/admin-agent-settlement";
|
||
|
||
export type SettlementPeriodView = "bills" | "ledger";
|
||
|
||
export type SettlementBillScopeFilter = "all" | SettlementBillListScope;
|
||
|
||
const VALID_VIEWS: SettlementPeriodView[] = ["bills", "ledger"];
|
||
|
||
const VALID_BILL_SCOPES: SettlementBillScopeFilter[] = [
|
||
"all",
|
||
"pending_confirm",
|
||
"awaiting_payment",
|
||
"settled",
|
||
"adjustment",
|
||
];
|
||
|
||
function parsePositiveInt(raw: string | null): number | null {
|
||
if (raw === null || raw === "") {
|
||
return null;
|
||
}
|
||
const value = Number(raw);
|
||
return Number.isInteger(value) && value > 0 ? value : null;
|
||
}
|
||
|
||
export function settlementCenterListHref(adminSiteId?: number | null): string {
|
||
return settlementCenterScopeHref(adminSiteId, "all");
|
||
}
|
||
|
||
/** 结算中心列表深链,可带账单筛选 scope(待确认 / 待收付等)。 */
|
||
export function settlementCenterScopeHref(
|
||
adminSiteId?: number | null,
|
||
billScope: SettlementBillScopeFilter = "all",
|
||
): string {
|
||
const params = new URLSearchParams();
|
||
if (adminSiteId != null && adminSiteId > 0) {
|
||
params.set("site", String(adminSiteId));
|
||
}
|
||
if (billScope !== "all") {
|
||
params.set("scope", billScope);
|
||
}
|
||
const qs = params.toString();
|
||
return qs ? `/admin/settlement-center?${qs}` : "/admin/settlement-center";
|
||
}
|
||
|
||
export function settlementPeriodViewHref(
|
||
periodId: number,
|
||
view: SettlementPeriodView = "bills",
|
||
adminSiteId?: number | null,
|
||
billScope?: SettlementBillScopeFilter | null,
|
||
): string {
|
||
const params = new URLSearchParams({
|
||
period: String(periodId),
|
||
view,
|
||
});
|
||
if (adminSiteId != null && adminSiteId > 0) {
|
||
params.set("site", String(adminSiteId));
|
||
}
|
||
if (billScope != null && billScope !== "all") {
|
||
params.set("scope", billScope);
|
||
}
|
||
return `/admin/settlement-center?${params.toString()}`;
|
||
}
|
||
|
||
export function preferredBillScopeForPeriod(summary?: {
|
||
pending_confirm?: number;
|
||
awaiting_payment?: number;
|
||
}): SettlementBillScopeFilter {
|
||
const pending = summary?.pending_confirm ?? 0;
|
||
const awaiting = summary?.awaiting_payment ?? 0;
|
||
if (pending > 0) {
|
||
return "pending_confirm";
|
||
}
|
||
if (awaiting > 0) {
|
||
return "awaiting_payment";
|
||
}
|
||
return "all";
|
||
}
|
||
|
||
export function parseSettlementCenterView(
|
||
siteRaw: string | null,
|
||
periodRaw: string | null,
|
||
viewRaw: string | null,
|
||
scopeRaw?: string | null,
|
||
): {
|
||
siteId: number | null;
|
||
periodId: number | null;
|
||
view: SettlementPeriodView;
|
||
billScope: SettlementBillScopeFilter;
|
||
} {
|
||
const normalizedView =
|
||
viewRaw === "reports" || viewRaw === "operations" ? "bills" : viewRaw;
|
||
const view =
|
||
normalizedView !== null && VALID_VIEWS.includes(normalizedView as SettlementPeriodView)
|
||
? (normalizedView as SettlementPeriodView)
|
||
: "bills";
|
||
|
||
const billScope =
|
||
scopeRaw !== null &&
|
||
scopeRaw !== "" &&
|
||
VALID_BILL_SCOPES.includes(scopeRaw as SettlementBillScopeFilter)
|
||
? (scopeRaw as SettlementBillScopeFilter)
|
||
: "all";
|
||
|
||
return {
|
||
siteId: parsePositiveInt(siteRaw),
|
||
periodId: parsePositiveInt(periodRaw),
|
||
view,
|
||
billScope,
|
||
};
|
||
}
|
||
|
||
export function isSettlementPeriodView(value: string): value is SettlementPeriodView {
|
||
return VALID_VIEWS.includes(value as SettlementPeriodView);
|
||
}
|