| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import { initialShareParties } from "./settlement-demo";
- import { enterpriseTeamIds, regionPath, type OrganizationData, type ShareFields } from "./organization-demo";
- import { typeLabel } from "./api/ticket";
- export const currentSharePartyTypes = ["运营商", "合伙人", "运维团队"] as const;
- export type CurrentSharePartyType = typeof currentSharePartyTypes[number];
- export const historicalSharePartyIds: Record<string, string> = {
- "op-0": "SP-01", "op-2": "SP-02", "pt-0": "SP-03",
- "pt-1": "SP-04", "mt-0": "SP-05", "mt-1": "SP-06", "op-5": "SP-07",
- };
- export function sharePartiesFromOrganization(data: OrganizationData, options: {
- customerRegions?: ReadonlySet<string>;
- defaultDay?: number | null;
- operatorBilling?: Record<string, Pick<OrganizationData["operators"][number], "reconcileDay" | "payCycle">>;
- } = {}) {
- const { customerRegions } = options;
- const customers = customerRegions
- ? data.enterprises.filter((customer) => customerRegions.has(customer.region))
- : data.enterprises;
- const defaultDay = options.defaultDay ?? null;
- const rows = [
- ...data.operators.map((item) => {
- const { reconcileDay, payCycle } = options.operatorBilling?.[item.id] ?? item;
- const day = reconcileDay == null
- ? (defaultDay == null ? "跟随系统默认" : `跟随默认(${defaultDay} 日)`)
- : `每月 ${reconcileDay} 日`;
- return { ...item, displayName: item.name, name: `${regionPath(data, item.region)} / ${item.name}`, note: `对账日 ${day} · ${payCycle}`, type: "运营商" as const, customerCount: customers.filter((customer) => customer.operator === item.id).length };
- }),
- ...data.partners.map((item) => ({ ...item, displayName: item.name, note: item.title, type: "合伙人" as const, customerCount: customers.filter((customer) => customer.partner === item.id).length })),
- ...data.maintenanceTeams.map((item) => ({ ...item, displayName: item.name, note: `${item.mode}分派 · 承接 ${item.ticketTypes?.map(typeLabel).join("、") || "—"}`, type: "运维团队" as const, customerCount: customers.filter((customer) => enterpriseTeamIds(customer).includes(item.id)).length })),
- ];
- return rows.map(({ id, name, displayName, note, type, region, shareMode, shareValue, sharePending, customerCount }) => {
- const historyId = historicalSharePartyIds[id];
- return { id, historyId, name, displayName, note, type, region, regionLabel: regionPath(data, region), shareMode, shareValue, sharePending, customerCount, history: initialShareParties.find((party) => party.id === historyId)?.history ?? [] };
- });
- }
- /**
- * 「已配分成/未配分成」判据:档案两列为空(`sharePending`=`toShare` 派生的「按比例 0」占位)
- * ⇒ 未配分成。⛔ 把占位值当已配置(否则状态列「已配分成」与取值列「未配分成」同行矛盾,TC-FN-24)。
- */
- export function hasShareTerms(party: ShareFields) {
- return !party.sharePending && Boolean(party.shareMode) && Number.isFinite(party.shareValue) && party.shareValue >= 0;
- }
- export function formatShareTerms(party: ShareFields) {
- if (!hasShareTerms(party)) return "未配分成";
- if (party.shareMode === "按比例") return `${Math.round(party.shareValue * 10000) / 100}%`;
- const amount = party.shareValue.toLocaleString("zh-CN", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
- return `¥ ${amount}${party.shareMode === "按金额" ? "/月" : "/账号"}`;
- }
|