|
7 | 7 | else $warnOffset = 0; |
8 | 8 | $limit = 50; |
9 | 9 |
|
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 ?"); |
11 | 11 | $stmt->bind_param("ii", $limit, $warnOffset); |
12 | 12 | $stmt->execute(); |
13 | 13 | $orders = $stmt->get_result(); |
|
26 | 26 | $links_list = $order['link']; |
27 | 27 | $notif = $order['notif']; |
28 | 28 | $expiryTime = ""; |
29 | | - $found = false; |
30 | | - |
| 29 | + $amount = $order['amount']; |
| 30 | + |
31 | 31 | $stmt = $connection->prepare("SELECT * FROM `server_config` WHERE `id` = ?"); |
32 | 32 | $stmt->bind_param('i', $server_id); |
33 | 33 | $stmt->execute(); |
|
36 | 36 | $serverType = $serverConfig['type']; |
37 | 37 | $panel_url = $serverConfig['panel_url']; |
38 | 38 |
|
| 39 | + |
| 40 | + $found = false; |
| 41 | + $logedIn = false; |
| 42 | + |
39 | 43 | if($serverType == "marzban"){ |
40 | 44 | $info = getMarzbanUser($server_id, $remark); |
41 | 45 | if(isset($info->username)){ |
42 | 46 | $found = true; |
| 47 | + $logedIn = true; |
43 | 48 | $total = $info->data_limit; |
44 | 49 | $totalLeft = $total - $info->used_traffic; |
45 | 50 | $expiryTime = $info->expire; |
46 | 51 | $enable = $info->status == "active"?true:false; |
| 52 | + }elseif(isset($info->detail)){ |
| 53 | + if($info->detail == "User not found") $logedIn = true; |
47 | 54 | } |
48 | 55 | }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 | + } |
80 | 92 | } |
81 | 93 | } |
82 | 94 | } |
83 | 95 | } |
| 96 | + $totalLeft = $total - $up - $down; |
84 | 97 | } |
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; |
110 | 98 | } |
| 99 | + if(!$found) continue; |
111 | 100 |
|
112 | 101 | $leftgb = round( ($totalLeft) / 1073741824, 2); |
113 | | - if($expiryTime != null && $total != null){ |
| 102 | + if($expiryTime != null && $total != null && $expiryTime >= 0 && $notif == 0){ |
114 | 103 | $send = ""; |
115 | 104 | if($expiryTime < time() + 86400) $send = "روز"; elseif($leftgb < 1) $send = "گیگ"; |
116 | 105 | if($send != ""){ |
117 | 106 | $msg = "💡 کاربر گرامی، |
118 | 107 | از سرویس اشتراک $remark تنها (۱ $send) باقی مانده است. میتواند از قسمت خرید های من سرویس فعلی خود را تمدید کنید یا سرویس جدید خریداری کنید."; |
119 | 108 | 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); |
123 | 112 | $stmt->execute(); |
124 | 113 | $stmt->close(); |
125 | 114 | } |
| 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(); |
126 | 122 | } |
127 | 123 | } |
128 | 124 | file_put_contents("warnOffset.txt", $warnOffset + $limit); |
129 | 125 | }else unlink('warnOffset.txt'); |
130 | 126 | } |
131 | 127 |
|
132 | 128 |
|
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"); |
134 | 130 | $stmt->bind_param("i", $time); |
135 | 131 | $stmt->execute(); |
136 | 132 | $orders = $stmt->get_result(); |
|
148 | 144 | $inbound_id = $order['inbound_id']; |
149 | 145 | $links_list = $order['link']; |
150 | 146 | $notif = $order['notif']; |
151 | | - $found = false; |
152 | 147 |
|
153 | 148 | $stmt = $connection->prepare("SELECT * FROM `server_config` WHERE `id` = ?"); |
154 | 149 | $stmt->bind_param('i', $server_id); |
|
159 | 154 | $panel_url = $serverConfig['panel_url']; |
160 | 155 |
|
161 | 156 | $found = false; |
| 157 | + $logedIn = false; |
| 158 | + |
162 | 159 | if($serverType == "marzban"){ |
163 | 160 | $info = getMarzbanUser($server_id, $remark); |
164 | 161 | if(isset($info->username)){ |
165 | 162 | $found = true; |
| 163 | + $logedIn = true; |
166 | 164 | $total = $info->data_limit; |
167 | 165 | $totalLeft = $total - $info->used_traffic; |
168 | 166 | $expiryTime = $info->expire; |
169 | 167 | $enable = $info->status == "active"?true:false; |
| 168 | + }elseif(isset($info->detail)){ |
| 169 | + if($info->detail == "User not found") $logedIn = true; |
170 | 170 | } |
171 | 171 | }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 | + } |
204 | 209 | } |
205 | 210 | } |
206 | 211 | } |
207 | | - } |
208 | | - } |
209 | | - $totalLeft = $total - $up - $down; |
| 212 | + } |
| 213 | + $totalLeft = $total - $up - $down; |
| 214 | + } |
210 | 215 | } |
| 216 | + |
| 217 | + if(!$found && !$logedIn) continue; |
| 218 | + |
211 | 219 | $leftgb = round( ($totalLeft) / 1073741824, 2); |
212 | | - if(!$found) continue; |
213 | 220 | if($expiryTime <= time()) $send = true; elseif($leftgb <= 0) $send = true; |
214 | 221 | if($send){ |
215 | 222 | if($serverType == "marzban") $res = deleteMarzban($server_id, $remark); |
|
0 commit comments