data.js 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. /* 模拟数据只存在于页面内存。内部下标从 0 开始,页面上的序号从 1 开始。 */
  2. const TODAY = "2026-10-15";
  3. /* 区域三级:大区 / 市 / 区县。客户可挂在任一层,只能挂一个节点。 */
  4. const LEVEL_NAMES = ["大区", "市", "区县"];
  5. const SEED = {
  6. setting: { defaultReconcileDay: 5, perAccountFee: 80 },
  7. regions: [
  8. { id: "east", name: "华东大区", level: 0, parent: null },
  9. { id: "south", name: "华南大区", level: 0, parent: null },
  10. { id: "sh", name: "上海市", level: 1, parent: "east" },
  11. { id: "su", name: "苏州市", level: 1, parent: "east" },
  12. { id: "gz", name: "广州市", level: 1, parent: "south" },
  13. { id: "pd", name: "浦东新区", level: 2, parent: "sh" },
  14. { id: "lg", name: "临港新片区", level: 2, parent: "sh" },
  15. { id: "mh", name: "闵行区", level: 2, parent: "sh" },
  16. { id: "ks", name: "昆山市", level: 2, parent: "su" },
  17. { id: "th", name: "天河区", level: 2, parent: "gz" },
  18. ],
  19. /* 运营商按所属区域建档(region 为区域节点 id,含下级生效);客户只归属唯一运营商。 */
  20. operators: [
  21. { name: "联通", region: "sh", reconcileDay: null, payCycle: "按月", notify: "notice@unicorn.example" },
  22. { name: "电信", region: "east", reconcileDay: null, payCycle: "按年", notify: "notice@ict-telecom.example" },
  23. { name: "移动", region: "east", reconcileDay: 8, payCycle: "按月", notify: "notice@mobile.example" },
  24. { name: "广东电信", region: "south", reconcileDay: null, payCycle: "按季度", notify: "notice@gd-ict.example" },
  25. { name: "苏州移动", region: "su", reconcileDay: 12, payCycle: "按季度", notify: "notice@sz-mobile.example" },
  26. { name: "广州移动", region: "gz", reconcileDay: null, payCycle: "按月", notify: "notice@gz-mobile.example" },
  27. ],
  28. partners: [
  29. { name: "邹合", region: "east", title: "华东渠道", notify: "zouhe@example", scope: { regions: ["east"], enterprises: [] } },
  30. { name: "何南", region: "gz", title: "华南渠道", notify: "henan@example", scope: { regions: ["th"], enterprises: [2] } },
  31. ],
  32. teams: [
  33. { name: "华东常规运维", type: "常规", mode: "手工", scope: { regions: ["sh", "su"], enterprises: [] } },
  34. { name: "沪东施工", type: "施工", mode: "自动平均", scope: { regions: ["pd"], enterprises: [1] } },
  35. ],
  36. /* hq: true 为系统内置的总运营团队:不限所属区域(region 为空),负责范围覆盖全国,列表置顶且不可删除。
  37. 该团队的默认主账号即总运营账号(见 users 中 builtin: true 的一条),不再另设运营团队账号。 */
  38. regOpsTeams: [
  39. { name: "总运营团队", region: "", hq: true, scope: { regions: ["east", "south"], enterprises: [] }, desc: "总部平台级团队,不限所属区域,覆盖全国全部客户" },
  40. { name: "华东运营", region: "east", scope: { regions: ["east"], enterprises: [] }, desc: "覆盖华东大区全部下挂客户" },
  41. { name: "华南运营", region: "south", scope: { regions: ["south"], enterprises: [] }, desc: "覆盖华南大区全部下挂客户" },
  42. { name: "上海运营", region: "sh", scope: { regions: ["sh"], enterprises: [] }, desc: "覆盖上海市及其下级区域" },
  43. ],
  44. members: [
  45. { name: "周宁", team: 0, type: "常规", scope: [0, 1, 2, 4] },
  46. { name: "李可", team: 0, type: "常规", scope: [0, 3, 4] },
  47. { name: "赵工", team: 1, type: "施工", scope: [0, 1, 3] },
  48. { name: "钱工", team: 1, type: "施工", scope: [0, 1, 3] },
  49. { name: "陈录", team: 0, type: "录入", scope: [0, 1, 2, 3, 4] },
  50. ],
  51. awards: [
  52. { member: 2, at: "2026-09-20", kind: "奖励", text: "浦东园区割接提前 1 天完成,客户零投诉", amount: 200 },
  53. { member: 2, at: "2026-10-11", kind: "扣罚", text: "临港上门未按约定时间到达,扣罚只作考核,费用在线下处理", amount: -100 },
  54. ],
  55. enterprises: [
  56. {
  57. no: "KL-2026-0001",
  58. name: "澄澜科技有限公司",
  59. subject: "企业",
  60. materials: "营业执照、企业名称、经办联系人、地址、合同、电话",
  61. files: ["oss://materials/KL-2026-0001/营业执照.pdf", "oss://materials/KL-2026-0001/受理单.pdf", "oss://materials/KL-2026-0001/联通交接单.pdf"],
  62. contact: "沈澄",
  63. address: "上海市浦东新区金港路 300 号 6 号楼 3 层",
  64. phone: "021-66001001",
  65. region: "pd",
  66. operator: 0,
  67. partner: 0,
  68. teams: { 常规: 0, 施工: 1 },
  69. status: "在用",
  70. quota: 5,
  71. costSel: [],
  72. history: [
  73. { at: "2026-08-10 10:20", field: "挂载区域", before: "未挂载", after: "华东大区 / 上海市 / 浦东新区", by: "林管" },
  74. { at: "2026-03-20 16:40", field: "账户状态", before: "未开通", after: "在用(实际开通日 2026-03-20)", by: "周宁回填" },
  75. ],
  76. },
  77. {
  78. no: "KL-2026-0008",
  79. name: "临港跨境贸易",
  80. subject: "企业",
  81. materials: "营业执照、企业名称、经办联系人、地址、合同、电话",
  82. files: ["oss://materials/KL-2026-0008/营业执照.pdf", "oss://materials/KL-2026-0008/ICT合同.pdf", "oss://materials/KL-2026-0008/联通交接单.pdf"],
  83. contact: "陆港",
  84. address: "上海市浦东新区环湖西二路 800 号 A 座 11 层",
  85. phone: "021-66002008",
  86. region: "lg",
  87. operator: 1,
  88. partner: null,
  89. teams: { 常规: 0 },
  90. status: "未开通",
  91. quota: 8,
  92. costSel: [],
  93. history: [
  94. { at: "2026-09-02 09:05", field: "挂载区域", before: "未挂载", after: "华东大区 / 上海市 / 临港新片区", by: "林管" },
  95. ],
  96. },
  97. {
  98. no: "KL-2026-0012",
  99. name: "陈阿福",
  100. subject: "个体工商户",
  101. materials: "身份证、姓名、手机号、地址",
  102. files: ["oss://materials/KL-2026-0012/身份证.jpg"],
  103. contact: "陈阿福",
  104. address: "江苏省昆山市玉山镇中华园东路 58 号 2 单元 402",
  105. phone: "13800001112",
  106. region: "ks",
  107. operator: 2,
  108. partner: 1,
  109. teams: { 常规: 0 },
  110. status: "在用",
  111. quota: 1,
  112. costSel: [],
  113. history: [
  114. { at: "2026-08-28 14:10", field: "挂载区域", before: "未挂载", after: "华东大区 / 苏州市 / 昆山市", by: "林管" },
  115. ],
  116. },
  117. {
  118. no: "KL-2026-0019",
  119. name: "王敏",
  120. subject: "个人",
  121. materials: "身份证、姓名、手机号、地址",
  122. files: ["oss://materials/KL-2026-0019/身份证.jpg"],
  123. contact: "王敏",
  124. address: "上海市浦东新区张杨路 1200 弄 12 号 1802 室",
  125. phone: "13900001019",
  126. region: "pd",
  127. operator: 2,
  128. partner: 1,
  129. teams: { 常规: 0, 施工: 1 },
  130. status: "在用",
  131. quota: 2,
  132. costSel: [1, 2],
  133. history: [
  134. { at: "2026-08-20 11:30", field: "挂载区域", before: "华东大区 / 苏州市 / 昆山市", after: "华东大区 / 上海市 / 浦东新区", by: "林管" },
  135. { at: "2026-08-20 11:32", field: "合伙人", before: "无", after: "何南(华南渠道,直接多选客户)", by: "林管" },
  136. ],
  137. },
  138. {
  139. no: "KL-2026-0023",
  140. name: "海岚跨境电商(上海)",
  141. subject: "企业",
  142. materials: "营业执照、企业名称、经办联系人、地址、合同、电话",
  143. files: ["oss://materials/KL-2026-0023/营业执照.pdf", "oss://materials/KL-2026-0023/续约合同.pdf"],
  144. contact: "周岚",
  145. address: "上海市闵行区申长路 988 号 3 号楼 5 层",
  146. phone: "021-54002023",
  147. region: "mh",
  148. operator: 0,
  149. partner: 0,
  150. teams: { 常规: 0 },
  151. status: "在用",
  152. quota: 2,
  153. costSel: [3],
  154. history: [
  155. { at: "2026-09-12 15:00", field: "挂载区域", before: "未挂载", after: "华东大区 / 上海市 / 闵行区", by: "林管" },
  156. { at: "2025-10-01 10:00", field: "账户状态", before: "未开通", after: "在用(实际开通日 2025-10-01)", by: "周宁回填" },
  157. ],
  158. },
  159. ],
  160. /* 固定套餐口径取自 docs/原始文档/跨境网络报价单.pdf:
  161. 使用规模 10 人左右分「通用办公 / 直播高需求 / AI 应用」三组共 8 档,另设「单独境外 IP」按个叠加档;
  162. 使用规模 30 人及以上走定制化,报价单不列固定单价,由区域运营为具体客户配自定义套餐承接
  163. (跨境养号的云手机租赁同为按需报价,同样走自定义套餐)。
  164. cat 为用途分类,目录按它分组;desc 为报价单权益口径。
  165. 报价单按月报价,首期只做按年订阅,年订阅价格 = 月价 × 12。
  166. 分账号额度报价单未给出,按用途推定(办公档 10;直播 A 单链接单流 2、B 单链接多流 5、C 顶配 10;
  167. AI 5M 档 3、10M 档 5;按个叠加的增值项不占额度记 0),运营可在目录内直接改。 */
  168. packages: [
  169. { name: "跨境办公 · 基础档", cat: "通用办公", yearPrice: 1080, monthPrice: 90, quota: 10, bw: "不承诺带宽", desc: "一般访问流量,无固定境外 IP,不承诺带宽", custom: null },
  170. { name: "跨境办公 · 标准档", cat: "通用办公", yearPrice: 1440, monthPrice: 120, quota: 10, bw: "下行 10M / 上行 1M", desc: "店铺管理、一般办公、视频会议、ERP 等,比基础档速度更快更稳定", custom: null },
  171. { name: "跨境办公 · 独立 IP 档", cat: "通用办公", yearPrice: 1920, monthPrice: 160, quota: 10, bw: "下行 5M / 上行 2M", desc: "单独境外 IP 配置,通过 CPE 组织网络管理平台", custom: null },
  172. { name: "直播高需求 · A 类", cat: "直播高需求", yearPrice: 10800, monthPrice: 900, quota: 2, bw: "上下行 10M", desc: "单链接、单流;单独境外 IP 另购,80 元/个", custom: null },
  173. { name: "直播高需求 · B 类", cat: "直播高需求", yearPrice: 32400, monthPrice: 2700, quota: 5, bw: "上下行 30M", desc: "单链接、多流;团队内部运营如后台管理、看播等已包含", custom: null },
  174. { name: "直播高需求 · C 类", cat: "直播高需求", yearPrice: 62400, monthPrice: 5200, quota: 10, bw: "上下行 50M", desc: "直播高需求顶配档;链接数与流数按合同另定", custom: null },
  175. { name: "AI 应用 · 5M 档", cat: "AI 应用", yearPrice: 5760, monthPrice: 480, quota: 3, bw: "上下行 5M", desc: "面向 AI 应用访问的固定上下行带宽档", custom: null },
  176. { name: "AI 应用 · 10M 档", cat: "AI 应用", yearPrice: 10800, monthPrice: 900, quota: 5, bw: "上下行 10M", desc: "面向 AI 应用访问的固定上下行带宽档", custom: null },
  177. { name: "单独境外 IP(按个叠加)", cat: "叠加增值", yearPrice: 960, monthPrice: 80, quota: 0, bw: "按个计,不占带宽", desc: "80 元/个/月,与主档叠加订阅、各自计费;个数与单价在订阅上按合同改写", custom: null },
  178. { name: "临港 ICT 定制套餐", cat: "定制化", yearPrice: 24000, monthPrice: 2000, quota: 8, bw: "150Mbps", desc: "使用规模 30 人及以上,业务分析与需求摸排调研后定制;临港跨境贸易专项档", custom: 1 },
  179. ],
  180. /* 订阅一律按名称引用「套餐目录」中的档位,签约时把目录价冻结到订阅上(目录改价不影响存量订阅)。
  181. 示例覆盖全部用途分类:通用办公(基础 / 标准 / 独立 IP 档)、直播高需求(A 类)、AI 应用(5M 档)、
  182. 叠加增值(单独境外 IP ×2 个:80 元/个/月 × 2 × 12)、定制化(临港 ICT 自定义档)。 */
  183. subs: [
  184. { enterprise: 0, name: "跨境办公 · 基础档", kind: "升降配前", status: "已到期", start: "2025-03-18", end: "2026-03-17", yearPrice: 1080, monthPrice: 90, openedOn: "2025-03-20", contractNo: "HT-CL-20250318", files: ["oss://contracts/HT-CL-20250318.pdf"] },
  185. { enterprise: 0, name: "跨境办公 · 标准档", kind: "正式", status: "生效中", start: "2026-03-18", end: "2027-03-17", yearPrice: 1440, monthPrice: 120, openedOn: "2026-03-20", contractNo: "HT-CL-20260318", files: ["oss://contracts/HT-CL-20260318.pdf"] },
  186. { enterprise: 1, name: "临港 ICT 定制套餐", kind: "正式", status: "生效中", start: "2026-09-02", end: "2027-09-01", yearPrice: 24000, monthPrice: 2000, openedOn: null, contractNo: "ICT-LG-20260902", files: ["oss://contracts/ICT-LG-20260902.pdf"] },
  187. { enterprise: 2, name: "直播高需求 · A 类", kind: "正式", status: "生效中", start: "2026-09-01", end: "2026-10-31", yearPrice: 10800, monthPrice: 900, openedOn: "2026-09-01", contractNo: "HT-CFA-20260901", files: ["oss://contracts/HT-CFA-20260901.pdf"] },
  188. { enterprise: 3, name: "AI 应用 · 5M 档", kind: "正式", status: "生效中", start: "2026-06-01", end: "2027-05-31", yearPrice: 5760, monthPrice: 480, openedOn: "2026-06-01", contractNo: "HT-WM-20260601", files: ["oss://contracts/HT-WM-20260601.pdf"] },
  189. { enterprise: 3, name: "单独境外 IP(按个叠加)", kind: "叠加", status: "生效中", start: "2026-08-01", end: "2027-07-31", yearPrice: 1920, monthPrice: 160, openedOn: "2026-08-01", contractNo: "HT-WM-20260801", files: ["oss://contracts/HT-WM-20260801.pdf"] },
  190. { enterprise: 4, name: "跨境办公 · 独立 IP 档", kind: "正式", status: "已到期", start: "2025-10-01", end: "2026-09-30", yearPrice: 1920, monthPrice: 160, openedOn: "2025-10-01", contractNo: "HT-HL-20251001", files: ["oss://contracts/HT-HL-20251001.pdf"] },
  191. { enterprise: 4, name: "跨境办公 · 独立 IP 档", kind: "正式", status: "待生效", start: "2026-11-01", end: "2027-10-31", yearPrice: 1920, monthPrice: 160, openedOn: null, contractNo: "HT-HL-20261101", files: ["oss://contracts/HT-HL-20261101.pdf"] },
  192. /* 客户已在用时新增的叠加订阅:保存时自动生成「服务开通」工单(见 tickets 末条),实际开通日尚未回填 */
  193. { enterprise: 3, name: "单独境外 IP(按个叠加)", kind: "叠加", status: "生效中", start: "2026-10-08", end: "2027-10-07", yearPrice: 1920, monthPrice: 160, openedOn: null, contractNo: "HT-WM-20261008", files: ["oss://contracts/HT-WM-20261008.pdf"] },
  194. ],
  195. /* 下属分账号:login 为账号名,规则是「客户主账号登录名-n」,n 为该客户的分账号序号,从 1 起,
  196. 正式与临时测试共用一个序号池;netLogin 为零信任客户端上的账号名,选填、可改、不校验唯一。
  197. 正式数量由套餐额度决定,示例里未建满的部分由启动时的 alignSubAccounts 按额度自动补齐。
  198. 分账号计费遵从合同:正式分账号只要客户合同在期就按合同期间计入外包运维费,未开通照计,到期停机后不计。 */
  199. accounts: [
  200. { enterprise: 0, name: "张敏", login: "clkj-1", status: "在用", usage: "正式", openedOn: "2026-03-20", netLogin: "zhangmin@clkj" },
  201. { enterprise: 0, name: "李航", login: "clkj-2", status: "在用", usage: "正式", openedOn: "2026-03-20", netLogin: "" },
  202. { enterprise: 0, name: "联调测试", login: "clkj-3", status: "在用", usage: "测试", openedOn: "2026-04-01", netLogin: "uat-liantiao@clkj" },
  203. { enterprise: 0, name: "待开通席位", login: "clkj-4", status: "未开通", usage: "正式", openedOn: null, netLogin: "" },
  204. { enterprise: 1, name: "临港-财务", login: "lgkjmy-1", status: "未开通", usage: "正式", openedOn: null, netLogin: "" },
  205. { enterprise: 1, name: "临港-关务", login: "lgkjmy-2", status: "未开通", usage: "正式", openedOn: null, netLogin: "customs-01@lingang" },
  206. { enterprise: 3, name: "王敏本人", login: "wm-1", status: "在用", usage: "正式", openedOn: "2026-06-01", netLogin: "wangmin@wm" },
  207. { enterprise: 4, name: "海岚-小王", login: "hlkjdssh-1", status: "在用", usage: "正式", openedOn: "2025-10-01", netLogin: "" },
  208. ],
  209. /* 开停记录与工单一一对应;状态:待执行 / 执行成功 / 执行失败 */
  210. actions: [
  211. { id: "A-20261007-08", enterprise: 1, type: "开户", status: "待执行", ticket: 0, created: "2026-10-07", doneOn: null, extendUntil: null, by: null },
  212. { id: "A-20261009-23", enterprise: 4, type: "到期停机", status: "待执行", ticket: 7, created: "2026-10-09", doneOn: null, extendUntil: null, by: null },
  213. ],
  214. tickets: [
  215. { type: "开户", enterprise: 1, account: null, team: 0, assignee: null, status: "待处理", created: "2026-10-07", text: "合同套餐已建立,网络侧尚未开通。本工单只开通客户本身,不含下属分账号;分账号在套餐订阅时按额度对齐开通。", logs: ["2026-10-07 生成待执行开户记录(A-20261007-08)", "2026-10-07 林管登记联通交接单的开通准备资料(办公应用 6 个账号;中国香港 10 兆固定 IP 2 个)"], closeReason: null, materials: ["oss://materials/KL-2026-0008/联通交接单.pdf"],
  216. prep: {
  217. apps: { 浏览应用: 0, 办公应用: 6, 运营应用: 0, 直播应用: 0, 定制应用: 0 },
  218. ips: [{ country: "中国香港", bw: "10兆", count: 2 }],
  219. agent: "临港联通 · 张工", agentPhone: "13601700208", handoverOn: "2026-10-06",
  220. } },
  221. { type: "故障", enterprise: 0, account: null, team: 0, assignee: 0, status: "处理中", created: "2026-10-12", text: "办公网晚高峰丢包,疑似国际出口拥塞。", logs: ["2026-10-12 客户主账号在系统内提交(文字)", "2026-10-12 吴队分派给周宁"], closeReason: null, materials: [] },
  222. { type: "故障", enterprise: 0, account: null, team: 1, assignee: null, status: "待处理", created: "2026-10-14", text: "机房侧线路需要现场复查(现场施工类)。", logs: ["2026-10-14 常规团队转施工团队,尚未分派"], closeReason: null, materials: [] },
  223. { type: "故障", enterprise: 0, account: null, team: 1, assignee: 2, status: "处理中", created: "2026-10-10", text: "园区弱电井跳纤,现场施工。", logs: ["2026-10-10 自动平均分派给赵工"], closeReason: null, materials: ["oss://tickets/T-1010/现场照片-1.jpg"] },
  224. { type: "故障", enterprise: 3, account: null, team: 1, assignee: 2, status: "待处理", created: "2026-10-13", text: "上门后用户不在,待再次上门。", logs: ["2026-10-13 分派给赵工"], closeReason: null, materials: [] },
  225. { type: "售后", enterprise: 0, account: null, team: 0, assignee: 1, status: "已完成", created: "2026-09-28", text: "补充开通说明并回传配置手册。", logs: ["2026-09-29 李可填写处理记录并完成"], closeReason: null, materials: [] },
  226. { type: "故障", enterprise: 0, account: 0, team: 0, assignee: 0, status: "处理中", created: "2026-10-14", text: "我的座位网络登不上。", logs: ["2026-10-14 下属分账号张敏在系统内提交", "2026-10-14 吴队分派给周宁"], closeReason: null, materials: [] },
  227. { type: "到期停机", enterprise: 4, account: null, team: 0, assignee: 0, status: "待处理", created: "2026-10-09", text: "订阅于 2026-09-30 到期,次日生成到期停机记录。停机不把计费延长过结束日。", logs: ["2026-10-09 日任务生成待执行到期停机记录(A-20261009-23)", "2026-10-09 吴队分派给周宁"], closeReason: null, materials: [] },
  228. { type: "故障", enterprise: 0, account: null, team: 0, assignee: 1, status: "已关闭", created: "2026-10-08", text: "重复报修:办公网丢包。", logs: ["2026-10-08 客户主账号在系统内提交", "2026-10-08 分派给李可", "2026-10-09 吴队关闭:与 10-12 晚高峰丢包工单重复,合并处理"], closeReason: "与同期晚高峰丢包工单重复,合并处理。", materials: [] },
  229. /* 客户已在用时新增订阅 → 服务开通工单:不带开停记录、不改客户账户状态,按套餐带出的服务清单逐条核对,
  230. 全部核对后填实际开通日完成,实际开通日写回 sub 指向的订阅。创建满 7 个自然日仍未完成即进超期提醒。 */
  231. { type: "服务开通", enterprise: 3, account: null, team: 0, assignee: 1, status: "处理中", created: "2026-10-07", sub: 8, extendUntil: null,
  232. text: "HT-WM-20261008 新增叠加订阅「单独境外 IP(按个叠加)」,客户已在用,请在网络侧开通下列 3 项服务。",
  233. logs: ["2026-10-07 林管 新增叠加订阅,自动生成服务开通工单", "2026-10-08 吴队分派给李可"], closeReason: null, materials: [],
  234. svcItems: [
  235. { text: "网络带宽:按个计,不占带宽", done: false },
  236. { text: "单独境外 IP(按个叠加):个数与单价以合同为准(本条订阅年价 1920 元),不补建分账号档案", done: false },
  237. { text: "套餐权益:80 元/个/月,与主档叠加订阅、各自计费;个数与单价在订阅上按合同改写", done: false },
  238. ] },
  239. ],
  240. /* 分成规则挂在渠道与客户的关系上,两种方式二选一:按总金额比例(rate,0-1)或按总客户账号数(per,每账号分成金额,精确到分)。
  241. mode 缺省为按总金额比例。两层都没有时分成计 0。合同增补优先于区域常规。 */
  242. rules: [
  243. { ch: "operator", ref: 0, ent: 0, layer: "区域常规", rate: 0.2 },
  244. { ch: "team", ref: 0, ent: 0, layer: "合同增补", mode: "按总客户账号数", per: 50 },
  245. { ch: "team", ref: 1, ent: 0, layer: "区域常规", rate: 0.05 },
  246. { ch: "partner", ref: 0, ent: 0, layer: "区域常规", rate: 0.05 },
  247. { ch: "operator", ref: 2, ent: 3, layer: "区域常规", rate: 0.15 },
  248. { ch: "team", ref: 0, ent: 3, layer: "区域常规", rate: 0.1 },
  249. { ch: "team", ref: 1, ent: 3, layer: "区域常规", rate: 0.05 },
  250. { ch: "partner", ref: 1, ent: 3, layer: "合同增补", rate: 0.08 },
  251. { ch: "operator", ref: 0, ent: 4, layer: "区域常规", rate: 0.2 },
  252. { ch: "team", ref: 0, ent: 4, layer: "区域常规", rate: 0.1 },
  253. { ch: "partner", ref: 0, ent: 4, layer: "区域常规", rate: 0.05 },
  254. ],
  255. /* 应扣除成本:线路投入不扣基数;国际资源按摊销扣;项目费用一次性。设备同一项目只选比例或固定金额之一。
  256. costSel 记该客户勾选要计入分成基数扣除的成本项下标;未勾选的成本项本月不扣。 */
  257. costs: [
  258. { ent: 0, sub: 1, kind: "国际资源", name: "国际出口带宽月摊销", amount: 80, repeat: "每月" },
  259. { ent: 3, sub: 4, kind: "国际资源", name: "国家 IP 地址月摊销", amount: 50, repeat: "每月" },
  260. { ent: 3, sub: 5, kind: "国际资源", name: "国际云主机月摊销", amount: 30, repeat: "每月" },
  261. { ent: 4, sub: 6, kind: "国际资源", name: "国家 IP 地址月摊销", amount: 40, repeat: "每月" },
  262. ],
  263. settlements: [
  264. {
  265. enterprise: 0, sub: 1, month: "2026-03", days: 12, monthDays: 31, partial: true, std: 120, amount: 46.45, tail: false, exact: 46.45,
  266. costs: [], base: 46.45,
  267. shares: [
  268. { who: "联通", mode: "按总金额比例", rate: 0.2, amount: 9.29 },
  269. { who: "华东常规运维", mode: "按总客户账号数", per: 50, accounts: 5, amount: 112.90 },
  270. { who: "沪东施工", mode: "按总金额比例", rate: 0.05, amount: 2.32 },
  271. { who: "华东合伙人", mode: "按总金额比例", rate: 0.05, amount: 2.32 },
  272. ],
  273. opsFee: 180.65, acctDays: [{ name: "张敏", days: 14, fee: 36.13 }, { name: "李航", days: 14, fee: 36.13 }, { name: "未开通的正式分账号 × 3(按合同照计)", days: 14, fee: 108.39 }],
  274. attrs: "联通 / 邹合(华东) / 华东常规运维 / 沪东施工", batch: null,
  275. },
  276. {
  277. enterprise: 0, sub: 1, month: "2026-04", days: 30, monthDays: 30, partial: false, std: 120, amount: 120, tail: false, exact: 120,
  278. costs: [], base: 120,
  279. shares: [
  280. { who: "联通", mode: "按总金额比例", rate: 0.2, amount: 24 },
  281. { who: "华东常规运维", mode: "按总客户账号数", per: 50, accounts: 5, amount: 250 },
  282. { who: "沪东施工", mode: "按总金额比例", rate: 0.05, amount: 6 },
  283. { who: "华东合伙人", mode: "按总金额比例", rate: 0.05, amount: 6 },
  284. ],
  285. opsFee: 400, acctDays: [{ name: "张敏", days: 30, fee: 80 }, { name: "李航", days: 30, fee: 80 }, { name: "未开通的正式分账号 × 3(按合同照计)", days: 30, fee: 240 }],
  286. attrs: "联通 / 邹合(华东) / 华东常规运维 / 沪东施工", batch: null,
  287. },
  288. {
  289. enterprise: 0, sub: 1, month: "2026-09", days: 30, monthDays: 30, partial: false, std: 120, amount: 120, tail: false, exact: 120,
  290. costs: [], base: 120,
  291. shares: [
  292. { who: "联通", mode: "按总金额比例", rate: 0.2, amount: 24 },
  293. { who: "华东常规运维", mode: "按总客户账号数", per: 50, accounts: 5, amount: 250 },
  294. { who: "沪东施工", mode: "按总金额比例", rate: 0.05, amount: 6 },
  295. { who: "华东合伙人", mode: "按总金额比例", rate: 0.05, amount: 6 },
  296. ],
  297. opsFee: 400, acctDays: [{ name: "张敏", days: 30, fee: 80 }, { name: "李航", days: 30, fee: 80 }, { name: "未开通的正式分账号 × 3(按合同照计)", days: 30, fee: 240 }],
  298. attrs: "联通 / 邹合(华东) / 华东常规运维 / 沪东施工", batch: 0,
  299. },
  300. {
  301. enterprise: 3, sub: 4, month: "2026-09", days: 30, monthDays: 30, partial: false, std: 480, amount: 480, tail: false, exact: 480,
  302. costs: [{ name: "国家 IP 地址月摊销", amount: 50 }], base: 430,
  303. shares: [
  304. { who: "移动", mode: "按总金额比例", rate: 0.15, amount: 64.5 },
  305. { who: "华东常规运维", mode: "按总金额比例", rate: 0.1, amount: 43 },
  306. { who: "沪东施工", mode: "按总金额比例", rate: 0.05, amount: 21.5 },
  307. { who: "华南合伙人", mode: "合同增补 · 比例", rate: 0.08, amount: 34.4 },
  308. ],
  309. opsFee: 160, acctDays: [{ name: "王敏本人", days: 30, fee: 80 }, { name: "未开通的正式分账号 × 1(按合同照计)", days: 30, fee: 80 }],
  310. attrs: "移动 / 何南(华南) / 华东常规运维 / 沪东施工", batch: 1,
  311. },
  312. {
  313. enterprise: 3, sub: 5, month: "2026-09", days: 30, monthDays: 30, partial: false, std: 160, amount: 160, tail: false, exact: 160,
  314. costs: [{ name: "国际云主机月摊销", amount: 30 }], base: 130,
  315. shares: [
  316. { who: "移动", mode: "按总金额比例", rate: 0.15, amount: 19.5 },
  317. { who: "华东常规运维", mode: "按总金额比例", rate: 0.1, amount: 13 },
  318. { who: "沪东施工", mode: "按总金额比例", rate: 0.05, amount: 6.5 },
  319. { who: "华南合伙人", mode: "合同增补 · 比例", rate: 0.08, amount: 10.4 },
  320. ],
  321. opsFee: 0, acctDays: [],
  322. attrs: "移动 / 何南(华南) / 华东常规运维 / 沪东施工(叠加订阅各算各的;叠加增值不占分账号额度,外包运维费已随主档行计入)", batch: 1,
  323. },
  324. {
  325. enterprise: 4, sub: 6, month: "2026-09", days: 30, monthDays: 30, partial: false, std: 160, amount: 160, tail: true, exact: 160,
  326. costs: [{ name: "国家 IP 地址月摊销", amount: 40 }], base: 120,
  327. shares: [
  328. { who: "联通", mode: "按总金额比例", rate: 0.2, amount: 24 },
  329. { who: "华东常规运维", mode: "按总金额比例", rate: 0.1, amount: 12 },
  330. { who: "沪东施工(未配置,计 0)", mode: "—", rate: 0, amount: 0 },
  331. { who: "华东合伙人", mode: "按总金额比例", rate: 0.05, amount: 6 },
  332. ],
  333. opsFee: 160, acctDays: [{ name: "海岚-小王", days: 30, fee: 80 }, { name: "未开通的正式分账号 × 1(按合同照计)", days: 30, fee: 80 }],
  334. attrs: "联通 / 邹合(华东) / 华东常规运维 / 无施工团队", batch: 0,
  335. },
  336. ],
  337. scopes: [
  338. { kind: "运营商", ref: 0, enabled: true },
  339. { kind: "运营商", ref: 1, enabled: true },
  340. { kind: "运营商", ref: 2, enabled: true },
  341. { kind: "合伙人", ref: 0, enabled: true },
  342. { kind: "合伙人", ref: 1, enabled: false },
  343. { kind: "运维", ref: 0, enabled: true },
  344. { kind: "运维", ref: 1, enabled: false },
  345. ],
  346. batches: [
  347. { no: "PC-20261005-LT", day: "2026-10-05", month: "2026-09", scope: "联通 · 运营商范围", trigger: "自动", status: "已执行", by: "系统", at: "2026-10-05 06:00", rows: [2, 5], warning: "" },
  348. { no: "PC-20261008-YD", day: "2026-10-08", month: "2026-09", scope: "移动 · 运营商范围", trigger: "自动", status: "已执行", by: "系统", at: "2026-10-08 06:00", rows: [3, 4], warning: "" },
  349. { no: "PC-20260905-DX", day: "2026-09-05", month: "2026-08", scope: "电信 · 运营商范围", trigger: "自动", status: "已打回", by: "系统", at: "2026-09-05 06:00", rows: [], warning: "分成比例误录,运营商尚未付款" },
  350. { no: "PC-20260912-DX-R", day: "2026-09-12", month: "2026-08", scope: "电信 · 运营商范围", trigger: "人工", status: "已执行", by: "林管", at: "2026-09-12 10:20", rows: [], warning: "打回后重做,新明细成为 8 月唯一有效应收" },
  351. { no: "PC-20260605-LT", day: "2026-06-05", month: "2026-05", scope: "联通 · 运营商范围", trigger: "自动", status: "执行失败", by: "系统", at: "2026-06-05 06:00", rows: [], warning: "出账任务异常中断,等待人工补跑" },
  352. ],
  353. /* 客户批量导入批次(见需求规格说明 4.8):一次上传一个文件生成一个批次,批次号贯穿行级结果、续传与按批次导出。
  354. rows 每行记 line 行编号、cells 模板 14 列原文、status 成功 / 失败、reason 失败原因、
  355. ent 导入生成的客户下标(未成功为 null)。行级明细持久保留,是续传与按批次导出的依据;批次不删除、不撤销。 */
  356. importBatches: [
  357. {
  358. no: "IMP-2026-0001", file: "闵行区客户建档-20261008.csv", by: "林管", at: "2026-10-08 10:05",
  359. status: "已完成",
  360. rows: [
  361. { line: "1", cells: ["1", "海岚跨境电商(上海)", "企业", "周岚", "021-54002023", "上海市闵行区申长路 988 号 3 号楼 5 层", "闵行区", "联通", "邹合", "华东常规运维", "", "跨境办公 · 独立 IP 档", "hlkjdssh", ""], status: "成功", reason: "", ent: 4 },
  362. ],
  363. },
  364. {
  365. no: "IMP-2026-0002", file: "临港与张江客户-20261012.csv", by: "周运营", at: "2026-10-12 09:40",
  366. status: "有失败待续传",
  367. rows: [
  368. { line: "1", cells: ["1", "临港跨境贸易", "企业", "陆港", "021-66002008", "上海市浦东新区环湖西二路 800 号 A 座 11 层", "临港新片区", "电信", "", "华东常规运维", "", "", "lgkjmy", ""], status: "成功", reason: "", ent: 1 },
  369. { line: "2", cells: ["2", "澄澜科技有限公司", "企业", "沈澄", "021-66001001", "上海市浦东新区金港路 300 号 6 号楼 3 层", "浦东新区", "联通", "邹合", "华东常规运维", "", "跨境办公 · 标准档", "", ""], status: "失败", reason: "客户名称与已有客户「澄澜科技有限公司」(KL-2026-0001)重复,不覆盖已有客户", ent: null },
  370. { line: "3", cells: ["3", "张江芯创半导体", "企业", "何工", "021-50003301", "上海市浦东新区祖冲之路 887 号 2 号楼", "张江区", "联通", "", "华东常规运维", "", "", "", "13900000331"], status: "失败", reason: "所挂区域「张江区」匹配不到,填区域名称原文且需在负责范围内", ent: null },
  371. { line: "4", cells: ["4", "陆家嘴外贸服务中心", "个体工商户", "王经理", "021-58002277", "上海市浦东新区世纪大道 100 号 18 层", "浦东新区", "联通", "", "华东常规运维", "", "", "clkj", ""], status: "失败", reason: "主账号登录名 clkj 已被占用,系统不自动加后缀,请改写后重新上传", ent: null },
  372. ],
  373. },
  374. ],
  375. notes: [
  376. { level: "严重", bill: "澄澜科技 2026-03", text: "3 月比例曾按 0.18 录入,核验后从 4 月起改为 0.20。3 月账单已递交运营商,原明细保留不改。", by: "林管", at: "2026-04-06 09:30" },
  377. { level: "严重", bill: "电信范围 2026-08(PC-20260905-DX)", text: "批次分成比例误录,运营商尚未付款,批次打回重做;重做批次 PC-20260912-DX-R 核验通过。", by: "林管", at: "2026-09-12 10:15" },
  378. ],
  379. feedback: [
  380. { no: "KL-UNKNOWN-3", action: "开户", date: "2026-10-11", state: "nomatch", result: "主体号匹配不到任何待执行记录,待人工处理。不自动创建客户,不改账户状态。", handled: false },
  381. { no: "KL-2026-0008", action: "开户", date: "2026-10-14", state: "pending", result: "匹配到待执行记录 A-20261007-08,反馈实际开通日 2026-10-14,可据此回填(与人工回填等效)。", handled: false, actionId: "A-20261007-08", fillDate: "2026-10-14" },
  382. { no: "KL-2026-0019", action: "开户", date: "2026-10-13", state: "conflict", result: "该客户开户记录已于 2026-06-01 回填成功,反馈与现状冲突,不覆盖,待人工确认。", handled: false },
  383. ],
  384. collections: [
  385. { partner: 0, enterprise: 0, amount: 8000, date: "2026-04-18", note: "运营商已收,仅作区域核对,不回写应收" },
  386. ],
  387. /* 审计日志只追加。区域树维护仅总运营可见。 */
  388. auditLogs: [
  389. { at: "2026-08-01 09:12", by: "林管", type: "新建区域", object: "华东大区 / 上海市 / 浦东新区", before: "", after: "新建三级节点" },
  390. { at: "2026-08-01 09:20", by: "林管", type: "新建区域", object: "华东大区 / 上海市 / 临港新片区", before: "", after: "新建区县节点" },
  391. { at: "2026-08-02 14:02", by: "林管", type: "新建区域", object: "华东大区 / 苏州市 / 昆山市", before: "", after: "新建区县节点" },
  392. { at: "2026-08-05 10:40", by: "林管", type: "重命名区域", object: "华东大区 / 上海市 / 临港新片区", before: "南汇新城区", after: "临港新片区" },
  393. { at: "2026-08-10 10:20", by: "林管", type: "客户挂载", object: "澄澜科技有限公司", before: "未挂载", after: "华东大区 / 上海市 / 浦东新区" },
  394. { at: "2026-08-20 11:30", by: "林管", type: "客户改挂区域", object: "王敏", before: "华东大区 / 苏州市 / 昆山市", after: "华东大区 / 上海市 / 浦东新区" },
  395. { at: "2026-08-21 16:00", by: "林管", type: "合伙人负责范围首次配置", object: "邹合(华东渠道)", before: "(空)", after: "澄澜科技、临港跨境、陈阿福、王敏、海岚跨境(选定华东大区,含其下级全部客户)" },
  396. { at: "2026-09-02 09:10", by: "林管", type: "运维团队负责范围调整", object: "沪东施工", before: "澄澜科技、王敏", after: "澄澜科技、临港跨境、王敏(新增直接多选客户:临港跨境)" },
  397. { at: "2026-10-05 15:20", by: "林管", type: "合伙人负责范围调整", object: "何南(华南渠道)", before: "(空)", after: "天河区(暂无直属客户);直接多选客户:陈阿福" },
  398. { at: "2026-10-05 15:25", by: "林管", type: "结算范围启用", object: "合伙人范围 · 何南(华南渠道)", before: "未启用", after: "未启用(拟首次应收后再启用)" },
  399. ],
  400. /* 登录账号:login 为登录名,acctStatus 在用 / 停用(停用的不出现在「换身份」列表),
  401. mustChange 为下次登录是否必须改密,pwdResetOn 为最近一次重置密码日期。
  402. role=operator 是运营商的对账查看账号(只读),与运营商档案一比一。
  403. builtin: true 为系统内置账号:总运营账号即总运营团队的默认主账号,必须存在、不能删除,主账号身份也不可转交。
  404. phone 为绑定手机号:选填,可更换,但全站唯一(一个手机号至多绑定一个账号),
  405. 绑定后可用手机号代替登录名登录;未填时只能用登录名登录。
  406. 客户主账号不用初始密码,改用一次性激活码激活(acctOpenOn 开通日、claimOn 当前码生成日、
  407. claimExpireOn 有效期截止日:导出交付时才写,未交付为空、不判过期、claimStatus 未激活 / 已激活 /
  408. 已过期;已激活时 claimCode 置空)。 */
  409. users: [
  410. { name: "林管", role: "admin", regTeam: 0, primary: true, builtin: true, title: "总运营团队主账号", phone: "13900000001", acctStatus: "在用", mustChange: false },
  411. { name: "周运营", role: "regAdmin", regTeam: 1, primary: true, title: "华东运营 · 团队主账号", login: "zhouyun@example", phone: "13900000101", acctStatus: "在用", mustChange: false, pwdResetOn: "2026-09-20" },
  412. { name: "许芸", role: "regAdmin", regTeam: 1, title: "华东运营 · 子账号(客户建档)", login: "xuyun@example", acctStatus: "在用", mustChange: true, pwdResetOn: "2026-10-09" },
  413. { name: "吴队", role: "teamLead", team: 0, title: "华东常规运维 · 团队主账号", login: "wudui@example", phone: "13900000103", acctStatus: "在用", mustChange: false, pwdResetOn: "2026-09-06" },
  414. { name: "周宁", role: "ops", member: 0, title: "常规运维 · 开停回填", login: "zhouning@example", phone: "13900000104", acctStatus: "在用", mustChange: false, pwdResetOn: "2026-09-18" },
  415. { name: "孙队", role: "teamLead", team: 1, title: "沪东施工 · 团队主账号", login: "sundui@example", phone: "13900000105", acctStatus: "在用", mustChange: false, pwdResetOn: "2026-09-02" },
  416. { name: "赵工", role: "worker", member: 2, title: "施工人员", login: "zhaogong@example", phone: "13900000106", acctStatus: "在用", mustChange: false, pwdResetOn: "2026-09-21" },
  417. { name: "陈录", role: "entry", member: 4, title: "录入人员 · 电信/移动 ICT 代录", login: "chenlu@example", acctStatus: "在用", mustChange: false, pwdResetOn: "2026-09-25" },
  418. /* 客户主账号登录名取客户名称的拼音首字母(见《需求规格说明》3.2),不照抄中文客户名称。
  419. 激活状态只有三种,样例:未激活且已交付还在有效期内(临港)、已激活(澄澜)、
  420. 截止日已过按当天即时判为已过期(陈阿福、海岚,导出时会自动重置出新码)、
  421. 刚建档还没导出交付(王敏,没有截止日、不判过期) */
  422. { name: "澄澜科技有限公司", role: "enterprise", enterprise: 0, title: "客户主账号", login: "clkj", phone: "13900000200", acctStatus: "在用", mustChange: false, pwdResetOn: "2026-09-11", acctOpenOn: "2026-09-11", claimStatus: "已激活", claimCode: "", claimOn: "2026-09-11", claimExpireOn: "2026-09-25" },
  423. { name: "临港跨境贸易", role: "enterprise", enterprise: 1, title: "客户主账号", login: "lgkjmy", acctStatus: "在用", mustChange: false, acctOpenOn: "2026-10-12", claimStatus: "未激活", claimCode: "KQF7HRM2XW", claimOn: "2026-10-12", claimExpireOn: "2026-10-26" },
  424. { name: "陈阿福", role: "enterprise", enterprise: 2, title: "客户主账号", login: "caf", phone: "13900000212", acctStatus: "在用", mustChange: false, acctOpenOn: "2026-09-20", claimStatus: "未激活", claimCode: "TBW4KJN6QD", claimOn: "2026-09-20", claimExpireOn: "2026-10-04" },
  425. { name: "王敏", role: "enterprise", enterprise: 3, title: "客户主账号", login: "wm", acctStatus: "在用", mustChange: false, acctOpenOn: "2026-10-15", claimStatus: "未激活", claimCode: "PMXZ3RTV8H", claimOn: "2026-10-15", claimExpireOn: "" },
  426. { name: "海岚跨境电商(上海)", role: "enterprise", enterprise: 4, title: "客户主账号", login: "hlkjdssh", acctStatus: "在用", mustChange: false, acctOpenOn: "2026-10-08", claimStatus: "未激活", claimCode: "GHY2NQSC5F", claimOn: "2026-10-08", claimExpireOn: "2026-10-13" },
  427. { name: "张敏", role: "sub", enterprise: 0, account: 0, title: "下属分账号" },
  428. { name: "邹合", role: "partner", partner: 0, title: "华东渠道", login: "zouhe@example", phone: "13900000107", acctStatus: "在用", mustChange: false, pwdResetOn: "2026-09-12" },
  429. { name: "何南", role: "partner", partner: 1, title: "华南渠道", login: "henan@example", phone: "13900000108", acctStatus: "停用", mustChange: false, pwdResetOn: "2026-08-05" },
  430. { name: "联通对账", role: "operator", operator: 0, title: "联通 · 对账查看账号", login: "unicom-dz@example", phone: "13900000109", acctStatus: "在用", mustChange: false, pwdResetOn: "2026-09-26" },
  431. ],
  432. };
  433. function cloneSeed() {
  434. return JSON.parse(JSON.stringify(SEED));
  435. }
  436. function money(n) {
  437. return Number(n || 0).toLocaleString("zh-CN", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
  438. }
  439. function pct(n) {
  440. const v = Math.round(Number(n || 0) * 10000) / 100;
  441. return String(v) + "%";
  442. }
  443. function daysBetween(start, end) {
  444. const a = new Date(start + "T00:00:00");
  445. const b = new Date(end + "T00:00:00");
  446. return Math.round((b - a) / 86400000) + 1;
  447. }
  448. function addDays(date, n) {
  449. const d = new Date(date + "T00:00:00");
  450. d.setDate(d.getDate() + n);
  451. const pad = (x) => String(x).padStart(2, "0");
  452. return d.getFullYear() + "-" + pad(d.getMonth() + 1) + "-" + pad(d.getDate());
  453. }
  454. function overdueAction(action) {
  455. if (!action || action.status !== "待执行") return false;
  456. const limit = action.extendUntil || addDays(action.created, 7);
  457. return TODAY > limit;
  458. }
  459. function unfinished(db, memberIndex) {
  460. return db.tickets.filter((t) => t.assignee === memberIndex && (t.status === "待处理" || t.status === "处理中")).length;
  461. }
  462. function ticketTypeOfTeam(team) {
  463. return team.type === "施工" ? "施工" : "常规";
  464. }
  465. function eligible(db, ticket) {
  466. const team = db.teams[ticket.team];
  467. const need = ticketTypeOfTeam(team);
  468. return db.members
  469. .map((m, index) => ({ ...m, index }))
  470. .filter((m) => m.team === ticket.team && m.type === need && m.scope.includes(ticket.enterprise));
  471. }
  472. function pickEven(db, ticket) {
  473. const list = eligible(db, ticket);
  474. if (!list.length) return null;
  475. list.sort((a, b) => unfinished(db, a.index) - unfinished(db, b.index) || a.index - b.index);
  476. return list[0].index;
  477. }
  478. /* ---- 区域与范围工具 ---- */
  479. function regionNode(db, id) {
  480. return db.regions.find((r) => r.id === id) || null;
  481. }
  482. function regionPath(db, id) {
  483. const names = [];
  484. let cur = regionNode(db, id);
  485. while (cur) {
  486. names.unshift(cur.name);
  487. cur = cur.parent ? regionNode(db, cur.parent) : null;
  488. }
  489. return names.join(" / ");
  490. }
  491. function descendantIds(db, id) {
  492. const out = [id];
  493. let added = true;
  494. while (added) {
  495. added = false;
  496. db.regions.forEach((r) => {
  497. if (r.parent && out.includes(r.parent) && !out.includes(r.id)) {
  498. out.push(r.id);
  499. added = true;
  500. }
  501. });
  502. }
  503. return out;
  504. }
  505. function enterprisesUnderRegion(db, id) {
  506. const ids = new Set(descendantIds(db, id));
  507. return db.enterprises.map((e, i) => i).filter((i) => ids.has(db.enterprises[i].region));
  508. }
  509. function scopeEnterpriseSet(db, scope) {
  510. const set = new Set();
  511. (scope.regions || []).forEach((rid) => enterprisesUnderRegion(db, rid).forEach((i) => set.add(i)));
  512. (scope.enterprises || []).forEach((i) => set.add(i));
  513. return set;
  514. }
  515. function scopeEnterprises(db, scope) {
  516. return Array.from(scopeEnterpriseSet(db, scope)).sort((a, b) => a - b);
  517. }
  518. function scopeSummary(db, scope) {
  519. const parts = [];
  520. (scope.regions || []).forEach((rid) => {
  521. const n = regionNode(db, rid);
  522. if (n) parts.push(`${n.name}(含下级 ${enterprisesUnderRegion(db, rid).length} 家客户)`);
  523. });
  524. const fromRegion = new Set();
  525. (scope.regions || []).forEach((rid) => enterprisesUnderRegion(db, rid).forEach((i) => fromRegion.add(i)));
  526. const extra = (scope.enterprises || []).filter((i) => !fromRegion.has(i));
  527. if (extra.length) parts.push(`直接多选:${extra.map((i) => db.enterprises[i].name).join("、")}`);
  528. return parts.length ? parts.join(";") : "(空)";
  529. }
  530. function regionReferenced(db, id) {
  531. const refs = [];
  532. db.teams.forEach((t, i) => { if ((t.scope.regions || []).includes(id)) refs.push(`运维团队「${t.name}」负责范围`); });
  533. db.partners.forEach((p, i) => {
  534. if (p.region === id) refs.push(`合伙人「${p.name}」所属区域`);
  535. if ((p.scope.regions || []).includes(id)) refs.push(`合伙人「${p.name}」负责范围`);
  536. });
  537. db.operators.forEach((o) => { if (o.region === id) refs.push(`运营商「${o.name}」所属区域`); });
  538. db.regOpsTeams.forEach((t) => { if (t.region === id) refs.push(`运营团队「${t.name}」所属区域`); });
  539. return refs;
  540. }