Delete Used Voucher which not exists in tbl recharges

This commit is contained in:
Ibnu Maksum 2024-01-08 16:12:21 +07:00
parent b862a759d0
commit 055b855bc1
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
5 changed files with 62 additions and 41 deletions

View File

@ -90,29 +90,29 @@ if (_post('send') == 'balance') {
$ui->assign('_bills', User::_billing());
if(isset($_GET['recharge']) && !empty($_GET['recharge'])){
if (isset($_GET['recharge']) && !empty($_GET['recharge'])) {
$bill = ORM::for_table('tbl_user_recharges')->where('id', $_GET['recharge'])->where('username', $user['username'])->findOne();
if ($bill) {
$router = ORM::for_table('tbl_routers')->where('name', $bill['routers'])->find_one();
if ($config['enable_balance'] == 'yes') {
$plan = ORM::for_table('tbl_plans')->find_one($bill['plan_id']);
if($user['balance']>$plan['price']){
if ($user['balance'] > $plan['price']) {
r2(U . "order/pay/$router[id]/$bill[plan_id]", 'e', 'Order Plan');
}else{
} else {
r2(U . "order/buy/$router[id]/$bill[plan_id]", 'e', 'Order Plan');
}
}else{
} else {
r2(U . "order/buy/$router[id]/$bill[plan_id]", 'e', 'Order Plan');
}
}
}else if(isset($_GET['deactivate']) && !empty($_GET['deactivate'])){
} else if (isset($_GET['deactivate']) && !empty($_GET['deactivate'])) {
$bill = ORM::for_table('tbl_user_recharges')->where('id', $_GET['deactivate'])->where('username', $user['username'])->findOne();
if ($bill) {
$p = ORM::for_table('tbl_plans')->where('id', $bill['plan_id'])->find_one();
if($p['is_radius']){
if ($p['is_radius']) {
Radius::customerDeactivate($user['username']);
}else{
try{
} else {
try {
$mikrotik = Mikrotik::info($bill['routers']);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
if ($bill['type'] == 'Hotspot') {
@ -122,7 +122,7 @@ if(isset($_GET['recharge']) && !empty($_GET['recharge'])){
Mikrotik::removePpoeUser($client, $bill['username']);
Mikrotik::removePpoeActive($client, $bill['username']);
}
}catch(Exception $e){
} catch (Exception $e) {
//ignore it maybe mikrotik has been deleted
}
}
@ -130,10 +130,10 @@ if(isset($_GET['recharge']) && !empty($_GET['recharge'])){
$bill->expiration = date('Y-m-d');
$bill->time = date('H:i:s');
$bill->save();
_log('User ' . $bill['username'] . ' Deactivate '.$bill['namebp'], 'User', $bill['customer_id']);
Message::sendTelegram('User u' . $bill['username'] . ' Deactivate '.$bill['namebp']);
r2(U . 'home', 's', 'Success deactivate '.$bill['namebp']);
}else{
_log('User ' . $bill['username'] . ' Deactivate ' . $bill['namebp'], 'User', $bill['customer_id']);
Message::sendTelegram('User u' . $bill['username'] . ' Deactivate ' . $bill['namebp']);
r2(U . 'home', 's', 'Success deactivate ' . $bill['namebp']);
} else {
r2(U . 'home', 'e', 'No Active Plan');
}
}

View File

@ -47,7 +47,7 @@ switch ($do) {
$username = _post('username');
$v1 = ORM::for_table('tbl_voucher')->where('code', $voucher)->find_one();
if ($v1) {
// coucher exists, check customer exists or not
// voucher exists, check customer exists or not
$user = ORM::for_table('tbl_customers')->where('username', $username)->find_one();
if (!$user) {
$d = ORM::for_table('tbl_customers')->create();
@ -63,7 +63,7 @@ switch ($do) {
r2(U . 'login', 'e', Lang::T('Voucher activation failed'));
}
} else {
r2(U . 'login', 'e', Lang::T('Voucher activation failed').'.');
r2(U . 'login', 'e', Lang::T('Voucher activation failed') . '.');
}
}
if ($v1['status'] == 0) {
@ -72,32 +72,34 @@ switch ($do) {
$user->password = $voucher;
$user->save();
// voucher activation
if (Package::rechargeUser($user['id'], $v1['routers'], $v1['id_plan'], "Activation", "Voucher")) {
if (Package::rechargeUser($user['id'], $v1['routers'], $v1['id_plan'], "Voucher", $voucher)) {
$v1->status = "1";
$v1->user = $user['username'];
$v1->save();
$user->last_login = date('Y-m-d H:i:s');
$user->save();
// add customer to mikrotik
if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) {
try{
try {
$m = Mikrotik::info($v1['routers']);
$c = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
Mikrotik::logMeIn($c, $user['username'], $user['password'], $_SESSION['nux-ip'], $_SESSION['nux-mac']);
if(!empty($config['voucher_redirect'])){
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, you are connected to internet"));
}else{
} else {
r2(U . "login", 's', Lang::T("Voucher activation success, you are connected to internet"));
}
} catch (Exception $e) {
if(!empty($config['voucher_redirect'])){
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, now you can login"));
}else{
} else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login"));
}
}
}
if(!empty($config['voucher_redirect'])){
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, now you can login"));
}else{
} else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login"));
}
} else {
@ -110,27 +112,29 @@ switch ($do) {
// used voucher
// check if voucher used by this username
if ($v1['user'] == $user['username']) {
$user->last_login = date('Y-m-d H:i:s');
$user->save();
if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) {
try{
try {
$m = Mikrotik::info($v1['routers']);
$c = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
Mikrotik::logMeIn($c, $user['username'], $user['password'], $_SESSION['nux-ip'], $_SESSION['nux-mac']);
if(!empty($config['voucher_redirect'])){
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, you are connected to internet"));
}else{
} else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login"));
}
} catch (Exception $e) {
if(!empty($config['voucher_redirect'])){
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, now you can login"));
}else{
} else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login"));
}
}
}else{
if(!empty($config['voucher_redirect'])){
} else {
if (!empty($config['voucher_redirect'])) {
r2($config['voucher_redirect'], 's', Lang::T("Voucher activation success, you are connected to internet"));
}else{
} else {
r2(U . "login", 's', Lang::T("Voucher activation success, now you can login"));
}
}
@ -140,14 +144,14 @@ switch ($do) {
}
}
} else {
// voucher not found
r2(U . 'login', 'e', $_L['Voucher_Not_Valid']);
_msglog('e', $_L['Invalid_Username_or_Password']);
r2(U . 'login');
}
default:
run_hook('customer_view_login'); #HOOK
if($config['disable_registration']=='yes'){
if ($config['disable_registration'] == 'yes') {
$ui->display('user-login-noreg.tpl');
}else{
} else {
$ui->display('user-login.tpl');
}
break;

View File

@ -288,8 +288,14 @@ switch ($action) {
case 'remove-voucher':
$d = ORM::for_table('tbl_voucher')->where_equal('status', '1')->findMany();
if ($d) {
$d->delete();
r2(U . 'prepaid/voucher', 's', $_L['Delete_Successfully']);
$jml = 0;
foreach ($d as $v) {
if(!ORM::for_table('tbl_user_recharges')->where_equal("method",'Voucher - '.$v['code'])->findOne()){
$v->delete();
$jml++;
}
}
r2(U . 'prepaid/voucher', 's', "$jml ".$_L['Delete_Successfully']);
}
case 'print-voucher':
$from_id = _post('from_id');
@ -410,6 +416,18 @@ switch ($action) {
$msg .= 'The Length Code must be a number' . '<br>';
}
if ($msg == '') {
if(!empty($prefix)){
$d = ORM::for_table('tbl_appconfig')->where('setting', 'voucher_prefix')->find_one();
if ($d) {
$d->value = $prefix;
$d->save();
} else {
$d = ORM::for_table('tbl_appconfig')->create();
$d->setting = 'voucher_prefix';
$d->value = $prefix;
$d->save();
}
}
run_hook('create_voucher'); #HOOK
for ($i = 0; $i < $numbervoucher; $i++) {
$code = strtoupper(substr(md5(time() . rand(10000, 99999)), 0, $lengthcode));
@ -459,7 +477,7 @@ switch ($action) {
run_hook('refill_customer'); #HOOK
if ($v1) {
if (Package::rechargeUser($user['id'], $v1['routers'], $v1['id_plan'], "Refill", "Voucher")) {
if (Package::rechargeUser($user['id'], $v1['routers'], $v1['id_plan'], "Voucher", $code)) {
$v1->status = "1";
$v1->user = $user['username'];
$v1->save();

View File

@ -11,8 +11,6 @@ $action = $routes['1'];
$user = User::_info();
$ui->assign('_user', $user);
use PEAR2\Net\RouterOS;
require_once 'system/autoload/PEAR2/Autoload.php';
switch ($action) {
@ -27,7 +25,7 @@ switch ($action) {
$v1 = ORM::for_table('tbl_voucher')->where('code', $code)->where('status', 0)->find_one();
run_hook('customer_activate_voucher'); #HOOK
if ($v1) {
if (Package::rechargeUser($user['id'], $v1['routers'], $v1['id_plan'], "Activation", "Voucher")) {
if (Package::rechargeUser($user['id'], $v1['routers'], $v1['id_plan'], "Voucher", $code)) {
$v1->status = "1";
$v1->user = $user['username'];
$v1->save();

View File

@ -418,3 +418,4 @@ $_L['Customer_just_Login_with_Phone_number_and_Voucher_Code_Voucher_will_be_pass
$_L['Login__Activate_Voucher'] = 'Login / Activate Voucher';
$_L['After_Customer_activate_voucher_or_login_customer_will_be_redirected_to_this_url'] = 'After Customer activate voucher or login, customer will be redirected to this url';
$_L['Voucher_Prefix'] = 'Voucher Prefix';
$_L['Voucher_activation_success_now_you_can_login'] = 'Voucher activation success, now you can login';