|
1 | 1 | <?php |
2 | | -require 'config.php'; |
3 | | -require 'core.php'; |
| 2 | +include_once 'baseInfo.php'; |
| 3 | +include_once 'config.php'; |
| 4 | +$time = time(); |
4 | 5 |
|
5 | | -$hourLeft = 24; |
6 | | -$mbLeft = 1000; |
7 | | - |
8 | | -$offset = 0; |
9 | | -if(file_exists("offset.txt")){ |
10 | | - $offset = file_get_contents("offset.txt"); |
11 | | -} |
12 | | -$stmt = $connection->prepare("SELECT * FROM `user` WHERE `uuid` IS NOT NULL AND (UNIX_TIMESTAMP() > `warned` OR `warned` IS NULL) LIMIT 30 OFFSET ? "); |
13 | | -$stmt->bind_param("i", $offset); |
| 6 | +$stmt = $connection->prepare("SELECT * FROM `orders_list` WHERE `status`=1 AND `notif`=0"); |
14 | 7 | $stmt->execute(); |
15 | | -$usersList = $stmt->get_result(); |
16 | | - |
17 | | -while($rowUser = $usersList->fetch_assoc()){ |
18 | | - $userId = $rowUser['id']; |
19 | | - $uuid = $rowUser['uuid']; |
20 | | - $warned = $rowUser['warned']; |
21 | | - |
22 | | - if($uuid != null && $warned != "true"){ |
23 | | - $server = $rowUser['sub_server']; |
24 | | - |
25 | | - $serversList = $connection->query("SELECT * FROM `servers` WHERE `server_ip` = '{$server}'"); |
26 | | - $row = $serversList->fetch_assoc(); |
27 | | - $serverIp = $row['server_ip']; |
28 | | - $serverName = $row['user_name']; |
29 | | - $serverPass = $row['password']; |
| 8 | +$orders = $stmt->get_result(); |
| 9 | +$stmt->close(); |
30 | 10 |
|
31 | | - $response = getJson($serverIp, $serverName, $serverPass, $userId); |
32 | | - if($response['success']){ |
33 | | - $list = $response['obj']; |
34 | | - if($uuid != null){ |
35 | | - if(!isset($list[0]['clientStats'])){ |
36 | | - foreach($list as $keys=>$packageInfo){ |
37 | | - if(strpos($packageInfo['settings'], $uuid)!=false){ |
38 | | - $upload = $packageInfo['up']; |
39 | | - $download = $packageInfo['down']; |
40 | | - $totalUsed = $packageInfo['up'] + $packageInfo['down']; |
41 | | - $total = $packageInfo['total']; |
42 | | - $expiryTime = substr($packageInfo['expiryTime'],0,-3); |
43 | | - $remark = $packageInfo['remark']; |
44 | | - $port = $packageInfo['port']; |
45 | | - } |
46 | | - } |
47 | | - }else{ |
48 | | - $keys = -1; |
49 | | - $settings = array_column($list,'settings'); |
50 | | - foreach($settings as $key => $value){ |
51 | | - if(strpos($value, $uuid)!= false){ |
52 | | - $keys = $key; |
53 | | - break; |
54 | | - } |
55 | | - } |
56 | | - $clientsSettings = json_decode($list[$keys]['settings'],true)['clients']; |
57 | | - if(!is_array($clientsSettings)){ |
58 | | - exit(); |
| 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 | + $response = getJson($server_id)->obj; |
| 23 | + foreach($response as $row){ |
| 24 | + if($inbound_id == 0) { |
| 25 | + if($row->remark == $remark) { |
| 26 | + $total = $row->total; |
| 27 | + $up = $row->up; |
| 28 | + $down = $row->down; |
| 29 | + $expiryTime = $row->expiryTime; |
| 30 | + break; |
| 31 | + } |
| 32 | + }else{ |
| 33 | + if($row->id == $inbound_id) { |
| 34 | + $settings = json_decode($row->settings, true); |
| 35 | + $clients = $settings['clients']; |
| 36 | + foreach($clients as $key => $client) { |
| 37 | + if($client['email'] == $remark) { |
| 38 | + $total = $client['totalGB']; |
| 39 | + break; |
| 40 | + } |
59 | 41 | } |
60 | | - $settingsId = array_column($clientsSettings,'id'); |
61 | | - $settingKey = array_search($uuid,$settingsId); |
62 | | - |
63 | | - $email = $clientsSettings[$settingKey]['email']; |
64 | | - $remark = $email; |
65 | | - $port = $list[$keys]['port']; |
66 | 42 |
|
67 | | - $clientState = $list[$keys]['clientStats']; |
68 | | - $emails = array_column($clientState,'email'); |
69 | | - $emailKey = array_search($email,$emails); |
70 | | - |
71 | | - if($clientState[$emailKey]['total'] != 0 || $clientState[$emailKey]['up'] != 0 || $clientState[$emailKey]['down'] != 0 || $clientState[$emailKey]['expiryTime'] != 0){ |
72 | | - $upload = $clientState[$emailKey]['up']; |
73 | | - $download = $clientState[$emailKey]['down']; |
74 | | - $totalUsed = $clientState[$emailKey]['up'] + $clientState[$emailKey]['down']; |
75 | | - $total = $clientState[$emailKey]['total']; |
76 | | - $expiryTime = substr($clientState[$emailKey]['expiryTime'],0,-3); |
77 | | - } |
78 | | - elseif($list[$keys]['total'] != 0 || $list[$keys]['up'] != 0 || $list[$keys]['down'] != 0 || $list[$keys]['expiryTime'] != 0){ |
79 | | - $upload = $clientState[$emailKey]['up']; |
80 | | - $download = $clientState[$emailKey]['down']; |
81 | | - $totalUsed = $clientState[$emailKey]['up'] + $clientState[$emailKey]['down']; |
82 | | - $total = $clientState[$emailKey]['total']; |
83 | | - $expiryTime = substr($clientState[$emailKey]['expiryTime'],0,-3); |
84 | | - |
85 | | - $upload = $list[$keys]['up']; |
86 | | - $download = $list[$keys]['down']; |
87 | | - $totalUsed = $list[$keys]['up'] + $list[$keys]['down']; |
88 | | - $total = $list[$keys]['total']; |
89 | | - $expiryTime = substr($list[$keys]['expiryTime'],0,-3); |
| 43 | + $clientStats = $row->clientStats; |
| 44 | + foreach($clientStats as $key => $clientStat) { |
| 45 | + if($clientStat->email == $remark) { |
| 46 | + $up = $clientStat->up; |
| 47 | + $down = $clientStat->down; |
| 48 | + $expiryTime = $clientStat->expiryTime; |
| 49 | + break; |
| 50 | + } |
90 | 51 | } |
| 52 | + break; |
91 | 53 | } |
| 54 | + } |
| 55 | + } |
| 56 | + $leftgb = round( ($total - $up - $down) / 1073741824, 2); |
| 57 | + $now_microdate = floor(microtime(true) * 1000); |
| 58 | + if($expiryTime < $now_microdate + 86400) $send = "روز"; elseif($leftgb < 1) $send = "گیگ"; |
| 59 | + if($send){ |
| 60 | + $msg = "❌ | مشترک گرامی |
| 61 | +از اشتراک $remark تنها (۱ $send) باقی مانده است لطفا هر چه سریع تر سرویس خود را تمدید کنید ..."; |
| 62 | + sendMessage( $msg, null, null, $from_id); |
| 63 | + $newTIme = $time + 86400 * 2; |
| 64 | + $stmt = $connection->prepare("UPDATE `orders_list` SET `notif`= ? WHERE `remark`=?"); |
| 65 | + $stmt->bind_param("is", $newTIme, $remark); |
| 66 | + $stmt->execute(); |
| 67 | + $stmt->close(); |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | +} |
92 | 72 |
|
93 | | - if($total - $totalUsed < ($mbLeft * 1024 * 1024) && $total != 0){ |
94 | | - $subLeft = "حجم بسته ی اشتراک شما رو به اتمام است، لطفا برای تمدید اشتراک خو اقدام کنید"; |
| 73 | +$stmt = $connection->prepare("SELECT * FROM `orders_list` WHERE `status`=1 AND `notif` !=0"); |
| 74 | +$stmt->execute(); |
| 75 | +$orders = $stmt->get_result(); |
| 76 | +$stmt->close(); |
95 | 77 |
|
96 | | - sendMessage($userId,$subLeft); |
97 | | - sendMessage($Config['report_channel'], "حجم بسته ی کاربر $userId\nuuid: $uuid"); |
98 | | - setUser('warned','true',$userId); |
99 | | - }elseif($expiryTime - time() <= ($hourLeft * 60 * 60) && $expiryTime != 0){ |
100 | | - $subLeft = "زمان اشتراک شما رو به پایان است، لطفا برای تمدید اشتراک خو اقدام کنید"; |
101 | | - |
102 | | - sendMessage($userId,$subLeft); |
103 | | - sendMessage($Config['report_channel'], "زمان بسته ی کاربر $userId\nuuid: $uuid"); |
104 | | - setUser('warned','true',$userId); |
| 78 | +if($orders){ |
| 79 | + if($orders->num_rows>0){ |
| 80 | + while ($order = $orders->fetch_assoc()){ |
| 81 | + $send = false; |
| 82 | + $from_id = $order['userid']; |
| 83 | + $token = $order['token']; |
| 84 | + $remark = $order['remark']; |
| 85 | + $server_id = $order['server_id']; |
| 86 | + $inbound_id = $order['inbound_id']; |
| 87 | + $links_list = $order['link']; |
| 88 | + $notif = $order['notif']; |
| 89 | + |
| 90 | + if($time > $notif) { |
| 91 | + $response = getJson($server_id)->obj; |
| 92 | + foreach($response as $row){ |
| 93 | + if($inbound_id == 0) { |
| 94 | + if($row->remark == $remark) { |
| 95 | + $total = $row->total; |
| 96 | + $up = $row->up; |
| 97 | + $down = $row->down; |
| 98 | + $expiryTime = $row->expiryTime; |
| 99 | + break; |
| 100 | + } |
| 101 | + }else{ |
| 102 | + if($row->id == $inbound_id) { |
| 103 | + $settings = json_decode($row->settings, true); |
| 104 | + $clients = $settings['clients']; |
| 105 | + foreach($clients as $key => $client) { |
| 106 | + if($client['email'] == $remark) { |
| 107 | + $total = $client['totalGB']; |
| 108 | + break; |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + $clientStats = $row->clientStats; |
| 113 | + foreach($clientStats as $key => $clientStat) { |
| 114 | + if($clientStat->email == $remark) { |
| 115 | + $up = $clientStat->up; |
| 116 | + $down = $clientStat->down; |
| 117 | + $expiryTime = $clientStat->expiryTime; |
| 118 | + break; |
| 119 | + } |
| 120 | + } |
| 121 | + break; |
| 122 | + } |
| 123 | + } |
| 124 | + } |
| 125 | + $leftgb = round( ($total - $up - $down) / 1073741824, 2); |
| 126 | + $now_microdate = floor(microtime(true) * 1000); |
| 127 | + if($expiryTime <= $now_microdate) $send = true; elseif($leftgb <= 0) $send = true; |
| 128 | + if($send){ |
| 129 | + if($inbound_id > 0) deleteClient($server_id, $inbound_id, $remark); else deleteInbound($server_id, $remark); |
| 130 | + $msg = "🥺 عزیزم |
| 131 | + سرویس $remark تموم شد و از لیست کانفیگ هات حذف شد ، لطفا یه سرویس جدید بخر ..."; |
| 132 | + sendMessage( $msg, null, null, $from_id); |
| 133 | + $stmt = $connection->prepare("DELETE FROM `orders_list` WHERE `remark`=?"); |
| 134 | + $stmt->bind_param("s", $remark); |
| 135 | + $stmt->execute(); |
| 136 | + $stmt->close(); |
| 137 | + continue; |
| 138 | + } |
| 139 | + else{ |
| 140 | + $stmt = $connection->prepare("UPDATE `orders_list` SET `notif`= 0 WHERE `remark`=?"); |
| 141 | + $stmt->bind_param("s", $remark); |
| 142 | + $stmt->execute(); |
| 143 | + $stmt->close(); |
105 | 144 | } |
106 | | - |
107 | 145 | } |
108 | 146 | } |
109 | 147 | } |
110 | 148 | } |
111 | | - |
112 | | -if(mysqli_num_rows($usersList) >= $offset + 30){ |
113 | | - file_put_contents("offset.txt",$offset+30); |
114 | | -}else{ |
115 | | - unlink("offset.txt"); |
116 | | -} |
117 | | - |
118 | | -//-----------------------------// |
119 | | -unlink("error_log"); |
120 | | -?> |
|
0 commit comments