|
26 | 26 | $links_list = $order['link']; |
27 | 27 | $notif = $order['notif']; |
28 | 28 | $expiryTime = ""; |
29 | | - $response = getJson($server_id)->obj; |
30 | 29 | $found = false; |
31 | | - foreach($response as $row){ |
32 | | - if($inbound_id == 0) { |
33 | | - $clients = json_decode($row->settings)->clients; |
34 | | - if($clients[0]->id == $uuid || $clients[0]->password == $uuid) { |
35 | | - $found = true; |
36 | | - $total = $row->total; |
37 | | - $up = $row->up; |
38 | | - $down = $row->down; |
39 | | - $expiryTime = $row->expiryTime; |
40 | | - break; |
41 | | - } |
42 | | - }else{ |
43 | | - if($row->id == $inbound_id) { |
44 | | - $settings = json_decode($row->settings, true); |
45 | | - $clients = $settings['clients']; |
46 | | - |
47 | | - $clientsStates = $row->clientStats; |
48 | | - foreach($clients as $key => $client){ |
49 | | - if($client['id'] == $uuid || $client['password'] == $uuid){ |
50 | | - $found = true; |
51 | | - $email = $client['email']; |
52 | | - $emails = array_column($clientsStates,'email'); |
53 | | - $emailKey = array_search($email,$emails); |
54 | | - |
55 | | - $total = $client['totalGB']; |
56 | | - $up = $clientsStates[$emailKey]->up; |
57 | | - $enable = $clientsStates[$emailKey]->enable; |
58 | | - $down = $clientsStates[$emailKey]->down; |
59 | | - $expiryTime = $clientsStates[$emailKey]->expiryTime; |
60 | | - break; |
| 30 | + |
| 31 | + $stmt = $connection->prepare("SELECT * FROM `server_config` WHERE `id` = ?"); |
| 32 | + $stmt->bind_param('i', $server_id); |
| 33 | + $stmt->execute(); |
| 34 | + $serverConfig = $stmt->get_result()->fetch_assoc(); |
| 35 | + $stmt->close(); |
| 36 | + $serverType = $serverConfig['type']; |
| 37 | + $panel_url = $serverConfig['panel_url']; |
| 38 | + |
| 39 | + if($serverType == "marzban"){ |
| 40 | + $info = getMarzbanUser($server_id, $remark); |
| 41 | + if(isset($info->username)){ |
| 42 | + $found = true; |
| 43 | + $total = $info->data_limit; |
| 44 | + $totalLeft = $total - $info->used_traffic; |
| 45 | + $expiryTime = $info->expire; |
| 46 | + $enable = $info->status == "active"?true:false; |
| 47 | + } |
| 48 | + }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; |
| 80 | + } |
61 | 81 | } |
62 | 82 | } |
63 | 83 | } |
64 | 84 | } |
| 85 | + $totalLeft = $total - $up - $down; |
65 | 86 | } |
66 | 87 | if(!$found) continue; |
67 | 88 |
|
68 | | - $leftgb = round( ($total - $up - $down) / 1073741824, 2); |
69 | | - $now_microdate = floor(microtime(true) * 1000); |
| 89 | + $leftgb = round( () / 1073741824, 2); |
70 | 90 | if($expiryTime != null && $total != null){ |
71 | 91 | $send = ""; |
72 | | - if($expiryTime < $now_microdate + 86400000) $send = "روز"; elseif($leftgb < 1) $send = "گیگ"; |
| 92 | + if($expiryTime < time() + 86400000) $send = "روز"; elseif($leftgb < 1) $send = "گیگ"; |
73 | 93 | if($send != ""){ |
74 | 94 | $msg = "💡 کاربر گرامی، |
75 | 95 | از سرویس اشتراک $remark تنها (۱ $send) باقی مانده است. میتواند از قسمت خرید های من سرویس فعلی خود را تمدید کنید یا سرویس جدید خریداری کنید."; |
|
105 | 125 | $inbound_id = $order['inbound_id']; |
106 | 126 | $links_list = $order['link']; |
107 | 127 | $notif = $order['notif']; |
| 128 | + $found = false; |
108 | 129 |
|
109 | | - $response = getJson($server_id)->obj; |
| 130 | + $stmt = $connection->prepare("SELECT * FROM `server_config` WHERE `id` = ?"); |
| 131 | + $stmt->bind_param('i', $server_id); |
| 132 | + $stmt->execute(); |
| 133 | + $serverConfig = $stmt->get_result()->fetch_assoc(); |
| 134 | + $stmt->close(); |
| 135 | + $serverType = $serverConfig['type']; |
| 136 | + $panel_url = $serverConfig['panel_url']; |
| 137 | + |
110 | 138 | $found = false; |
111 | | - foreach($response as $row){ |
112 | | - if($inbound_id == 0) { |
113 | | - $clients = json_decode($row->settings)->clients; |
114 | | - if($clients[0]->id == $uuid || $clients[0]->password == $uuid) { |
115 | | - $total = $row->total; |
116 | | - $up = $row->up; |
117 | | - $down = $row->down; |
118 | | - $expiryTime = $row->expiryTime; |
119 | | - $found = true; |
120 | | - break; |
121 | | - } |
122 | | - }else{ |
123 | | - if($row->id == $inbound_id) { |
124 | | - $settings = json_decode($row->settings, true); |
125 | | - $clients = $settings['clients']; |
126 | | - |
127 | | - |
128 | | - $clientsStates = $row->clientStats; |
129 | | - foreach($clients as $key => $client){ |
130 | | - if($client['id'] == $uuid || $client['password'] == $uuid){ |
131 | | - $email = $client['email']; |
132 | | - $emails = array_column($clientsStates,'email'); |
133 | | - $emailKey = array_search($email,$emails); |
134 | | - |
135 | | - $total = $client['totalGB']; |
136 | | - $up = $clientsStates[$emailKey]->up; |
137 | | - $enable = $clientsStates[$emailKey]->enable; |
138 | | - $down = $clientsStates[$emailKey]->down; |
139 | | - $expiryTime = $clientsStates[$emailKey]->expiryTime; |
140 | | - $found = true; |
141 | | - break; |
| 139 | + if($serverType == "marzban"){ |
| 140 | + $info = getMarzbanUser($server_id, $remark); |
| 141 | + if(isset($info->username)){ |
| 142 | + $found = true; |
| 143 | + $total = $info->data_limit; |
| 144 | + $totalLeft = $total - $info->used_traffic; |
| 145 | + $expiryTime = $info->expire; |
| 146 | + $enable = $info->status == "active"?true:false; |
| 147 | + } |
| 148 | + }else{ |
| 149 | + $response = getJson($server_id)->obj; |
| 150 | + foreach($response as $row){ |
| 151 | + if($inbound_id == 0) { |
| 152 | + $clients = json_decode($row->settings)->clients; |
| 153 | + if($clients[0]->id == $uuid || $clients[0]->password == $uuid) { |
| 154 | + $total = $row->total; |
| 155 | + $up = $row->up; |
| 156 | + $down = $row->down; |
| 157 | + $expiryTime = substr($row->expiryTime, 0, -3); |
| 158 | + $found = true; |
| 159 | + break; |
| 160 | + } |
| 161 | + }else{ |
| 162 | + if($row->id == $inbound_id) { |
| 163 | + $settings = json_decode($row->settings, true); |
| 164 | + $clients = $settings['clients']; |
| 165 | + |
| 166 | + |
| 167 | + $clientsStates = $row->clientStats; |
| 168 | + foreach($clients as $key => $client){ |
| 169 | + if($client['id'] == $uuid || $client['password'] == $uuid){ |
| 170 | + $email = $client['email']; |
| 171 | + $emails = array_column($clientsStates,'email'); |
| 172 | + $emailKey = array_search($email,$emails); |
| 173 | + |
| 174 | + $total = $client['totalGB']; |
| 175 | + $up = $clientsStates[$emailKey]->up; |
| 176 | + $enable = $clientsStates[$emailKey]->enable; |
| 177 | + $down = $clientsStates[$emailKey]->down; |
| 178 | + $expiryTime = substr($clientsStates[$emailKey]->expiryTime, 0, -3); |
| 179 | + $found = true; |
| 180 | + break; |
| 181 | + } |
142 | 182 | } |
143 | 183 | } |
144 | 184 | } |
145 | | - } |
146 | | - } |
| 185 | + } |
| 186 | + $totalLeft = $total - $up - $down; |
| 187 | + } |
| 188 | + $leftgb = round( ($totalLeft) / 1073741824, 2); |
147 | 189 | if(!$found) continue; |
148 | | - $leftgb = round( ($total - $up - $down) / 1073741824, 2); |
149 | | - $now_microdate = floor(microtime(true) * 1000); |
150 | | - if($expiryTime <= $now_microdate) $send = true; elseif($leftgb <= 0) $send = true; |
151 | | - if($send){ |
152 | | - if($inbound_id > 0) $res = deleteClient($server_id, $inbound_id, $uuid, 1); else $res = deleteInbound($server_id, $uuid, 1); |
| 190 | + if($expiryTime <= time()) $send = true; elseif($leftgb <= 0) $send = true; |
| 191 | + if($send){ |
| 192 | + if($serverType == "marzban") $res = deleteMarzban($server_id, $remark); |
| 193 | + else{if($inbound_id > 0) $res = deleteClient($server_id, $inbound_id, $uuid, 1); else $res = deleteInbound($server_id, $uuid, 1); } |
153 | 194 | if(!is_null($res)){ |
154 | 195 | $msg = "💡 کاربر گرامی، |
155 | 196 | اشتراک سرویس $remark منقضی شد و از لیست سفارش ها حذف گردید. لطفا از فروشگاه, سرویس جدید خریداری کنید."; |
|
0 commit comments