Esempio n. 1
0
 public function walletPayAction($payId, $walletId)
 {
     $pay = Money\Pay::get((int) $payId);
     if (!$pay || $pay->user_id != \Users\User::$cur->id) {
         Tools::redirect('/money/merchants/pay/', 'Такой счет не найден');
     }
     $wallet = Money\Wallet::get((int) $walletId);
     if (!$wallet || $wallet->user_id != \Users\User::$cur->id) {
         Tools::redirect('/money/merchants/pay/' . $pay->id, 'Такой кошелек не найден');
     }
     if ($pay->currency_id != $wallet->currency_id) {
         $rate = \Money\Currency\ExchangeRate::get([['currency_id', $wallet->currency_id], ['target_currency_id', $pay->currency_id]]);
         if (!$rate) {
             Tools::redirect('/money/merchants/pay/' . $pay->id, 'Нет возможности оплатить счет в валюте ' . $pay->currency->name() . ' валютой ' . $wallet->currency->name());
         }
         $sum = $pay->sum / $rate->rate;
     } else {
         $sum = $pay->sum;
     }
     if ($sum > $wallet->amount) {
         Tools::redirect('/money/merchants/pay/' . $pay->id, 'На вашем счете недостаточно средств', 'danger');
     }
     $wallet->diff(-$sum, 'Оплата счета №' . $payId);
     $statuses = \Money\Pay\Status::getList(['key' => 'code']);
     if (!empty($statuses['success'])) {
         $pay->pay_status_id = $statuses['success']->id;
     }
     $pay->date_recive = date('Y-m-d H:i:s');
     $pay->save();
     if ($pay->callback_module && $pay->callback_method) {
         App::$cur->{$pay->callback_module}->{$pay->callback_method}(['status' => 'success', 'payId' => $pay->id, 'pay' => $pay]);
     }
     Tools::redirect('/users/cabinet', 'Вы успешно оплатили счет', 'success');
 }
Esempio n. 2
0
<?php

return ['name' => 'Валюта', 'params' => ['currency_id' => ['type' => 'select'], 'type' => ['type' => 'select', 'source' => 'array', 'sourceArray' => ['procent' => 'Процент', 'amount' => 'Кол-во']], 'amount' => ['type' => 'decimal']], 'viewer' => function ($level) {
    $levelTypes = ['procent' => 'Процент', 'amount' => 'Сумма'];
    return $levelTypes[$level->params['type']->value] . ': ' . $level->params['amount']->value . ' ' . ($level->params['type']->value == 'procent' ? '%' : ($level->params['currency_id']->value ? \Money\Currency::get($level->params['currency_id']->value)->acronym() : ''));
}, 'rewarder' => function ($reward, $sums, $user, $rootUser, $level, $rewardGet) {
    $wallets = \App::$cur->money->getUserWallets($user->id);
    $amount = 0;
    if (!empty($wallets[$level->params['currency_id']->value])) {
        switch ($level->params['type']->value) {
            case 'procent':
                $finalSum = 0;
                foreach ($sums as $currency_id => $sum) {
                    if ($currency_id != $level->params['currency_id']->value) {
                        $rate = \Money\Currency\ExchangeRate::get([['currency_id', $currency_id], ['target_currency_id', $level->params['currency_id']->value]]);
                        if ($rate) {
                            $finalSum += $sum * $rate->rate;
                        }
                    } else {
                        $finalSum += $sum;
                    }
                }
                switch ($reward->round_type) {
                    case 'round':
                        $finalSum = round($finalSum, $reward->round_precision);
                        $amount = $finalSum / 100 * (double) $level->params['amount']->value;
                        break;
                    case 'floor':
                        $finalSum = floor($finalSum);
                        $amount = $finalSum / 100 * (double) $level->params['amount']->value;
                        break;