feat: add commission settlement workflow

This commit is contained in:
Codex
2026-06-29 04:18:17 +08:00
parent 0bca1f00a9
commit 0cff0d102d
13 changed files with 1271 additions and 12 deletions

View File

@@ -208,7 +208,7 @@ async function main() {
and user_id = $2::uuid
and source_type in ('order', 'activation_code')
and (
legacy_source_id in ('SMOKE20260621', 'SMOKESELF20260621')
legacy_source_id in ('SMOKE20260621', 'SMOKESELF20260621', 'IT-COMMISSION-001')
or source_id in (
select id
from public.orders
@@ -256,6 +256,53 @@ async function main() {
[tenantId, checkoutCouponCodes],
);
await client.query(
`
delete from public.commission_settlement_items
where tenant_id = $1
and (
referrer_user_id in ($2::uuid, $3::uuid, $4::uuid)
or student_user_id in ($5::uuid, $6::uuid)
)
`,
[tenantId, ids.tenantOperatorUser, ids.tenantSalesUser, ids.tenantAgentUser, ids.user, ids.secondStudentUser],
);
await client.query(
`
delete from public.commission_settlements
where tenant_id = $1
and referrer_user_id in ($2::uuid, $3::uuid, $4::uuid)
`,
[tenantId, ids.tenantOperatorUser, ids.tenantSalesUser, ids.tenantAgentUser],
);
await client.query(
`
delete from public.tenant_commission_settings
where tenant_id = $1
`,
[tenantId],
);
await client.query(
`
delete from public.activation_codes
where tenant_id = $1
and code::text = 'IT-COMMISSION-001'
`,
[tenantId],
);
await client.query(
`
delete from public.code_batches
where tenant_id = $1
and name = '集成测试分佣批次'
`,
[tenantId],
);
await client.query(
`
delete from public.crm_webhook_queue