|
3 | 3 | include_once '../config.php';
|
4 | 4 | $time = time();
|
5 | 5 |
|
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); |
7 | 12 | $stmt->execute();
|
8 | 13 | $orders = $stmt->get_result();
|
9 | 14 | $stmt->close();
|
|
21 | 26 | $notif = $order['notif'];
|
22 | 27 | $expiryTime = "";
|
23 | 28 | $response = getJson($server_id)->obj;
|
| 29 | + $found = false; |
24 | 30 | foreach($response as $row){
|
25 | 31 | if($inbound_id == 0) {
|
26 | 32 | if($row->remark == $remark) {
|
| 33 | + $found = true; |
27 | 34 | $total = $row->total;
|
28 | 35 | $up = $row->up;
|
29 | 36 | $down = $row->down;
|
|
36 | 43 | $clients = $settings['clients'];
|
37 | 44 | foreach($clients as $key => $client) {
|
38 | 45 | if($client['email'] == $remark) {
|
| 46 | + $found = true; |
39 | 47 | $total = $client['totalGB'];
|
40 | 48 | break;
|
41 | 49 | }
|
|
53 | 61 | break;
|
54 | 62 | }
|
55 | 63 | }
|
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 | + } |
57 | 73 | $leftgb = round( ($total - $up - $down) / 1073741824, 2);
|
58 | 74 | $now_microdate = floor(microtime(true) * 1000);
|
59 | 75 | if($expiryTime != null && $total != null){
|
|
71 | 87 | }
|
72 | 88 | }
|
73 | 89 | }
|
74 |
| - } |
| 90 | + file_put_contents("warnOffset.txt", $warnOffset + $limit); |
| 91 | + }else unlink('warnOffset.txt'); |
75 | 92 | }
|
76 | 93 |
|
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); |
78 | 97 | $stmt->execute();
|
79 | 98 | $orders = $stmt->get_result();
|
80 | 99 | $stmt->close();
|
|
91 | 110 | $links_list = $order['link'];
|
92 | 111 | $notif = $order['notif'];
|
93 | 112 |
|
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; |
114 | 131 | }
|
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; |
124 | 141 | }
|
125 |
| - break; |
126 | 142 | }
|
| 143 | + break; |
127 | 144 | }
|
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(); |
148 | 145 | }
|
| 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(); |
149 | 166 | }
|
150 | 167 | }
|
151 | 168 | }
|
|
0 commit comments