Commit 31dae71d authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: daily-reward and shop use array get instead of getOne

Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent d7626367
...@@ -18,9 +18,10 @@ $action = $input['action'] ?? 'claim'; ...@@ -18,9 +18,10 @@ $action = $input['action'] ?? 'claim';
$db = supabase($token); $db = supabase($token);
if ($action === 'claim') { if ($action === 'claim') {
$profile = $db->getOne('profiles', ['id' => 'eq.' . $userId, 'select' => 'coins,last_daily_claim,daily_streak']); $profiles = $db->get('profiles', ['id' => 'eq.' . $userId, 'select' => 'coins,last_daily_claim,daily_streak', 'limit' => 1]);
$profile = is_array($profiles) && !empty($profiles) && !isset($profiles['error']) ? $profiles[0] : null;
if (!$profile || isset($profile['error'])) jsonError('Profile not found'); if (!$profile) jsonError('Profile not found');
$lastClaim = $profile['last_daily_claim'] ?? null; $lastClaim = $profile['last_daily_claim'] ?? null;
$today = date('Y-m-d'); $today = date('Y-m-d');
......
...@@ -28,10 +28,12 @@ if ($action === 'purchase') { ...@@ -28,10 +28,12 @@ if ($action === 'purchase') {
$cosmeticId = $input['cosmetic_id'] ?? ''; $cosmeticId = $input['cosmetic_id'] ?? '';
if (!$cosmeticId) jsonError('cosmetic_id required'); if (!$cosmeticId) jsonError('cosmetic_id required');
$item = $db->getOne('cosmetics', ['id' => 'eq.' . $cosmeticId]); $items = $db->get('cosmetics', ['id' => 'eq.' . $cosmeticId, 'limit' => 1]);
if (!$item || isset($item['error'])) jsonError('Item not found', 404); $item = is_array($items) && !empty($items) && !isset($items['error']) ? $items[0] : null;
if (!$item) jsonError('Item not found', 404);
$profile = $db->getOne('profiles', ['id' => 'eq.' . $userId, 'select' => 'coins,gems']); $profiles = $db->get('profiles', ['id' => 'eq.' . $userId, 'select' => 'coins,gems', 'limit' => 1]);
$profile = is_array($profiles) && !empty($profiles) ? $profiles[0] : ['coins' => 0, 'gems' => 0];
$coins = $profile['coins'] ?? 0; $coins = $profile['coins'] ?? 0;
$gems = $profile['gems'] ?? 0; $gems = $profile['gems'] ?? 0;
$priceCoin = $item['price_coins'] ?? 0; $priceCoin = $item['price_coins'] ?? 0;
......
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