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

@ -47,7 +47,7 @@ switch ($do) {
$username = _post('username'); $username = _post('username');
$v1 = ORM::for_table('tbl_voucher')->where('code', $voucher)->find_one(); $v1 = ORM::for_table('tbl_voucher')->where('code', $voucher)->find_one();
if ($v1) { 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(); $user = ORM::for_table('tbl_customers')->where('username', $username)->find_one();
if (!$user) { if (!$user) {
$d = ORM::for_table('tbl_customers')->create(); $d = ORM::for_table('tbl_customers')->create();
@ -72,10 +72,12 @@ switch ($do) {
$user->password = $voucher; $user->password = $voucher;
$user->save(); $user->save();
// voucher activation // 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->status = "1";
$v1->user = $user['username']; $v1->user = $user['username'];
$v1->save(); $v1->save();
$user->last_login = date('Y-m-d H:i:s');
$user->save();
// add customer to mikrotik // add customer to mikrotik
if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) { if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) {
try { try {
@ -110,6 +112,8 @@ switch ($do) {
// used voucher // used voucher
// check if voucher used by this username // check if voucher used by this username
if ($v1['user'] == $user['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'])) { if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) {
try { try {
$m = Mikrotik::info($v1['routers']); $m = Mikrotik::info($v1['routers']);
@ -140,8 +144,8 @@ switch ($do) {
} }
} }
} else { } else {
// voucher not found _msglog('e', $_L['Invalid_Username_or_Password']);
r2(U . 'login', 'e', $_L['Voucher_Not_Valid']); r2(U . 'login');
} }
default: default:
run_hook('customer_view_login'); #HOOK run_hook('customer_view_login'); #HOOK

View File

@ -288,8 +288,14 @@ switch ($action) {
case 'remove-voucher': case 'remove-voucher':
$d = ORM::for_table('tbl_voucher')->where_equal('status', '1')->findMany(); $d = ORM::for_table('tbl_voucher')->where_equal('status', '1')->findMany();
if ($d) { if ($d) {
$d->delete(); $jml = 0;
r2(U . 'prepaid/voucher', 's', $_L['Delete_Successfully']); 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': case 'print-voucher':
$from_id = _post('from_id'); $from_id = _post('from_id');
@ -410,6 +416,18 @@ switch ($action) {
$msg .= 'The Length Code must be a number' . '<br>'; $msg .= 'The Length Code must be a number' . '<br>';
} }
if ($msg == '') { 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 run_hook('create_voucher'); #HOOK
for ($i = 0; $i < $numbervoucher; $i++) { for ($i = 0; $i < $numbervoucher; $i++) {
$code = strtoupper(substr(md5(time() . rand(10000, 99999)), 0, $lengthcode)); $code = strtoupper(substr(md5(time() . rand(10000, 99999)), 0, $lengthcode));
@ -459,7 +477,7 @@ switch ($action) {
run_hook('refill_customer'); #HOOK run_hook('refill_customer'); #HOOK
if ($v1) { 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->status = "1";
$v1->user = $user['username']; $v1->user = $user['username'];
$v1->save(); $v1->save();

View File

@ -11,8 +11,6 @@ $action = $routes['1'];
$user = User::_info(); $user = User::_info();
$ui->assign('_user', $user); $ui->assign('_user', $user);
use PEAR2\Net\RouterOS;
require_once 'system/autoload/PEAR2/Autoload.php'; require_once 'system/autoload/PEAR2/Autoload.php';
switch ($action) { switch ($action) {
@ -27,7 +25,7 @@ switch ($action) {
$v1 = ORM::for_table('tbl_voucher')->where('code', $code)->where('status', 0)->find_one(); $v1 = ORM::for_table('tbl_voucher')->where('code', $code)->where('status', 0)->find_one();
run_hook('customer_activate_voucher'); #HOOK run_hook('customer_activate_voucher'); #HOOK
if ($v1) { 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->status = "1";
$v1->user = $user['username']; $v1->user = $user['username'];
$v1->save(); $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['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['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_Prefix'] = 'Voucher Prefix';
$_L['Voucher_activation_success_now_you_can_login'] = 'Voucher activation success, now you can login';