From a09dc5749538977d437267d6b0aa830253edf8cc Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Wed, 23 Aug 2023 16:46:05 +0700 Subject: [PATCH] send balance to other users --- system/autoload/Balance.php | 12 +-- system/controllers/home.php | 59 ++++++++++++- system/controllers/order.php | 2 +- system/lan/english/common.lan.php | 9 +- ui/ui/user-dashboard.tpl | 24 ++++++ ui/ui/user-orderView.tpl | 138 ++++++++++++++++++------------ 6 files changed, 177 insertions(+), 67 deletions(-) diff --git a/system/autoload/Balance.php b/system/autoload/Balance.php index a3686e7d..f6557a3f 100644 --- a/system/autoload/Balance.php +++ b/system/autoload/Balance.php @@ -18,15 +18,11 @@ class Balance public static function transfer($id_customer, $phoneTarget, $amount) { global $config; - if ($config['allow_balance_transfer'] == 'yes') { - if (Balance::min($id_customer, $amount)) { - if (Balance::plusByPhone($phoneTarget, $amount)) { - return true; - } else { - Balance::plus($id_customer, $amount); - return false; - } + if (Balance::min($id_customer, $amount)) { + if (Balance::plusByPhone($phoneTarget, $amount)) { + return true; } else { + Balance::plus($id_customer, $amount); return false; } } else { diff --git a/system/controllers/home.php b/system/controllers/home.php index 6108d816..a669ca7a 100644 --- a/system/controllers/home.php +++ b/system/controllers/home.php @@ -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']); diff --git a/system/controllers/order.php b/system/controllers/order.php index 68ac4eec..d665889b 100644 --- a/system/controllers/order.php +++ b/system/controllers/order.php @@ -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); diff --git a/system/lan/english/common.lan.php b/system/lan/english/common.lan.php index a5c1457e..d5f7e152 100644 --- a/system/lan/english/common.lan.php +++ b/system/lan/english/common.lan.php @@ -371,4 +371,11 @@ $_L['Success_to_buy_package'] = 'Success to buy package'; $_L['Auto_Renewal'] = 'Auto Renewal'; $_L['View'] = 'View'; $_L['Back'] = 'Back'; -$_L['Active'] = 'Active'; +$_L['Active'] = 'Active'; +$_L['Transfer_Balance'] = 'Transfer Balance'; +$_L['Send_your_balance'] = 'Send your balance?'; +$_L['Send'] = 'Send'; +$_L['Cannot_send_to_yourself'] = 'Cannot send to yourself'; +$_L['Sending_balance_success'] = 'Sending balance success'; +$_L['From'] = 'From'; +$_L['To'] = 'To'; diff --git a/ui/ui/user-dashboard.tpl b/ui/ui/user-dashboard.tpl index 80851465..29462ac8 100644 --- a/ui/ui/user-dashboard.tpl +++ b/ui/ui/user-dashboard.tpl @@ -138,6 +138,30 @@ }, 2000); {/if} + {if $_c['enable_balance'] == 'yes'} +
+
+

{Lang::T("Transfer Balance")}

+
+
+
+
+
+ +
+
+ +
+
+ +
+
+
+
+
+ {/if}
{if $_c['disable_voucher'] != 'yes'}
diff --git a/ui/ui/user-orderView.tpl b/ui/ui/user-orderView.tpl index 48c2006a..6a090412 100644 --- a/ui/ui/user-orderView.tpl +++ b/ui/ui/user-orderView.tpl @@ -6,7 +6,7 @@
- {if $plan['type']!='Balance'} + {if $trx['routers']!='balance'}
{$router['name']}
@@ -17,70 +17,98 @@
{/if}
- - - - - - - - - - - {if $trx['status']==2} + {if $trx['pg_url_payment']=='balance'} +
{Lang::T('Status')}{if $trx['status']==1}{Lang::T('UNPAID')}{elseif $trx['status']==2}{Lang::T('PAID')}{elseif $trx['status']==3}{Lang::T('FAILED')}{elseif $trx['status']==4}{Lang::T('CANCELED')}{else}{Lang::T('UNKNOWN')}{/if} -
{Lang::T('expired')}{date($_c['date_format'], strtotime($trx['expired_date']))} - {date('H:i', strtotime($trx['expired_date']))}
+ + + + + - {/if} - - - - - - - - - - - - - {if $plan['type']!='Balance'} - {if $plan['type'] eq 'Hotspot'} - - - - - {if $plan['typebp'] eq 'Limited'} - {if $plan['limit_type'] eq 'Time_Limit' or $plan['limit_type'] eq 'Both_Limit'} - - - - - {/if} - {if $plan['limit_type'] eq 'Data_Limit' or $plan['limit_type'] eq 'Both_Limit'} - - - - - {/if} - {/if} - {/if} - - + {if $trx['plan_name'] == 'Receive Balance'} + + {else} + + {/if} + - - + + + +
{Lang::T('Type')}{$trx['plan_name']}
{Lang::T('Paid Date')} {date($_c['date_format'], strtotime($trx['paid_date']))} {date('H:i', strtotime($trx['paid_date']))}
{$_L['Plan_Name']}{$plan['name_plan']}
{$_L['Plan_Price']}{Lang::moneyFormat($plan['price'])}
{Lang::T('Type')}{$plan['type']}
{Lang::T('Plan_Type')}{Lang::T($plan['typebp'])}
{Lang::T('Time_Limit')}{$ds['time_limit']} {$ds['time_unit']}
{Lang::T('Data_Limit')}{$ds['data_limit']} {$ds['data_unit']}
{$_L['Plan_Validity']}{$plan['validity']} {$plan['validity_unit']}{Lang::T('From')}{Lang::T('To')}{$trx['gateway']}
{$_L['Bandwidth_Plans']}{$bandw['name_bw']}
{$bandw['rate_down']}{$bandw['rate_down_unit']}/{$bandw['rate_up']}{$bandw['rate_up_unit']} +
{$_L['Balance']}{Lang::moneyFormat($trx['price'])}
+ {else} + + + + + - {/if} - -
{Lang::T('Status')}{if $trx['status']==1}{Lang::T('UNPAID')}{elseif $trx['status']==2}{Lang::T('PAID')}{elseif $trx['status']==3}{Lang::T('FAILED')}{elseif $trx['status']==4}{Lang::T('CANCELED')}{else}{Lang::T('UNKNOWN')}{/if}
+ + {Lang::T('expired')} + {date($_c['date_format'], strtotime($trx['expired_date']))} + {date('H:i', strtotime($trx['expired_date']))} + + {if $trx['status']==2} + + {Lang::T('Paid Date')} + {date($_c['date_format'], strtotime($trx['paid_date']))} + {date('H:i', strtotime($trx['paid_date']))} + + {/if} + + {$_L['Plan_Name']} + {$plan['name_plan']} + + + {$_L['Plan_Price']} + {Lang::moneyFormat($plan['price'])} + + + {Lang::T('Type')} + {$plan['type']} + + {if $plan['type']!='Balance'} + {if $plan['type'] eq 'Hotspot'} + + {Lang::T('Plan_Type')} + {Lang::T($plan['typebp'])} + + {if $plan['typebp'] eq 'Limited'} + {if $plan['limit_type'] eq 'Time_Limit' or $plan['limit_type'] eq 'Both_Limit'} + + {Lang::T('Time_Limit')} + {$ds['time_limit']} {$ds['time_unit']} + + {/if} + {if $plan['limit_type'] eq 'Data_Limit' or $plan['limit_type'] eq 'Both_Limit'} + + {Lang::T('Data_Limit')} + {$ds['data_limit']} {$ds['data_unit']} + + {/if} + {/if} + {/if} + + {$_L['Plan_Validity']} + {$plan['validity']} {$plan['validity_unit']} + + + {$_L['Bandwidth_Plans']} + {$bandw['name_bw']}
{$bandw['rate_down']}{$bandw['rate_down_unit']}/{$bandw['rate_up']}{$bandw['rate_up_unit']} + + + {/if} + + + {/if}
{if $trx['status']==1}