forked from kevinowino869/mitrobill
.github
admin
install
pages_template
qrcode
system
autoload
PEAR2
mail
Admin.php
App.php
Balance.php
File.php
Hookers.php
Http.php
Lang.php
Log.php
Message.php
Mikrotik.php
Package.php
Paginator.php
Password.php
Radius.php
Timezone.php
User.php
Validator.php
index.html
cache
controllers
lan
paymentgateway
plugin
uploads
vendor
.htaccess
api.php
boot.php
composer.json
composer.lock
cron.php
cron_reminder.php
index.html
orm.php
updates.json
ui
.gitignore
.htaccess_firewall
CHANGELOG.md
LICENSE
README.md
composer.json
config.sample.php
favicon.ico
index.php
init.php
update.php
version.json
65 lines
1.7 KiB
PHP
65 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
|
|
* by https://t.me/ibnux
|
|
**/
|
|
/**
|
|
* This script is for managing user balance
|
|
**/
|
|
|
|
class Balance
|
|
{
|
|
|
|
public static function plus($id_customer, $amount)
|
|
{
|
|
$c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one();
|
|
$c->balance = $amount + $c['balance'];
|
|
$c->save();
|
|
}
|
|
|
|
public static function transfer($id_customer, $phoneTarget, $amount)
|
|
{
|
|
global $config;
|
|
if (Balance::min($id_customer, $amount)) {
|
|
return Balance::plusByPhone($phoneTarget, $amount);
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static function min($id_customer, $amount)
|
|
{
|
|
$c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one();
|
|
if ($c && $c['balance'] >= $amount) {
|
|
$c->balance = $c['balance'] - $amount;
|
|
$c->save();
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static function plusByPhone($phone_customer, $amount)
|
|
{
|
|
$c = ORM::for_table('tbl_customers')->where('username', $phone_customer)->find_one();
|
|
if ($c) {
|
|
$c->balance = $amount + $c['balance'];
|
|
$c->save();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static function minByPhone($phone_customer, $amount)
|
|
{
|
|
$c = ORM::for_table('tbl_customers')->where('username', $phone_customer)->find_one();
|
|
if ($c && $c['balance'] >= $amount) {
|
|
$c->balance = $c['balance'] - $amount;
|
|
$c->save();
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
}
|