Skip to content

Commit 81ffdcf

Browse files
authored
Update warnusers.php
1 parent a74dde3 commit 81ffdcf

File tree

1 file changed

+71
-54
lines changed

1 file changed

+71
-54
lines changed

settings/warnusers.php

+71-54
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
include_once '../config.php';
44
$time = time();
55

6-
$stmt = $connection->prepare("SELECT * FROM `orders_list` WHERE `status`=1 AND `notif`=0");
6+
if(file_exists("warnOffset.txt")) $warnOffset = file_get_contents("warnOffset.txt");
7+
else $warnOffset = 0;
8+
$limit = 50;
9+
10+
$stmt = $connection->prepare("SELECT * FROM `orders_list` WHERE `status`=1 AND `notif`=0 ORDER BY `id` ASC LIMIT ? OFFSET ?");
11+
$stmt->bind_param("ii", $limit, $warnOffset);
712
$stmt->execute();
813
$orders = $stmt->get_result();
914
$stmt->close();
@@ -21,9 +26,11 @@
2126
$notif = $order['notif'];
2227
$expiryTime = "";
2328
$response = getJson($server_id)->obj;
29+
$found = false;
2430
foreach($response as $row){
2531
if($inbound_id == 0) {
2632
if($row->remark == $remark) {
33+
$found = true;
2734
$total = $row->total;
2835
$up = $row->up;
2936
$down = $row->down;
@@ -36,6 +43,7 @@
3643
$clients = $settings['clients'];
3744
foreach($clients as $key => $client) {
3845
if($client['email'] == $remark) {
46+
$found = true;
3947
$total = $client['totalGB'];
4048
break;
4149
}
@@ -53,7 +61,15 @@
5361
break;
5462
}
5563
}
56-
}
64+
}
65+
if(!$found){
66+
$warnOffset--;
67+
$stmt = $connection->prepare("UPDATE `orders_list` SET `status`= 0 WHERE `remark`=?");
68+
$stmt->bind_param("s", $remark);
69+
$stmt->execute();
70+
$stmt->close();
71+
continue;
72+
}
5773
$leftgb = round( ($total - $up - $down) / 1073741824, 2);
5874
$now_microdate = floor(microtime(true) * 1000);
5975
if($expiryTime != null && $total != null){
@@ -71,10 +87,13 @@
7187
}
7288
}
7389
}
74-
}
90+
file_put_contents("warnOffset.txt", $warnOffset + $limit);
91+
}else unlink('warnOffset.txt');
7592
}
7693

77-
$stmt = $connection->prepare("SELECT * FROM `orders_list` WHERE `status`=1 AND `notif` !=0");
94+
95+
$stmt = $connection->prepare("SELECT * FROM `orders_list` WHERE `status`=1 AND `notif` !=0 AND `notif` < ? LIMIT 50");
96+
$stmt->bind_param("i", $time);
7897
$stmt->execute();
7998
$orders = $stmt->get_result();
8099
$stmt->close();
@@ -91,61 +110,59 @@
91110
$links_list = $order['link'];
92111
$notif = $order['notif'];
93112

94-
if($time > $notif) {
95-
$response = getJson($server_id)->obj;
96-
foreach($response as $row){
97-
if($inbound_id == 0) {
98-
if($row->remark == $remark) {
99-
$total = $row->total;
100-
$up = $row->up;
101-
$down = $row->down;
102-
$expiryTime = $row->expiryTime;
103-
break;
104-
}
105-
}else{
106-
if($row->id == $inbound_id) {
107-
$settings = json_decode($row->settings, true);
108-
$clients = $settings['clients'];
109-
foreach($clients as $key => $client) {
110-
if($client['email'] == $remark) {
111-
$total = $client['totalGB'];
112-
break;
113-
}
113+
$response = getJson($server_id)->obj;
114+
foreach($response as $row){
115+
if($inbound_id == 0) {
116+
if($row->remark == $remark) {
117+
$total = $row->total;
118+
$up = $row->up;
119+
$down = $row->down;
120+
$expiryTime = $row->expiryTime;
121+
break;
122+
}
123+
}else{
124+
if($row->id == $inbound_id) {
125+
$settings = json_decode($row->settings, true);
126+
$clients = $settings['clients'];
127+
foreach($clients as $key => $client) {
128+
if($client['email'] == $remark) {
129+
$total = $client['totalGB'];
130+
break;
114131
}
115-
116-
$clientStats = $row->clientStats;
117-
foreach($clientStats as $key => $clientStat) {
118-
if($clientStat->email == $remark) {
119-
$up = $clientStat->up;
120-
$down = $clientStat->down;
121-
$expiryTime = $clientStat->expiryTime;
122-
break;
123-
}
132+
}
133+
134+
$clientStats = $row->clientStats;
135+
foreach($clientStats as $key => $clientStat) {
136+
if($clientStat->email == $remark) {
137+
$up = $clientStat->up;
138+
$down = $clientStat->down;
139+
$expiryTime = $clientStat->expiryTime;
140+
break;
124141
}
125-
break;
126142
}
143+
break;
127144
}
128-
}
129-
$leftgb = round( ($total - $up - $down) / 1073741824, 2);
130-
$now_microdate = floor(microtime(true) * 1000);
131-
if($expiryTime <= $now_microdate) $send = true; elseif($leftgb <= 0) $send = true;
132-
if($send){
133-
if($inbound_id > 0) deleteClient($server_id, $inbound_id, $remark); else deleteInbound($server_id, $remark);
134-
$msg = "💡 کاربر گرامی،
135-
اشتراک سرویس $remark منقضی شد و از لیست سفارش ها حذف گردید. لطفا از فروشگاه, سرویس جدید خریداری کنید.";
136-
sendMessage( $msg, null, null, $from_id);
137-
$stmt = $connection->prepare("DELETE FROM `orders_list` WHERE `remark`=?");
138-
$stmt->bind_param("s", $remark);
139-
$stmt->execute();
140-
$stmt->close();
141-
continue;
142-
}
143-
else{
144-
$stmt = $connection->prepare("UPDATE `orders_list` SET `notif`= 0 WHERE `remark`=?");
145-
$stmt->bind_param("s", $remark);
146-
$stmt->execute();
147-
$stmt->close();
148145
}
146+
}
147+
$leftgb = round( ($total - $up - $down) / 1073741824, 2);
148+
$now_microdate = floor(microtime(true) * 1000);
149+
if($expiryTime <= $now_microdate) $send = true; elseif($leftgb <= 0) $send = true;
150+
if($send){
151+
if($inbound_id > 0) deleteClient($server_id, $inbound_id, $remark); else deleteInbound($server_id, $remark);
152+
$msg = "💡 کاربر گرامی،
153+
اشتراک سرویس $remark منقضی شد و از لیست سفارش ها حذف گردید. لطفا از فروشگاه, سرویس جدید خریداری کنید.";
154+
sendMessage( $msg, null, null, $from_id);
155+
$stmt = $connection->prepare("DELETE FROM `orders_list` WHERE `remark`=?");
156+
$stmt->bind_param("s", $remark);
157+
$stmt->execute();
158+
$stmt->close();
159+
continue;
160+
}
161+
else{
162+
$stmt = $connection->prepare("UPDATE `orders_list` SET `notif`= 0 WHERE `remark`=?");
163+
$stmt->bind_param("s", $remark);
164+
$stmt->execute();
165+
$stmt->close();
149166
}
150167
}
151168
}

0 commit comments

Comments
 (0)