Add planwith validity period

This commit is contained in:
gerandonk 2024-03-03 11:03:25 +07:00
parent b153e5b595
commit 61b3f5b5f5
4 changed files with 43 additions and 5 deletions

View file

@ -91,7 +91,7 @@ CREATE TABLE `tbl_plans` (
`data_limit` int(10) UNSIGNED DEFAULT NULL,
`data_unit` enum('MB','GB') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
`validity` int(10) NOT NULL,
`validity_unit` enum('Mins','Hrs','Days','Months') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`validity_unit` enum('Mins','Hrs','Days','Months','Period') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`shared_users` int(10) DEFAULT NULL,
`routers` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`is_radius` tinyint(1) NOT NULL DEFAULT '0' COMMENT '1 is radius',

View file

@ -100,6 +100,18 @@ class Package
$mikrotik = Mikrotik::info($router_name);
if ($p['validity_unit'] == 'Months') {
$date_exp = date("Y-m-d", strtotime('+' . $p['validity'] . ' month'));
} else if ($p['validity_unit'] == 'Period') {
$date_tmp = date("Y-m-20", strtotime('+' . $p['validity'] . ' month'));
$dt1 = new DateTime("$date_only");
$dt2 = new DateTime("$date_tmp");
$diff = $dt2->diff($dt1);
$sum = $diff->format("%a");// => 453
if ($sum >= 35) {
$date_exp = date("Y-m-20", strtotime('+0 month'));
} else {
$date_exp = date("Y-m-20", strtotime('+' . $p['validity'] . ' month'));
};
$time = date("23:59:00");
} else if ($p['validity_unit'] == 'Days') {
$date_exp = date("Y-m-d", strtotime('+' . $p['validity'] . ' day'));
} else if ($p['validity_unit'] == 'Hrs') {
@ -119,6 +131,9 @@ class Package
if ($p['validity_unit'] == 'Months') {
$date_exp = date("Y-m-d", strtotime($b['expiration'] . ' +' . $p['validity'] . ' months'));
$time = $b['time'];
} else if ($p['validity_unit'] == 'Period') {
$date_exp = date("Y-m-20", strtotime($b['expiration'] . ' +' . $p['validity'] . ' months'));
$time = date("23:59:00");
} else if ($p['validity_unit'] == 'Days') {
$date_exp = date("Y-m-d", strtotime($b['expiration'] . ' +' . $p['validity'] . ' days'));
$time = $b['time'];
@ -180,6 +195,12 @@ class Package
$t->admin_id = '0';
}
$t->save();
Message::sendTelegram("#u$c[username] #recharge #Hotspot \n" . $p['name_plan'] .
"\nRouter: " . $router_name .
"\nGateway: " . $gateway .
"\nChannel: " . $channel .
"\nPrice: " . Lang::moneyFormat($p['price']));
} else {
if ($p['is_radius']) {
Radius::customerAddPlan($c, $p, "$date_exp $time");
@ -229,12 +250,14 @@ class Package
$t->admin_id = '0';
}
$t->save();
}
Message::sendTelegram("#u$c[username] #buy #Hotspot \n" . $p['name_plan'] .
Message::sendTelegram("#u$c[username] #buy #Hotspot \n" . $p['name_plan'] .
"\nRouter: " . $router_name .
"\nGateway: " . $gateway .
"\nChannel: " . $channel .
"\nPrice: " . Lang::moneyFormat($p['price']));
}
} else {
if ($b) {
@ -243,6 +266,9 @@ class Package
if ($p['validity_unit'] == 'Months') {
$date_exp = date("Y-m-d", strtotime($b['expiration'] . ' +' . $p['validity'] . ' months'));
$time = $b['time'];
} else if ($p['validity_unit'] == 'Period') {
$date_exp = date("Y-m-20", strtotime($b['expiration'] . ' +' . $p['validity'] . ' months'));
$time = date("23:59:00");
} else if ($p['validity_unit'] == 'Days') {
$date_exp = date("Y-m-d", strtotime($b['expiration'] . ' +' . $p['validity'] . ' days'));
$time = $b['time'];
@ -304,6 +330,12 @@ class Package
$t->admin_id = '0';
}
$t->save();
Message::sendTelegram("#u$c[username] #recharge #PPPOE \n" . $p['name_plan'] .
"\nRouter: " . $router_name .
"\nGateway: " . $gateway .
"\nChannel: " . $channel .
"\nPrice: " . Lang::moneyFormat($p['price']));
} else {
if ($p['is_radius']) {
Radius::customerAddPlan($c, $p, "$date_exp $time");
@ -353,12 +385,14 @@ class Package
}
$t->type = "PPPOE";
$t->save();
}
Message::sendTelegram("#u$c[username] #buy #PPPOE \n" . $p['name_plan'] .
Message::sendTelegram("#u$c[username] #buy #PPPOE \n" . $p['name_plan'] .
"\nRouter: " . $router_name .
"\nGateway: " . $gateway .
"\nChannel: " . $channel .
"\nPrice: " . Lang::moneyFormat($p['price']));
}
}
run_hook("recharge_user_finish");
Message::sendInvoice($c, $t);

View file

@ -60,6 +60,7 @@
<label class="col-md-2 control-label">{Lang::T('Plan Validity')}</label>
<div class="col-md-4">
<input type="text" class="form-control" id="validity" name="validity">
<p class="help-block">{Lang::T('1 Period = 1 Month, Expires the 20th of each month')}</p>
</div>
<div class="col-md-2">
<select class="form-control" id="validity_unit" name="validity_unit">
@ -67,6 +68,7 @@
<option value="Hrs">{Lang::T('Hrs')}</option>
<option value="Days">{Lang::T('Days')}</option>
<option value="Months">{Lang::T('Months')}</option>
<option value="Period">{Lang::T('Period')}</option>
</select>
</div>
</div>

View file

@ -62,6 +62,7 @@
<div class="col-md-4">
<input type="text" class="form-control" id="validity" name="validity"
value="{$d['validity']}">
<p class="help-block">{Lang::T('1 Period = 30 Month, Expires the 20th of each month')}</p>
</div>
<div class="col-md-2">
<select class="form-control" id="validity_unit" name="validity_unit">
@ -73,6 +74,7 @@
</option>
<option value="Months" {if $d['validity_unit'] eq 'Months'} selected {/if}>
{Lang::T('Months')}</option>
<option value="Period" {if $d['validity_unit'] eq 'Period'} selected {/if}>{Lang::T('Period')}</option>
</select>
</div>
</div>