70 lines
2.7 KiB
PHP
70 lines
2.7 KiB
PHP
<?php
|
|
namespace App\Controllers\Admin;
|
|
|
|
use App\Core\AdminBaseController;
|
|
use Db\Database;
|
|
|
|
class WaterController extends AdminBaseController {
|
|
private $db;
|
|
public function __construct(Database $db) { $this->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]);
|
|
$this->render('Admin/water_control.php', compact('configs', 'limits', 'gameId'));
|
|
}
|
|
|
|
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']);
|
|
}
|
|
|
|
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); }
|
|
}
|