add point totalConsumed

This commit is contained in:
Timi
2026-08-22 11:45:00 +08:00
parent 376f0ecd05
commit 3c56e21efa
7 changed files with 28 additions and 7 deletions
@@ -0,0 +1,13 @@
ALTER TABLE `gao_point_account`
ADD COLUMN `total_consumed` BIGINT NOT NULL DEFAULT 0 COMMENT '累计消耗积分' AFTER `total_earned`;
UPDATE `gao_point_account` account
LEFT JOIN (
SELECT `account_id`, SUM(-`point_delta`) AS `total_consumed`
FROM `gao_point_ledger`
WHERE `change_type` = 'CONSUME'
AND `point_delta` < 0
AND `deleted_at` IS NULL
GROUP BY `account_id`
) ledger ON ledger.`account_id` = account.`id`
SET account.`total_consumed` = COALESCE(ledger.`total_consumed`, 0);