data.js 45 KB

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