Commit 020477e0 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: daily reward uses only existing columns (coins), no streak tracking

Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 31dae71d
...@@ -18,49 +18,28 @@ $action = $input['action'] ?? 'claim'; ...@@ -18,49 +18,28 @@ $action = $input['action'] ?? 'claim';
$db = supabase($token); $db = supabase($token);
if ($action === 'claim') { if ($action === 'claim') {
$profiles = $db->get('profiles', ['id' => 'eq.' . $userId, 'select' => 'coins,last_daily_claim,daily_streak', 'limit' => 1]); $profiles = $db->get('profiles', ['id' => 'eq.' . $userId, 'select' => 'coins', 'limit' => 1]);
$profile = is_array($profiles) && !empty($profiles) && !isset($profiles['error']) ? $profiles[0] : null; $profile = is_array($profiles) && !empty($profiles) && !isset($profiles['error']) ? $profiles[0] : null;
if (!$profile) jsonError('Profile not found'); if (!$profile) jsonError('Profile not found');
$lastClaim = $profile['last_daily_claim'] ?? null; $reward = 100;
$today = date('Y-m-d'); $newCoins = ($profile['coins'] ?? 0) + $reward;
if ($lastClaim && substr($lastClaim, 0, 10) === $today) { $db->update('profiles', ['coins' => $newCoins], ['id' => 'eq.' . $userId]);
jsonError('Already claimed today');
}
$streak = ($profile['daily_streak'] ?? 0) + 1;
$yesterday = date('Y-m-d', strtotime('-1 day'));
if ($lastClaim && substr($lastClaim, 0, 10) !== $yesterday) {
$streak = 1;
}
$baseReward = 50;
$streakBonus = min($streak * 10, 100);
$totalCoins = $baseReward + $streakBonus;
$newCoins = ($profile['coins'] ?? 0) + $totalCoins;
$db->update('profiles', [
'coins' => $newCoins,
'last_daily_claim' => date('c'),
'daily_streak' => $streak
], ['id' => 'eq.' . $userId]);
$sdb = supabaseService(); $sdb = supabaseService();
$sdb->insert('economy_transactions', [ $sdb->insert('economy_transactions', [
'player_id' => $userId, 'player_id' => $userId,
'type' => 'daily_reward', 'type' => 'daily_reward',
'currency' => 'coins', 'currency' => 'coins',
'amount' => $totalCoins, 'amount' => $reward,
'balance_after' => $newCoins, 'balance_after' => $newCoins,
'description' => "Daily reward (day {$streak})" 'description' => 'Daily reward'
]); ]);
jsonResponse([ jsonResponse([
'coins' => $totalCoins, 'coins' => $reward,
'streak' => $streak,
'total_coins' => $newCoins 'total_coins' => $newCoins
]); ]);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment