public function getUserBlocks($userId = null) { $userId = $userId ? $userId : \Users\User::$cur->id; $blocked = \Money\Wallet\Block::getList(['where' => [['wallet:user_id', $userId], [['date_expired', '0000-00-00 00:00:00'], ['date_expired', date('Y-m-d H:i:s'), '>', 'OR']]]]); $blocks = []; foreach ($blocked as $block) { if (empty($blocks[$block->wallet->currency_id])) { $blocks[$block->wallet->currency_id] = $block->amount; } else { $blocks[$block->wallet->currency_id] += $block->amount; } } return $blocks; }
<h3>Блокировки на счете</h3> <?php $currency_id = !empty($_GET['currency_id']) ? (int) $_GET['currency_id'] : 0; $wallets = App::$cur->money->getUserWallets(); if ($currency_id && empty($wallets[$currency_id])) { Msg::add('У вас нет такого кошелька'); Msg::show(); return; } if ($currency_id) { $ids = $wallets[$currency_id]->id; } else { $ids = []; foreach ($wallets as $wallet) { $ids[] = $wallet->id; } $ids = implode(',', $ids); } $table = new \Ui\Table(); $table->setCols(['№', 'Кошелек', 'Сумма', 'Комментарий', 'Дата']); //items pages $pages = new \Ui\Pages($_GET, ['count' => \Money\Wallet\Block::getCount(['where' => ['wallet_id', $ids, 'IN']]), 'limit' => 20]); $histories = \Money\Wallet\Block::getList(['where' => ['wallet_id', $ids, 'IN'], 'order' => [['date_create', 'DESC'], ['id', 'DESC']], 'start' => $pages->params['start'], 'limit' => $pages->params['limit']]); foreach ($histories as $history) { $amount = $history->amount; $table->addRow([$history->id, $history->wallet->currency->name(), '<span class = "' . ($amount > 0 ? "text-success" : 'text-danger') . '">' . $amount . '</span>', $history->comment, $history->date_create]); } $table->draw(); $pages->draw();
public function complete() { if ($this->canceled || $this->complete) { return false; } $this->complete = 1; $block = \Money\Wallet\Block::get('Money\\Transfer:' . $this->id, 'data'); if ($block) { $block->delete(); } $wallets = \App::$cur->money->getUserWallets($this->to_user_id); $text = 'Перевод средств от ' . $this->user->name() . '.' . ($this->comment ? ' Комментарий:' . $this->comment : ''); $wallets[$this->currency_id]->diff($this->amount, $text); \App::$cur->users->AddUserActivity($this->to_user_id, 4, $text . '<br />' . (double) $this->amount . ' ' . $wallets[$this->currency_id]->currency->acronym()); $this->save(); return true; }