send balance to other users

This commit is contained in:
Ibnu Maksum
2023-08-23 16:46:05 +07:00
parent 74ac7f3eb4
commit a09dc57495
6 changed files with 177 additions and 67 deletions

View File

@ -9,11 +9,66 @@ $ui->assign('_title', $_L['Dashboard']);
$user = User::_info();
$ui->assign('_user', $user);
if(isset($_GET['renewal'])){
if (isset($_GET['renewal'])) {
$user->auto_renewal = $_GET['renewal'];
$user->save();
}
if (_post('send') == 'balance') {
if ($config['allow_balance_transfer'] == 'yes') {
$target = ORM::for_table('tbl_customers')->where('username', _post('username'))->find_one();
if (!$target) {
r2(U . 'home', 'd', Lang::T('Username not found'));
}
$username = _post('username');
$balance = _post('balance');
if ($user['balance'] < $balance) {
r2(U . 'home', 'd', Lang::T('insufficient balance'));
}
if ($user['username'] == $target['username']) {
r2(U . 'home', 'd', Lang::T('Cannot send to yourself'));
}
if(Balance::transfer($user['id'], $username, $balance)){
//sender
$d = ORM::for_table('tbl_payment_gateway')->create();
$d->username = $user['username'];
$d->gateway = $target['username'];
$d->plan_id = 0;
$d->plan_name = 'Send Balance';
$d->routers_id = 0;
$d->routers = 'balance';
$d->price = $balance;
$d->payment_method = "Customer";
$d->payment_channel = "Balance";
$d->created_date = date('Y-m-d H:i:s');
$d->paid_date = date('Y-m-d H:i:s');
$d->expired_date = date('Y-m-d H:i:s');
$d->pg_url_payment = 'balance';
$d->status = 2;
$d->save();
//receiver
$d = ORM::for_table('tbl_payment_gateway')->create();
$d->username = $target['username'];
$d->gateway = $user['username'];
$d->plan_id = 0;
$d->plan_name = 'Receive Balance';
$d->routers_id = 0;
$d->routers = 'balance';
$d->payment_method = "Customer";
$d->payment_channel = "Balance";
$d->price = $balance;
$d->created_date = date('Y-m-d H:i:s');
$d->paid_date = date('Y-m-d H:i:s');
$d->expired_date = date('Y-m-d H:i:s');
$d->pg_url_payment = 'balance';
$d->status = 2;
$d->save();
r2(U . 'home', 's', Lang::T('Sending balance success'));
}
}else{
r2(U . 'home', 'd', 'Failed, balance is not available');
}
}
//Client Page
$bill = User::_billing();
@ -27,7 +82,7 @@ if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) {
$c = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
Mikrotik::logMeIn($c, $user['username'], $user['password'], $_SESSION['nux-ip'], $_SESSION['nux-mac']);
r2(U . 'home', 's', Lang::T('Login Request successfully'));
}else if ($_GET['mikrotik'] == 'logout') {
} else if ($_GET['mikrotik'] == 'logout') {
$m = Mikrotik::info($bill['routers']);
$c = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
Mikrotik::logMeOut($c, $user['username']);

View File

@ -63,7 +63,7 @@ switch ($action) {
}
break;
case 'view':
$trxid = $routes['2'] * 1;
$trxid = $routes['2'];
$trx = ORM::for_table('tbl_payment_gateway')
->where('username', $user['username'])
->find_one($trxid);