phpnuxbill/system/autoload/Balance.php

65 lines
1.7 KiB
PHP
Raw Normal View History

<?php
2023-08-14 16:59:53 +08:00
/**
2023-10-12 16:55:42 +08:00
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* by https://t.me/ibnux
**/
/**
* This script is for managing user balance
2023-08-14 16:59:53 +08:00
**/
2023-08-14 16:59:53 +08:00
class Balance
{
2023-08-14 16:59:53 +08:00
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();
}
2023-08-14 16:59:53 +08:00
public static function transfer($id_customer, $phoneTarget, $amount)
{
global $config;
2023-08-23 17:46:05 +08:00
if (Balance::min($id_customer, $amount)) {
2023-09-13 16:38:56 +08:00
return Balance::plusByPhone($phoneTarget, $amount);
2023-08-18 10:47:03 +08:00
} else {
2023-08-14 16:59:53 +08:00
return false;
}
}
2023-08-14 16:59:53 +08:00
public static function min($id_customer, $amount)
{
$c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one();
if ($c && $c['balance'] >= $amount) {
2023-08-18 10:47:03 +08:00
$c->balance = $c['balance'] - $amount;
2023-08-14 16:59:53 +08:00
$c->save();
return true;
} else {
return false;
}
}
2023-08-14 16:59:53 +08:00
public static function plusByPhone($phone_customer, $amount)
{
$c = ORM::for_table('tbl_customers')->where('username', $phone_customer)->find_one();
2023-08-18 10:47:03 +08:00
if ($c) {
2023-08-14 16:59:53 +08:00
$c->balance = $amount + $c['balance'];
$c->save();
return true;
}
return false;
}
2023-08-14 16:59:53 +08:00
public static function minByPhone($phone_customer, $amount)
{
$c = ORM::for_table('tbl_customers')->where('username', $phone_customer)->find_one();
if ($c && $c['balance'] >= $amount) {
2023-08-18 10:47:03 +08:00
$c->balance = $c['balance'] - $amount;
2023-08-14 16:59:53 +08:00
$c->save();
return true;
} else {
return false;
}
}
2023-08-14 16:59:53 +08:00
}