auto renewal from deposit

This commit is contained in:
Ibnu Maksum 2023-08-15 10:17:28 +07:00
parent af0b2cda28
commit 7e78c5db40
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
5 changed files with 39 additions and 7 deletions

View File

@ -56,6 +56,7 @@ CREATE TABLE
`phonenumber` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '0',
`email` varchar(128) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '1',
`balance` decimal(15,2) NOT NULL COMMENT 'For Money Deposit',
`auto_renewal` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Auto renewal from balance',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`last_login` datetime DEFAULT NULL
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;

View File

@ -19,9 +19,9 @@ ORM::configure('logging', true);
include "autoload/Hookers.php";
// notification message
if(file_exists("uploads/notifications.json")){
$_notifmsg =json_decode(file_get_contents('uploads/notifications.json'), true);
}else{
if (file_exists("uploads/notifications.json")) {
$_notifmsg = json_decode(file_get_contents('uploads/notifications.json'), true);
} else {
$_notifmsg = json_decode(file_get_contents('uploads/notifications.default.json'), true);
}
@ -87,6 +87,21 @@ foreach ($d as $ds) {
//update database user dengan status off
$u->status = 'off';
$u->save();
// autorenewal from deposit
if ($config['enable_balance'] == 'yes' && $c['auto_renewal']) {
$p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one();
if ($p && $p['enabled'] && $c['balance'] >= $p['price']) {
if (Package::rechargeUser($ds['customer_id'], $p['routers'], $p['id'], 'Customer', 'Balance')) {
// if success, then get the balance
Balance::min($ds['customer_id'], $p['price']);
} else {
Message::sendTelegram("FAILED RENEWAL #cron\n\n#u$c[username] #buy #Hotspot \n" . $p['name_plan'] .
"\nRouter: " . $router_name .
"\nPrice: " . $p['price']);
}
}
}
} else echo " : ACTIVE \r\n";
} else {
$date_now = strtotime(date("Y-m-d H:i:s"));
@ -107,6 +122,21 @@ foreach ($d as $ds) {
$u->status = 'off';
$u->save();
// autorenewal from deposit
if ($config['enable_balance'] == 'yes' && $c['auto_renewal']) {
$p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one();
if ($p && $p['enabled'] && $c['balance'] >= $p['price']) {
if (Package::rechargeUser($ds['customer_id'], $p['routers'], $p['id'], 'Customer', 'Balance')) {
// if success, then get the balance
Balance::min($ds['customer_id'], $p['price']);
} else {
Message::sendTelegram("FAILED RENEWAL #cron\n\n#u$c[username] #buy #Hotspot \n" . $p['name_plan'] .
"\nRouter: " . $router_name .
"\nPrice: " . $p['price']);
}
}
}
} else echo " : ACTIVE \r\n";
}
}

View File

@ -8,6 +8,7 @@
"2023.8.14": [
"ALTER TABLE `tbl_customers` ADD `pppoe_password` varchar(45) NOT NULL DEFAULT '1' COMMENT 'For PPPOE Login' AFTER `password`;",
"ALTER TABLE `tbl_plans` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;",
"ALTER TABLE `tbl_transactions` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;"
"ALTER TABLE `tbl_transactions` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;",
"ALTER TABLE `tbl_customers` ADD `auto_renewal` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Auto renewall using balance' AFTER `balance`;"
]
}

View File

@ -1,5 +1,5 @@
{
"user_notification_expired_text": "Hello [[name]], your internet package [[package]] has been expired.",
"expired": "Hello [[name]], your internet package [[package]] has been expired.",
"reminder_7_day": "Hello *[[name]]*, \r\nyour internet package *[[package]]* will be expired in 7 days.",
"reminder_3_day": "Hello *[[name]]*, \r\nyour internet package *[[package]]* will be expired in 3 days.",
"reminder_1_day": "Hello *[[name]]*,\r\n your internet package *[[package]]* will be expired tomorrow.",

View File

@ -15,8 +15,8 @@
<div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Expired Notification Message')}</label>
<div class="col-md-6">
<textarea class="form-control" id="user_notification_expired_text"
name="user_notification_expired_text"
<textarea class="form-control" id="expired"
name="expired"
placeholder="Hello [[name]], your internet package [[package]] has been expired"
rows="3">{if $_json['expired']!=''}{Lang::htmlspecialchars($_json['expired'])}{else}Hello [[name]], your internet package [[package]] has been expired.{/if}</textarea>
</div>