checkWebLogin(); I18n::init(); $db = new Database(); $userId = $this->getCurrentUserId(); $user = $db->get('users', ['id','username','balance','lang'], ['id' => $userId]); $game = $db->get('games', '*', ['code' => 'pk10', 'status' => 1]); extract([ 'user' => $user ?: ['id' => $userId, 'username' => $this->getCurrentUsername(), 'balance' => 0], 'game' => $game, ]); include __DIR__ . '/../../Views/Web/home.php'; } public function pk10Game() { $this->checkWebLogin(); I18n::init(); $db = new Database(); $userId = $this->getCurrentUserId(); $user = $db->get('users', ['id','username','balance','lang'], ['id' => $userId]); $game = $db->get('games', '*', ['code' => 'pk10', 'status' => 1]); $isAgent = !!$db->get('agents', 'id', ['user_id' => $userId, 'status' => 1]); // 加载赔率(优先代理专属赔率,否则用游戏默认赔率) $gameId = $game['id'] ?? 0; $oddsRaw = $db->select('game_odds', '*', ['game_id' => $gameId]); $oddsMap = []; foreach ($oddsRaw as $o) { $oddsMap[$o['type'] . '_' . $o['target']] = (float)$o['odds']; } // 代理专属赔率覆盖 $agentId = $db->get('agents', 'id', ['user_id' => $userId, 'status' => 1]); if ($agentId) { $agentOdds = $db->select('agent_odds', '*', ['agent_id' => $agentId, 'game_id' => $gameId]); foreach ($agentOdds as $ao) { $oddsMap[$ao['bet_type'] . '_' . $ao['bet_target']] = (float)$ao['odds']; } } extract([ 'user' => $user ?: ['id' => $userId, 'username' => $this->getCurrentUsername(), 'balance' => 0], 'game' => $game, 'isAgent' => !!$agentId, 'oddsMap' => $oddsMap, ]); include __DIR__ . '/../../Views/Web/pk10.php'; } public function profile() { $this->checkWebLogin(); I18n::init(); $db = new Database(); $userId = $this->getCurrentUserId(); $user = $db->get('users', '*', ['id' => $userId]); // 最近交易 $transactions = $db->select('transactions', '*', [ 'user_id' => $userId, 'is_virtual' => 0, 'ORDER' => ['id' => 'DESC'], 'LIMIT' => 20 ]); // 最近投注 $bets = $db->select('bets', '*', [ 'user_id' => $userId, 'ORDER' => ['id' => 'DESC'], 'LIMIT' => 20 ]); // 充提记录 $fundRequests = $db->select('fund_requests', '*', [ 'user_id' => $userId, 'ORDER' => ['id' => 'DESC'], 'LIMIT' => 20 ]); extract(compact('user', 'transactions', 'bets', 'fundRequests')); include __DIR__ . '/../../Views/Web/profile.php'; } public function bindUsdt() { $this->checkWebLogin(); header('Content-Type: application/json'); $db = new Database(); $userId = $this->getCurrentUserId(); $data = json_decode(file_get_contents('php://input'), true); $address = trim($data['usdt_address'] ?? ''); // TRC20地址验证: 以T开头, 34字符, base58 if (!preg_match('/^T[1-9A-HJ-NP-Za-km-z]{33}$/', $address)) { echo json_encode(['success' => false, 'message' => 'Invalid TRC20 address']); return; } // 唯一性 $exists = $db->get('users', 'id', ['usdt_address' => $address, 'id[!]' => $userId]); if ($exists) { echo json_encode(['success' => false, 'message' => 'Address already bound to another account']); return; } $db->update('users', ['usdt_address' => $address, 'usdt_chain' => 'TRC20'], ['id' => $userId]); echo json_encode(['success' => true, 'message' => 'Address bound successfully']); } public function setLang() { header('Content-Type: application/json'); $data = json_decode(file_get_contents('php://input'), true); $lang = $data['lang'] ?? 'en'; if (isset(I18n::LANGUAGES[$lang])) { $_SESSION['lang'] = $lang; setcookie('lang', $lang, time() + 86400 * 365, '/'); $db = new Database(); $userId = $this->getCurrentUserId(); if ($userId) $db->update('users', ['lang' => $lang], ['id' => $userId]); echo json_encode(['success' => true]); } else { echo json_encode(['success' => false, 'message' => 'Invalid language']); } } public function lottery() { $this->checkWebLogin(); I18n::init(); $db = new Database(); $gameCode = $_GET['game'] ?? 'pk10'; $game = $db->get('games', '*', ['code' => $gameCode, 'status' => 1]); if (!$game) $game = $db->get('games', '*', ['code' => 'pk10', 'status' => 1]); $gameId = $game['id'] ?? 0; $gameType = $game['type'] ?? 'pk10'; $algoClass = \App\Core\GameFactory::getAlgorithm($gameType); $resultTable = $algoClass::getResultTable(); $periods = $db->select('periods', '*', [ 'game_id' => $gameId, 'status' => 'settled', 'ORDER' => ['id' => 'DESC'], 'LIMIT' => 50 ]); foreach ($periods as &$p) { if ($resultTable) { $pk = $db->get($resultTable, '*', ['period_id' => $p['id']]); if ($pk) { foreach ($pk as $k => $v) $p[$k] = $v; } } } unset($p); extract(compact('game', 'periods')); include __DIR__ . '/../../Views/Web/lottery.php'; } public function pk10Stats() { $this->checkWebLogin(); I18n::init(); $db = new Database(); $game = $db->get('games', '*', ['code' => 'pk10', 'status' => 1]); $gameId = $game['id'] ?? 0; // 最近100期已结算结果 $periods = $db->select('periods', ['id','period_number'], [ 'game_id' => $gameId, 'status' => 'settled', 'ORDER' => ['id' => 'DESC'], 'LIMIT' => 100 ]); $results = []; foreach ($periods as $p) { $pk = $db->get('pk10_results', '*', ['period_id' => $p['id']]); if ($pk) { $pk['period_number'] = $p['period_number']; $results[] = $pk; } } extract(compact('game', 'results')); include __DIR__ . '/../../Views/Web/pk10_stats.php'; } public function details() { $this->checkWebLogin(); I18n::init(); $db = new Database(); $userId = $this->getCurrentUserId(); $settled = $db->select('bets', '*', [ 'user_id' => $userId, 'status[!]' => 'pending', 'ORDER' => ['id' => 'DESC'], 'LIMIT' => 50 ]); $pending = $db->select('bets', '*', [ 'user_id' => $userId, 'status' => 'pending', 'ORDER' => ['id' => 'DESC'], 'LIMIT' => 50 ]); extract(compact('settled', 'pending')); include __DIR__ . '/../../Views/Web/details.php'; } }