-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_wallets.sql
More file actions
28 lines (22 loc) · 920 Bytes
/
sync_wallets.sql
File metadata and controls
28 lines (22 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
USE stream_team;
-- =======================================================
-- 🕓 Script de synchronisation automatique des Team Coins
-- Compatible avec secure-file-priv
-- =======================================================
-- 1️⃣ Synchroniser les soldes des portefeuilles
UPDATE streamer_wallets sw
JOIN (
SELECT streamer_id, COALESCE(SUM(amount),0) AS total
FROM team_coins_transactions
GROUP BY streamer_id
) t ON sw.streamer_id = t.streamer_id
SET sw.balance = t.total;
SET @wallets_updated := ROW_COUNT();
-- 2️⃣ Synchroniser les niveaux
UPDATE streamer_levels sl
JOIN streamer_wallets sw ON sl.streamer_id = sw.streamer_id
SET sl.team_coins = sw.balance;
SET @levels_updated := ROW_COUNT();
-- 3️⃣ Ajouter un log en base
INSERT INTO wallet_sync_log (updated_wallets, updated_levels, comment)
VALUES (@wallets_updated, @levels_updated, CONCAT('Synchro automatique cron - ', NOW()));