public function getUserWallets($userId = null, $walletIdasKey = false, $forSelect = false, $transferOnly = false) { $userId = $userId ? $userId : \Users\User::$cur->id; if (!$userId) { return []; } $this->getUserBlocks($userId); $where = [['wallet', 1]]; if ($transferOnly) { $where[] = ['transfer', 1]; } $currencies = Money\Currency::getList(['where' => $where]); $wallets = Money\Wallet::getList(['where' => ['user_id', $userId], 'key' => 'currency_id']); $result = []; foreach ($currencies as $currency) { if (empty($wallets[$currency->id])) { $wallet = new Money\Wallet(); $wallet->user_id = $userId; $wallet->currency_id = $currency->id; $wallet->save(); $result[$walletIdasKey ? $wallet->id : $currency->id] = $forSelect ? $wallet->name() : $wallet; } else { $result[$walletIdasKey ? $wallets[$currency->id]->id : $currency->id] = $forSelect ? $wallets[$currency->id]->name() : $wallets[$currency->id]; } } return $result; }
public function refillAction($currencyId = 0) { $currency = null; if (!empty($_POST['currency_id'])) { $currency = Money\Currency::get((int) $_POST['currency_id']); } if ($currency && !empty($_POST['amount'])) { $pay = new Money\Pay(['data' => '', 'user_id' => \Users\User::$cur->id, 'currency_id' => $currency->id, 'sum' => (double) str_replace(',', '.', $_POST['amount']), 'type' => 'refill', 'description' => 'Пополнение баланса ' . $currency->name(), 'callback_module' => 'Money', 'callback_method' => 'refillPayRecive']); $pay->save(); Tools::redirect('/money/merchants/pay/' . $pay->id); } else { $currencies = Money\Currency::getList(['where' => ['refill', 1], 'forSelect' => true]); $this->view->setTitle('Пополнение счета'); $this->view->page(['data' => compact('currencies')]); } }
<?php $currencies = Money\Currency::getList(['where' => ['wallet', 1]]); if (!$currencies) { return false; } return ['name' => 'Мои кошельки', 'fullWidget' => 'Money\\cabinet/wallets', 'smallWidget' => 'Money\\cabinet/walletsWidget'];