89 lines
3.3 KiB
PHP
89 lines
3.3 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../config.php';
|
|
|
|
$db = db();
|
|
|
|
// Add columns to users table
|
|
$columns_to_add = [
|
|
'registration_ip' => 'VARCHAR(45) DEFAULT NULL',
|
|
'status' => "ENUM('normal', 'frozen') DEFAULT 'normal'",
|
|
'win_loss_control' => 'TINYINT DEFAULT 0 COMMENT "0: normal, 1: win, 2: loss"',
|
|
'kyc_rejection_reason' => 'TEXT DEFAULT NULL'
|
|
];
|
|
|
|
foreach ($columns_to_add as $column => $type) {
|
|
try {
|
|
$db->exec("ALTER TABLE users ADD COLUMN $column $type");
|
|
echo "Added column $column to users table.\n";
|
|
} catch (PDOException $e) {
|
|
echo "Column $column might already exist or error: " . $e->getMessage() . "\n";
|
|
}
|
|
}
|
|
|
|
// Create admins table
|
|
try {
|
|
$db->exec("CREATE TABLE IF NOT EXISTS admins (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
username VARCHAR(50) NOT NULL UNIQUE,
|
|
password_hash VARCHAR(255) NOT NULL,
|
|
role VARCHAR(20) DEFAULT 'admin',
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
)");
|
|
echo "Created admins table.\n";
|
|
|
|
// Check if any admin exists, if not create default
|
|
$stmt = $db->query("SELECT COUNT(*) FROM admins");
|
|
if ($stmt->fetchColumn() == 0) {
|
|
$username = 'admin';
|
|
$password = 'admin123';
|
|
$hash = password_hash($password, PASSWORD_DEFAULT);
|
|
$db->prepare("INSERT INTO admins (username, password_hash) VALUES (?, ?)")->execute([$username, $hash]);
|
|
echo "Created default admin account: admin / admin123\n";
|
|
}
|
|
} catch (PDOException $e) {
|
|
echo "Error creating admins table: " . $e->getMessage() . "\n";
|
|
}
|
|
|
|
// Create recharge/withdrawal tables if not exist
|
|
try {
|
|
$db->exec("CREATE TABLE IF NOT EXISTS finance_requests (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
user_id INT NOT NULL,
|
|
type ENUM('recharge', 'withdrawal') NOT NULL,
|
|
amount DECIMAL(20,8) NOT NULL,
|
|
symbol VARCHAR(10) DEFAULT 'USDT',
|
|
status ENUM('pending', 'approved', 'rejected') DEFAULT 'pending',
|
|
payment_method VARCHAR(50) DEFAULT NULL,
|
|
payment_details TEXT DEFAULT NULL,
|
|
rejection_reason TEXT DEFAULT NULL,
|
|
tx_hash VARCHAR(255) DEFAULT NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
)");
|
|
echo "Created finance_requests table.\n";
|
|
} catch (PDOException $e) {
|
|
echo "Error creating finance_requests table: " . $e->getMessage() . "\n";
|
|
}
|
|
|
|
// Create trading tables if not exist (binary, contract)
|
|
try {
|
|
$db->exec("CREATE TABLE IF NOT EXISTS binary_orders (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
user_id INT NOT NULL,
|
|
symbol VARCHAR(20) NOT NULL,
|
|
direction ENUM('buy', 'sell') NOT NULL,
|
|
amount DECIMAL(20,8) NOT NULL,
|
|
duration INT NOT NULL,
|
|
profit_rate DECIMAL(5,2) NOT NULL,
|
|
entry_price DECIMAL(20,8) NOT NULL,
|
|
close_price DECIMAL(20,8) DEFAULT NULL,
|
|
status ENUM('pending', 'won', 'lost', 'cancelled') DEFAULT 'pending',
|
|
control_status TINYINT DEFAULT 0 COMMENT '0: normal, 1: force win, 2: force loss',
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
end_at TIMESTAMP NULL DEFAULT NULL
|
|
)");
|
|
echo "Created binary_orders table.\n";
|
|
} catch (PDOException $e) {
|
|
echo "Error creating binary_orders table: " . $e->getMessage() . "\n";
|
|
}
|