feat: 项目层级树+合作方绑定KOC资源+客户群全量可选+精简编辑表单,移除复盘报表

- 项目支持父子层级:树形折叠展示、详情面板内联管理总群成员、推送聚合子项目任务、环检测与子项目删除守卫
- 外部KOC合作方绑定 KOC 资源账号(唯一占用、换绑/解绑、资源页一键设为合作方),列表直显联系方式
- 绑定客户群改为全量外部群缓存(含各群主),同步按钮强刷;member_count 缺失以 member_list 兜底
- 任务/项目编辑模式隐藏不可变字段(平台/内容类型/品牌/总群成员),详情面板维护成员时保留 parent_id
- 删除复盘报表整栏(导航/页面/task_report_list/导出路由/CSV lib 及测试)
This commit is contained in:
ABAPPLO
2026-09-23 11:13:17 +08:00
parent 8f1ebf7697
commit ab78b187c0
20 changed files with 1354 additions and 958 deletions

View File

@@ -0,0 +1,91 @@
import assert from "node:assert/strict";
import test from "node:test";
import { readFileSync } from "node:fs";
const actionRoute = readFileSync(
new URL("../app/api/action/route.ts", import.meta.url),
"utf8",
);
const mvpDb = readFileSync(
new URL("../lib/mvp-db.ts", import.meta.url),
"utf8",
);
const adminApp = readFileSync(
new URL("../app/admin-app.tsx", import.meta.url),
"utf8",
);
const migration = readFileSync(
new URL("../mysql/0018_partner_resource_binding.sql", import.meta.url),
"utf8",
);
function section(source, action) {
const start = source.indexOf(`"${action}"`);
assert.ok(start >= 0, `action ${action} 不存在于路由源码`);
const next = source.indexOf("} else if (body.action ===", start);
return source.slice(start, next === -1 ? undefined : next);
}
test("partner_bind_account enforces one partner per resource account", () => {
const body = section(actionRoute, "partner_bind_account");
assert.match(
body,
/SELECT id, name FROM partners WHERE account_id = \? AND id != \? LIMIT 1/,
"绑定前必须检查资源账号是否已被其它合作方占用",
);
assert.match(body, /该 KOC 资源已绑定合作方/, "占用时返回可读错误");
assert.match(
body,
/UPDATE partners SET account_id = '' WHERE id = \?/,
"空 accountId 表示解绑",
);
assert.match(body, /群主合作方不绑定 KOC 资源/);
});
test("partner_create_from_account creates external_koc bound to account", () => {
const body = section(actionRoute, "partner_create_from_account");
assert.match(
body,
/SELECT id, name FROM partners WHERE account_id = \? LIMIT 1/,
"一键创建前必须确认资源未被绑定",
);
assert.match(
body,
/partner-koc-/,
"合作方 id 使用 partner-koc- 前缀,避免与领取流程冲突",
);
assert.match(body, /'external_koc'/);
assert.match(
body,
/INSERT INTO partners[\s\S]*account_id[\s\S]*VALUES/,
"INSERT 必须写入 account_id",
);
});
test("dashboard partners query joins accounts for contact display", () => {
assert.match(
mvpDb,
/FROM partners p\s+LEFT JOIN accounts a ON a\.id = p\.account_id/,
"partners 列表需带出资源昵称与联系方式",
);
assert.match(mvpDb, /a\.current_contact AS account_contact/);
assert.match(
mvpDb,
/ensureColumn\(\s*"partners",\s*"account_id"/,
"自托管路径也要补 account_id 列",
);
});
test("migration 0018 adds partners.account_id with index", () => {
assert.match(migration, /ADD COLUMN `account_id`/);
assert.match(migration, /partners_account_idx/);
});
test("admin app renders resource binding affordances", () => {
assert.match(adminApp, /partner_bind_account/);
assert.match(adminApp, /partner_create_from_account/);
assert.match(adminApp, /绑定资源/, "未绑合作方有绑定入口");
assert.match(adminApp, /换绑/, "已绑合作方可换绑");
assert.match(adminApp, /解绑中…/, "已绑合作方可解绑");
assert.match(adminApp, /设为合作方/, "资源页支持一键创建合作方");
});