db = $db; } public function index() { $this->checkLogin(); $this->checkAdmin(); $gameId = $this->getGameId(); $configs = $this->db->select('water_control', '*', ['game_id' => $gameId]); $limits = $this->db->select('bet_limits', '*', ['game_id' => $gameId]); $targetProfitRate = \App\Core\SettingsHelper::get('target_profit_rate'); $this->render('Admin/water_control.php', compact('configs', 'limits', 'gameId', 'targetProfitRate')); } public function updateWater() { $this->checkLogin(); $this->checkAdmin(); $data = json_decode(file_get_contents('php://input'), true); foreach ($data['items'] ?? [] as $item) { $existing = $this->db->get('water_control', 'id', [ 'game_id' => (int)$item['game_id'], 'bet_type' => $item['bet_type'] ]); $fields = [ 'win_rate_pct' => floatval($item['win_rate_pct']), 'enabled' => (int)($item['enabled'] ?? 0), ]; if ($existing) { $this->db->update('water_control', $fields, ['id' => $existing]); } else { $fields['game_id'] = (int)$item['game_id']; $fields['bet_type'] = $item['bet_type']; $this->db->insert('water_control', $fields); } } $this->json(['status' => 'success']); } public function updateLimits() { $this->checkLogin(); $this->checkAdmin(); $data = json_decode(file_get_contents('php://input'), true); foreach ($data['items'] ?? [] as $item) { $existing = $this->db->get('bet_limits', 'id', [ 'game_id' => (int)$item['game_id'], 'bet_type' => $item['bet_type'] ]); $fields = [ 'min_amount' => floatval($item['min_amount']), 'max_amount' => floatval($item['max_amount']), 'max_per_period' => floatval($item['max_per_period'] ?? 500000), ]; if ($existing) { $this->db->update('bet_limits', $fields, ['id' => $existing]); } else { $fields['game_id'] = (int)$item['game_id']; $fields['bet_type'] = $item['bet_type']; $this->db->insert('bet_limits', $fields); } } $this->json(['status' => 'success']); } public function updateProfitRate() { $this->checkLogin(); $this->checkAdmin(); $data = json_decode(file_get_contents('php://input'), true); $rate = isset($data['target_profit_rate']) ? floatval($data['target_profit_rate']) : 15; if ($rate < 0 || $rate > 100) { $this->json(['status' => 'error', 'message' => '盈利率必须在0-100之间']); return; } $db = $this->db; $existing = $db->get('system_settings', 'id', ['setting_key' => 'target_profit_rate']); if ($existing) { $db->update('system_settings', ['setting_value' => (string)$rate], ['id' => $existing]); } else { $db->insert('system_settings', ['setting_key' => 'target_profit_rate', 'setting_value' => (string)$rate]); } \App\Core\SettingsHelper::clearCache(); $this->json(['status' => 'success']); } private function getGameId(): int { if (!empty($_GET['game_id'])) return (int)$_GET['game_id']; return (int)($this->db->get('games', 'id', ['code' => 'pk10']) ?: 0); } private function json($d) { header('Content-Type: application/json'); echo json_encode($d); } }