phpnuxbill/system/cron_reminder.php

60 lines
2.2 KiB
PHP
Raw Normal View History

2023-08-14 15:15:15 +08:00
<?php
/**
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
2024-04-19 12:23:50 +08:00
* This file for reminding user about expiration
* Example to run every at 7:00 in the morning
2023-08-14 15:15:15 +08:00
* 0 7 * * * /usr/bin/php /var/www/system/cron_reminder.php
**/
2024-02-19 15:24:34 +08:00
include "../init.php";
2023-08-14 15:15:15 +08:00
2024-02-19 15:24:34 +08:00
$isCli = true;
if (php_sapi_name() !== 'cli') {
$isCli = false;
2023-09-07 10:35:00 +08:00
echo "<pre>";
}
2024-07-10 16:44:11 +08:00
$d = ORM::for_table('tbl_user_recharges')->where('status', 'on')->whereNotEqual('customer_id', '0')->find_many();
2024-04-19 12:23:50 +08:00
run_hook('cronjob_reminder'); #HOOK
2023-08-14 15:15:15 +08:00
2023-09-07 10:35:00 +08:00
echo "PHP Time\t" . date('Y-m-d H:i:s') . "\n";
$res = ORM::raw_execute('SELECT NOW() AS WAKTU;');
$statement = ORM::get_last_statement();
$rows = array();
while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
echo "MYSQL Time\t" . $row['WAKTU'] . "\n";
}
2024-04-19 12:23:50 +08:00
2023-08-14 15:15:15 +08:00
$day7 = date('Y-m-d', strtotime("+7 day"));
$day3 = date('Y-m-d', strtotime("+3 day"));
$day1 = date('Y-m-d', strtotime("+1 day"));
2023-08-24 12:35:23 +08:00
print_r([$day1, $day3, $day7]);
2024-04-19 12:23:50 +08:00
foreach ($d as $ds) {
if (in_array($ds['expiration'], [$day1, $day3, $day7])) {
$u = ORM::for_table('tbl_user_recharges')->where('id', $ds['id'])->find_one();
$p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one();
$c = ORM::for_table('tbl_customers')->where('id', $ds['customer_id'])->find_one();
if ($p['validity_unit'] == 'Period') {
2024-04-19 12:23:50 +08:00
// Postpaid price from field
$add_inv = User::getAttribute("Invoice", $ds['customer_id']);
if (empty ($add_inv) or $add_inv == 0) {
$price = $p['price'];
2024-04-19 12:23:50 +08:00
} else {
$price = $add_inv;
2024-04-19 12:23:50 +08:00
}
} else {
$price = $p['price'];
}
2024-04-19 12:23:50 +08:00
if ($ds['expiration'] == $day7) {
echo Message::sendPackageNotification($c, $p['name_plan'], $price, Lang::getNotifText('reminder_7_day'), $config['user_notification_reminder']) . "\n";
} else if ($ds['expiration'] == $day3) {
echo Message::sendPackageNotification($c, $p['name_plan'], $price, Lang::getNotifText('reminder_3_day'), $config['user_notification_reminder']) . "\n";
} else if ($ds['expiration'] == $day1) {
echo Message::sendPackageNotification($c, $p['name_plan'], $price, Lang::getNotifText('reminder_1_day'), $config['user_notification_reminder']) . "\n";
2023-08-14 15:15:15 +08:00
}
}
}