Skip to content

Commit 03731ee

Browse files
authored
Update warnusers.php
1 parent 11a372f commit 03731ee

File tree

1 file changed

+108
-101
lines changed

1 file changed

+108
-101
lines changed

settings/warnusers.php

Lines changed: 108 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
else $warnOffset = 0;
88
$limit = 50;
99

10-
$stmt = $connection->prepare("SELECT * FROM `orders_list` WHERE `status`=1 AND `notif`=0 ORDER BY `id` ASC LIMIT ? OFFSET ?");
10+
$stmt = $connection->prepare("SELECT * FROM `orders_list` WHERE `status`=1 AND (`notif`=0 OR `notif` = -1) ORDER BY `id` ASC LIMIT ? OFFSET ?");
1111
$stmt->bind_param("ii", $limit, $warnOffset);
1212
$stmt->execute();
1313
$orders = $stmt->get_result();
@@ -26,8 +26,8 @@
2626
$links_list = $order['link'];
2727
$notif = $order['notif'];
2828
$expiryTime = "";
29-
$found = false;
30-
29+
$amount = $order['amount'];
30+
3131
$stmt = $connection->prepare("SELECT * FROM `server_config` WHERE `id` = ?");
3232
$stmt->bind_param('i', $server_id);
3333
$stmt->execute();
@@ -36,101 +36,97 @@
3636
$serverType = $serverConfig['type'];
3737
$panel_url = $serverConfig['panel_url'];
3838

