fix: remove incorrect TEAM_BONUS records given to uplines

TEAM_BONUS should only be given to the adopter themselves, not to their
uplines. This migration deletes all TEAM_BONUS records where
account_sequence != source_account_sequence.

Also updates contribution_accounts totals in contribution-service.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-12 09:49:44 -08:00
parent fe332fdb3f
commit e71f2aadfc
2 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,35 @@
-- 清理错误的 TEAM_BONUS 记录
-- TEAM_BONUS 只应该给认种人自己,即 account_sequence == source_account_sequence
-- 删除那些 account_sequence != source_account_sequence 的 TEAM_BONUS 记录
DELETE FROM contribution_records
WHERE source_type = 'TEAM_BONUS'
AND account_sequence != source_account_sequence;
-- 同时需要更新 contribution_accounts 表中的 team_bonus_contribution 统计
-- 重新计算每个账户的 team_bonus_contribution
UPDATE contribution_accounts ca
SET team_bonus_contribution = COALESCE(
(SELECT SUM(amount)
FROM contribution_records cr
WHERE cr.account_sequence = ca.account_sequence
AND cr.source_type = 'TEAM_BONUS'
AND cr.is_expired = false),
0
),
total_contribution = personal_contribution + team_level_contribution + COALESCE(
(SELECT SUM(amount)
FROM contribution_records cr
WHERE cr.account_sequence = ca.account_sequence
AND cr.source_type = 'TEAM_BONUS'
AND cr.is_expired = false),
0
),
effective_contribution = personal_contribution + team_level_contribution + COALESCE(
(SELECT SUM(amount)
FROM contribution_records cr
WHERE cr.account_sequence = ca.account_sequence
AND cr.source_type = 'TEAM_BONUS'
AND cr.is_expired = false),
0
);

View File

@ -0,0 +1,7 @@
-- 清理错误的 TEAM_BONUS 记录
-- TEAM_BONUS 只应该给认种人自己,即 account_sequence == source_account_sequence
-- 删除那些 account_sequence != source_account_sequence 的 TEAM_BONUS 记录
DELETE FROM synced_contribution_records
WHERE source_type = 'TEAM_BONUS'
AND account_sequence != source_account_sequence;