Skip to content

Commit 28d589c

Browse files
committed
Update user notification file
1 parent f02dd00 commit 28d589c

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed

warnusers.php

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<?php
2+
include_once 'baseInfo.php';
3+
include_once 'config.php';
4+
$time = time();
5+
6+
$stmt = $connection->prepare("SELECT * FROM `orders_list` WHERE `status`=1 AND `notif`=0");
7+
$stmt->execute();
8+
$orders = $stmt->get_result();
9+
$stmt->close();
10+
11+
if($orders){
12+
if($orders->num_rows>0){
13+
while ($order = $orders->fetch_assoc()){
14+
$send = false;
15+
$from_id = $order['userid'];
16+
$token = $order['token'];
17+
$remark = $order['remark'];
18+
$server_id = $order['server_id'];
19+
$inbound_id = $order['inbound_id'];
20+
$links_list = $order['link'];
21+
$notif = $order['notif'];
22+
$expiryTime = "";
23+
$response = getJson($server_id)->obj;
24+
foreach($response as $row){
25+
if($inbound_id == 0) {
26+
if($row->remark == $remark) {
27+
$total = $row->total;
28+
$up = $row->up;
29+
$down = $row->down;
30+
$expiryTime = $row->expiryTime;
31+
break;
32+
}
33+
}else{
34+
if($row->id == $inbound_id) {
35+
$settings = json_decode($row->settings, true);
36+
$clients = $settings['clients'];
37+
foreach($clients as $key => $client) {
38+
if($client['email'] == $remark) {
39+
$total = $client['totalGB'];
40+
break;
41+
}
42+
}
43+
44+
$clientStats = $row->clientStats;
45+
foreach($clientStats as $key => $clientStat) {
46+
if($clientStat->email == $remark) {
47+
$up = $clientStat->up;
48+
$down = $clientStat->down;
49+
$expiryTime = $clientStat->expiryTime;
50+
break;
51+
}
52+
}
53+
break;
54+
}
55+
}
56+
}
57+
$leftgb = round( ($total - $up - $down) / 1073741824, 2);
58+
$now_microdate = floor(microtime(true) * 1000);
59+
if($expiryTime != null && $total != null){
60+
if($expiryTime < $now_microdate + 86400) $send = "روز"; elseif($leftgb < 1) $send = "گیگ";
61+
if($send){
62+
$msg = "💡 کاربر گرامی،
63+
از سرویس اشتراک $remark تنها (۱ $send) باقی مانده است. میتواند از قسمت خرید های من سرویس فعلی خود را تمدید کنید یا سرویس جدید خریداری کنید
64+
65+
🚪 /start
66+
67+
";
68+
sendMessage( $msg, null, null, $from_id);
69+
$newTIme = $time + 86400 * 2;
70+
$stmt = $connection->prepare("UPDATE `orders_list` SET `notif`= ? WHERE `remark`=?");
71+
$stmt->bind_param("is", $newTIme, $remark);
72+
$stmt->execute();
73+
$stmt->close();
74+
}
75+
}
76+
}
77+
}
78+
}
79+
80+
$stmt = $connection->prepare("SELECT * FROM `orders_list` WHERE `status`=1 AND `notif` !=0");
81+
$stmt->execute();
82+
$orders = $stmt->get_result();
83+
$stmt->close();
84+
85+
if($orders){
86+
if($orders->num_rows>0){
87+
while ($order = $orders->fetch_assoc()){
88+
$send = false;
89+
$from_id = $order['userid'];
90+
$token = $order['token'];
91+
$remark = $order['remark'];
92+
$server_id = $order['server_id'];
93+
$inbound_id = $order['inbound_id'];
94+
$links_list = $order['link'];
95+
$notif = $order['notif'];
96+
97+
if($time > $notif) {
98+
$response = getJson($server_id)->obj;
99+
foreach($response as $row){
100+
if($inbound_id == 0) {
101+
if($row->remark == $remark) {
102+
$total = $row->total;
103+
$up = $row->up;
104+
$down = $row->down;
105+
$expiryTime = $row->expiryTime;
106+
break;
107+
}
108+
}else{
109+
if($row->id == $inbound_id) {
110+
$settings = json_decode($row->settings, true);
111+
$clients = $settings['clients'];
112+
foreach($clients as $key => $client) {
113+
if($client['email'] == $remark) {
114+
$total = $client['totalGB'];
115+
break;
116+
}
117+
}
118+
119+
$clientStats = $row->clientStats;
120+
foreach($clientStats as $key => $clientStat) {
121+
if($clientStat->email == $remark) {
122+
$up = $clientStat->up;
123+
$down = $clientStat->down;
124+
$expiryTime = $clientStat->expiryTime;
125+
break;
126+
}
127+
}
128+
break;
129+
}
130+
}
131+
}
132+
$leftgb = round( ($total - $up - $down) / 1073741824, 2);
133+
$now_microdate = floor(microtime(true) * 1000);
134+
if($expiryTime <= $now_microdate) $send = true; elseif($leftgb <= 0) $send = true;
135+
if($send){
136+
if($inbound_id > 0) deleteClient($server_id, $inbound_id, $remark); else deleteInbound($server_id, $remark);
137+
$msg = "💡 کاربر گرامی،
138+
اشتراک سرویس $remark منقضی شد و از لیست سفارش ها حذف گردید. لطفا از فروشگاه, سرویس جدید خریداری کنید
139+
140+
🚪 /start
141+
142+
";
143+
sendMessage( $msg, null, null, $from_id);
144+
$stmt = $connection->prepare("DELETE FROM `orders_list` WHERE `remark`=?");
145+
$stmt->bind_param("s", $remark);
146+
$stmt->execute();
147+
$stmt->close();
148+
continue;
149+
}
150+
else{
151+
$stmt = $connection->prepare("UPDATE `orders_list` SET `notif`= 0 WHERE `remark`=?");
152+
$stmt->bind_param("s", $remark);
153+
$stmt->execute();
154+
$stmt->close();
155+
}
156+
}
157+
}
158+
}
159+
}

0 commit comments

Comments
 (0)