-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.php
More file actions
179 lines (150 loc) · 5.13 KB
/
Copy pathprocess.php
File metadata and controls
179 lines (150 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
session_start();
header('Content-Type: application/json');
if (!isset($_SESSION['user'])) {
echo json_encode(['error' => 'Unauthorized']);
exit();
}
$user = $_SESSION['user'];
$user_folder = "users/" . $user . "/";
$wallet_file = $user_folder . "wallet.json";
// Initialize wallet if not exists
if (!file_exists($wallet_file)) {
if (!is_dir($user_folder)) {
mkdir($user_folder, 0755, true);
}
file_put_contents($wallet_file, json_encode(['balance' => 1000]));
}
// Load wallet data
$wallet = json_decode(file_get_contents($wallet_file), true);
$action = $_GET['action'] ?? $_POST['action'] ?? '';
// Utility: Transaction Logger
function logTransaction($folder, $type, $data) {
$logFile = $folder . $type . ".json";
$existing = file_exists($logFile) ? json_decode(file_get_contents($logFile), true) : [];
$existing[] = $data;
file_put_contents($logFile, json_encode($existing, JSON_PRETTY_PRINT));
}
// Start Bet
if ($action === 'start_bet' && isset($_GET['bet'])) {
$bet = (int)$_GET['bet'];
if ($bet > $wallet['balance']) {
echo json_encode(['error' => 'Insufficient balance']);
exit();
}
$wallet['balance'] -= $bet;
file_put_contents($wallet_file, json_encode($wallet));
echo json_encode(['balance' => $wallet['balance']]);
exit();
}
// Cashout
if ($action === 'cashout' && isset($_GET['amount'])) {
$amount = (int)$_GET['amount'];
$wallet['balance'] += $amount;
file_put_contents($wallet_file, json_encode($wallet));
logTransaction($user_folder, 'wins', [
'amount' => $amount,
'date' => date('Y-m-d H:i:s')
]);
echo json_encode([
'message' => 'Cashout successful!',
'balance' => $wallet['balance']
]);
exit();
}
// Crash
if ($action === 'crash' && isset($_GET['bet'])) {
$bet = (int)$_GET['bet'];
logTransaction($user_folder, 'losses', [
'amount' => $bet,
'date' => date('Y-m-d H:i:s')
]);
echo json_encode(['balance' => $wallet['balance']]);
exit();
}
// Withdraw (handles both UPI and Bank Transfer)
if ($action === 'withdraw') {
$amount = (int)($_POST['amount'] ?? 0);
if ($amount < 100 || $amount > $wallet['balance']) {
echo json_encode(['error' => 'Invalid or insufficient balance']);
exit();
}
$wallet['balance'] -= $amount;
file_put_contents($wallet_file, json_encode($wallet));
$method = $_POST['method'] ?? '';
if ($method === 'upi') {
$details = $_POST['upi_id'] ?? '';
} elseif ($method === 'bank') {
// Store bank details as an associative array instead of a concatenated string.
$details = [
'account_holder' => $_POST['account_holder'] ?? '',
'account_no' => $_POST['account_no'] ?? '',
'ifsc' => $_POST['ifsc'] ?? ''
];
} else {
$details = '';
}
logTransaction($user_folder, 'withdrawals', [
'amount' => $amount,
'method' => $method,
'details' => $details,
'date' => date('Y-m-d H:i:s'),
'status' => 'pending'
]);
echo json_encode([
'message' => 'Withdrawal request submitted!',
'balance' => $wallet['balance']
]);
exit();
}
// Deposit
if ($action === 'deposit') {
$amount = (int)($_POST['amount'] ?? 0);
if ($amount < 100) {
echo json_encode(['error' => 'Minimum deposit is ₹100']);
exit();
}
if (!isset($_FILES['screenshot'])) {
echo json_encode(['error' => 'Screenshot is required']);
exit();
}
$file = $_FILES['screenshot'];
// Validate file type
$allowedTypes = ['image/jpeg', 'image/png', 'image/webp'];
if (!in_array($file['type'], $allowedTypes)) {
echo json_encode(['error' => 'Only JPG, PNG, and WEBP files are allowed']);
exit();
}
// File size check
if ($file['size'] > 5 * 1024 * 1024) {
echo json_encode(['error' => 'File is too large. Max 5MB allowed.']);
exit();
}
$upload_dir = $user_folder . 'deposits/';
if (!is_dir($upload_dir)) {
mkdir($upload_dir, 0755, true);
}
$ext = pathinfo($file['name'], PATHINFO_EXTENSION);
$fileName = date('Ymd_His') . "_" . uniqid() . "." . $ext;
$targetFile = $upload_dir . $fileName;
if (!move_uploaded_file($file['tmp_name'], $targetFile)) {
echo json_encode(['error' => 'Screenshot upload failed']);
exit();
}
// Load wallet to return current balance
$wallet = json_decode(file_get_contents($wallet_file), true);
logTransaction($user_folder, 'deposits', [
'amount' => $amount,
'screenshot' => $fileName,
'date' => date('Y-m-d H:i:s')
]);
echo json_encode([
'message' => '✅ Deposit submitted! Admin will verify and update your wallet balance shortly.',
'balance' => $wallet['balance']
]);
exit();
}
// Invalid Action
echo json_encode(['error' => 'Invalid action']);
exit();
?>