Пример #1
0
function web_controller_user_profile()
{
    lets_use('user_self', 'billing_log');
    $balance = user_self_balance();
    $transactions = billing_log_get_user_transactions(user_self_id());
    web_router_render_page('user', 'profile', ['balance' => $balance, 'transactions' => $transactions]);
}
Пример #2
0
function web_controller_index_index()
{
    lets_use('user_self');
    if (user_self_id()) {
        web_router_call('order', 'list', '');
        return;
    }
    web_router_render_page('index', 'index');
}
Пример #3
0
function user_self_balance()
{
    lets_use('billing_balance', 'billing_account');
    $userId = user_self_id();
    core_log('user_id: ' . $userId, __FUNCTION__);
    if (!$userId) {
        return 0;
    }
    $account = billing_account_get_user_main_account($userId);
    return billing_balance_get_account_amount($account);
}
Пример #4
0
function web_controller_order_mine()
{
    lets_use('storage_db', 'order_storage', 'user_self');
    $posts = order_storage_get_by_user(user_self_id());
    $authors = [];
    if ($posts) {
        $authors = storage_db_get_rows('users', '*', [['id', array_unique(array_column($posts, 'author_id'))]], [], 'id');
    }
    web_router_render_page('order', 'list', ['posts' => $posts, 'authors' => $authors]);
}
Пример #5
0
function web_controller_billing_refill()
{
    lets_use('web_router', 'billing_balance', 'billing_account', 'billing_transaction', 'billing_locks', 'user_self');
    $incomingSource = 1;
    // благотоврительный фонд
    $sum = (double) web_router_get_param('sum');
    $sum = round($sum, 2);
    $accountFrom = billing_account_get_income_account($incomingSource);
    $accountTo = billing_account_get_user_main_account(user_self_id());
    $trId = billing_transaction_register($accountFrom, $accountTo, $sum);
    if (!$trId) {
        // cant register transaction
        billing_transaction_fail($trId);
        web_router_render_page('billing', 'refill', ['result' => false, 'msg' => 'Ошибка сервера, повторите позже.']);
        return;
    }
    $lockRes = billing_locks_lock_transaction($trId, [$accountFrom, $accountTo]);
    if (!$lockRes) {
        // cant lock transaction
        billing_transaction_fail($trId);
        web_router_render_page('billing', 'refill', ['result' => false, 'msg' => 'В данный момент операция невозможна, повторите позже']);
        return;
    }
    $movementPossible = billing_balance_check_sum_available($accountFrom, $sum);
    if (!$movementPossible) {
        // not enough money
        billing_transaction_fail($trId);
        billing_locks_unlock_transaction($trId);
        web_router_render_page('billing', 'refill', ['result' => false, 'msg' => 'На исходящем счете недостаточно денег']);
        return;
    }
    $dbTransactionLock = billing_balance_storage_transaction_start();
    if (!$dbTransactionLock) {
        // cant begin db transaction
        billing_transaction_fail($trId);
        billing_locks_unlock_transaction($trId);
        web_router_render_page('billing', 'refill', ['result' => false, 'msg' => 'Не удалось начать транзакцию']);
        return;
    }
    $moveRes = billing_balance_process_move($accountFrom, $accountTo, $sum, $trId);
    if (!$moveRes) {
        // cant move money
        billing_balance_storage_transaction_rollback();
        billing_transaction_fail($trId);
        billing_locks_unlock_transaction($trId);
        web_router_render_page('billing', 'refill', ['result' => false, 'msg' => 'Не удалось перевести деньги']);
        return;
    }
    $transactionCommit = billing_balance_storage_transaction_commit();
    if ($transactionCommit) {
        // cant commit db transaction
        billing_transaction_fail($trId);
        billing_locks_unlock_transaction($trId);
        web_router_render_page('billing', 'refill', ['result' => false, 'msg' => 'Не удалось завершить транзакцию']);
        return;
    }
    billing_transaction_success($trId);
    billing_locks_unlock_transaction($trId);
    $moneyNow = billing_balance_get_account_amount($accountTo);
    web_router_render_page('billing', 'refill', ['result' => true, 'msg' => $sum . ' денежных единиц успешно переведены вам на счет. На вашем счету теперь: ' . $moneyNow]);
}