39+
40+
$found = false;
41+
$logedIn = false;
42+
3943
if($serverType == "marzban"){
4044
$info = getMarzbanUser($server_id, $remark);
4145
if(isset($info->username)){
4246
$found = true;
47+
$logedIn = true;
4348
$total = $info->data_limit;
4449
$totalLeft = $total - $info->used_traffic;
4550
$expiryTime = $info->expire;
4651
$enable = $info->status == "active"?true:false;
52+
}elseif(isset($info->detail)){
53+
if($info->detail == "User not found") $logedIn = true;
4754
}
4855
}else{
49-
$response = getJson($server_id)->obj;
50-
foreach($response as $row){
51-
if($inbound_id == 0) {
52-
$clients = json_decode($row->settings)->clients;
53-
if($clients[0]->id == $uuid || $clients[0]->password == $uuid) {
54-
$found = true;
55-
$total = $row->total;
56-
$up = $row->up;
57-
$down = $row->down;
58-
$expiryTime = substr($row->expiryTime, 0, -3);
59-
break;
60-
}
61-
}else{
62-
if($row->id == $inbound_id) {
63-
$settings = json_decode($row->settings, true);
64-
$clients = $settings['clients'];
65-
66-
$clientsStates = $row->clientStats;
67-
foreach($clients as $key => $client){
68-
if($client['id'] == $uuid || $client['password'] == $uuid){
69-
$found = true;
70-
$email = $client['email'];
71-
$emails = array_column($clientsStates,'email');
72-
$emailKey = array_search($email,$emails);
73-
74-
$total = $client['totalGB'];
75-
$up = $clientsStates[$emailKey]->up;
76-
$enable = $clientsStates[$emailKey]->enable;
77-
$down = $clientsStates[$emailKey]->down;
78-
$expiryTime = substr($clientsStates[$emailKey]->expiryTime, 0, -3);
79-
break;
56+
$response = getJson($server_id);
57+
if($response->success){
58+
$response = $response->obj;
59+
$logedIn = true;
60+
foreach($response as $row){
61+
if($inbound_id == 0) {
62+
$clients = json_decode($row->settings)->clients;
63+
if($clients[0]->id == $uuid || $clients[0]->password == $uuid) {
64+
$found = true;
65+
$total = $row->total;
66+
$up = $row->up;
67+
$down = $row->down;
68+
$expiryTime = substr($row->expiryTime, 0, -3);
69+
$enable = $row->enable;
70+
break;
71+
}
72+
}else{
73+
if($row->id == $inbound_id) {
74+
$settings = json_decode($row->settings, true);
75+
$clients = $settings['clients'];
76+
77+
$clientsStates = $row->clientStats;
78+
foreach($clients as $key => $client){
79+
if($client['id'] == $uuid || $client['password'] == $uuid){
80+
$found = true;
81+
$email = $client['email'];
82+
$emails = array_column($clientsStates,'email');
83+
$emailKey = array_search($email,$emails);
84+
85+
$total = $client['totalGB'];
86+
$up = $clientsStates[$emailKey]->up;
87+
$enable = $clientsStates[$emailKey]->enable;
88+
$down = $clientsStates[$emailKey]->down;
89+
$expiryTime = substr($clientsStates[$emailKey]->expiryTime, 0, -3);
90+
break;
91+
}
8092
}
8193
}
8294
}
8395
}
96+
$totalLeft = $total - $up - $down;
8497
}
85-
$totalLeft = $total - $up - $down;
86-
}
87-
if(!$found){
88-
if($logedIn){
89-
$stmt = $connection->prepare("DELETE FROM `orders_list` WHERE `id` = ?");
90-
$stmt->bind_param('i', $id);
91-
$stmt->execute();
92-
$stmt->close();
93-
94-
$stmt = $connection->prepare("SELECT * FROM `server_info` WHERE `id` = ?");
95-
$stmt->bind_param('i', $server_id);
96-
$stmt->execute();
97-
$serverTitle = $stmt->get_result()->fetch_assoc()['title'];
98-
$stmt->close();
99-
100-
$stmt = $connection->prepare("SELECT * FROM `users` WHERE `userid` = ?");
101-
$stmt->bind_param('i', $from_id);
102-
$stmt->execute();
103-
$serverInfo = $stmt->get_result()->fetch_assoc();
104-
$stmt->close();
105-
$userName = $serverInfo['name'];
106-
107-
sendMessage( "کانفیگ $remark مربوط به کاربر $userName ($from_id) توی سرور $serverTitle نبود و از دیتابیس حذف شد", null, null, $admin);
108-
}
109-
continue;
11098
}
99+
if(!$found) continue;
111100

112101
$leftgb = round( ($totalLeft) / 1073741824, 2);
113-
if($expiryTime != null && $total != null){
102+
if($expiryTime != null && $total != null && $expiryTime >= 0 && $notif == 0){
114103
$send = "";
115104
if($expiryTime < time() + 86400) $send = "روز"; elseif($leftgb < 1) $send = "گیگ";
116105
if($send != ""){
117106
$msg = "💡 کاربر گرامی،
118107
از سرویس اشتراک $remark تنها (۱ $send) باقی مانده است. میتواند از قسمت خرید های من سرویس فعلی خود را تمدید کنید یا سرویس جدید خریداری کنید.";
119108
sendMessage( $msg, null, null, $from_id);
120-
$newTIme = $time + 86400 * 2;
121-
$stmt = $connection->prepare("UPDATE `orders_list` SET `notif`= ? WHERE `uuid`=?");
122-
$stmt->bind_param("is", $newTIme, $uuid);
109+
110+
$stmt = $connection->prepare("UPDATE `orders_list` SET `notif`= -1 WHERE `uuid`=?");
111+
$stmt->bind_param("s", $uuid);
123112
$stmt->execute();
124113
$stmt->close();
125114
}
115+
}elseif(!$enable){
116+
$newTIme = $time + 86400 * 2;
117+
118+
$stmt = $connection->prepare("UPDATE `orders_list` SET `notif`= ? WHERE `uuid`=?");
119+
$stmt->bind_param("is", $newTIme, $uuid);
120+
$stmt->execute();
121+
$stmt->close();
126122
}
127123
}
128124
file_put_contents("warnOffset.txt", $warnOffset + $limit);
129125
}else unlink('warnOffset.txt');
130126
}
131127

132128

133-
$stmt = $connection->prepare("SELECT * FROM `orders_list` WHERE `status`=1 AND `notif` !=0 AND `notif` < ? LIMIT 50");
129+
$stmt = $connection->prepare("SELECT * FROM `orders_list` WHERE `status`=1 AND `notif` > 0 AND `notif` < ? LIMIT 50");
134130
$stmt->bind_param("i", $time);
135131
$stmt->execute();
136132
$orders = $stmt->get_result();
@@ -148,7 +144,6 @@
148144
$inbound_id = $order['inbound_id'];
149145
$links_list = $order['link'];
150146
$notif = $order['notif'];
151-
$found = false;
152147

153148
$stmt = $connection->prepare("SELECT * FROM `server_config` WHERE `id` = ?");
154149
$stmt->bind_param('i', $server_id);
@@ -159,57 +154,69 @@
159154
$panel_url = $serverConfig['panel_url'];
160155

161156
$found = false;
157+
$logedIn = false;
158+
162159
if($serverType == "marzban"){
163160
$info = getMarzbanUser($server_id, $remark);
164161
if(isset($info->username)){
165162
$found = true;
163+
$logedIn = true;
166164
$total = $info->data_limit;
167165
$totalLeft = $total - $info->used_traffic;
168166
$expiryTime = $info->expire;
169167
$enable = $info->status == "active"?true:false;
168+
}elseif(isset($info->detail)){
169+
if($info->detail == "User not found") $logedIn = true;
170170
}
171171
}else{
172-
$response = getJson($server_id)->obj;
173-
foreach($response as $row){
174-
if($inbound_id == 0) {
175-
$clients = json_decode($row->settings)->clients;
176-
if($clients[0]->id == $uuid || $clients[0]->password == $uuid) {
177-
$total = $row->total;
178-
$up = $row->up;
179-
$down = $row->down;
180-
$expiryTime = substr($row->expiryTime, 0, -3);
181-
$found = true;
182-
break;
183-
}
184-
}else{
185-
if($row->id == $inbound_id) {
186-
$settings = json_decode($row->settings, true);
187-
$clients = $settings['clients'];
188-
189-
190-
$clientsStates = $row->clientStats;
191-
foreach($clients as $key => $client){
192-
if($client['id'] == $uuid || $client['password'] == $uuid){
193-
$email = $client['email'];
194-
$emails = array_column($clientsStates,'email');
195-
$emailKey = array_search($email,$emails);
196-
197-
$total = $client['totalGB'];
198-
$up = $clientsStates[$emailKey]->up;
199-
$enable = $clientsStates[$emailKey]->enable;
200-
$down = $clientsStates[$emailKey]->down;
201-
$expiryTime = substr($clientsStates[$emailKey]->expiryTime, 0, -3);
202-
$found = true;
203-
break;
172+
$response = getJson($server_id);
173+
if($response->success){
174+
$logedIn = true;
175+
$response = $response->obj;
176+
foreach($response as $row){
177+
if($inbound_id == 0) {
178+
$clients = json_decode($row->settings)->clients;
179+
if($clients[0]->id == $uuid || $clients[0]->password == $uuid) {
180+
$total = $row->total;
181+
$up = $row->up;
182+
$down = $row->down;
183+
$expiryTime = substr($row->expiryTime, 0, -3);
184+
$enable = $row->enable;
185+
$found = true;
186+
break;
187+
}
188+
}else{
189+
if($row->id == $inbound_id) {
190+
$settings = json_decode($row->settings, true);
191+
$clients = $settings['clients'];
192+
193+
194+
$clientsStates = $row->clientStats;
195+
foreach($clients as $key => $client){
196+
if($client['id'] == $uuid || $client['password'] == $uuid){
197+
$email = $client['email'];
198+
$emails = array_column($clientsStates,'email');
199+
$emailKey = array_search($email,$emails);
200+
201+
$total = $client['totalGB'];
202+
$up = $clientsStates[$emailKey]->up;
203+
$enable = $clientsStates[$emailKey]->enable;
204+
$down = $clientsStates[$emailKey]->down;
205+
$expiryTime = substr($clientsStates[$emailKey]->expiryTime, 0, -3);
206+
$found = true;
207+
break;
208+
}
204209
}
205210
}
206211
}
207-
}
208-
}
209-
$totalLeft = $total - $up - $down;
212+
}
213+
$totalLeft = $total - $up - $down;
214+
}
210215
}
216+
217+
if(!$found && !$logedIn) continue;
218+
211219
$leftgb = round( ($totalLeft) / 1073741824, 2);
212-
if(!$found) continue;
213220
if($expiryTime <= time()) $send = true; elseif($leftgb <= 0) $send = true;
214221
if($send){
215222
if($serverType == "marzban") $res = deleteMarzban($server_id, $remark);

0 commit comments

Comments
 (0)