public function RequestFriend($id) { $mongodb = Connections::get('default')->connection; $RequestFriend = Orders::connection()->connection->command(array('aggregate' => 'orders', 'pipeline' => array(array('$project' => array('_id' => 0, 'user_id' => '$user_id', 'TransactUsername' => '$Transact.username', 'TransactUser_id' => '$Transact.user_id', 'TransactDateTime' => '$Transact.DateTime', 'Completed' => '$Completed')), array('$match' => array('Completed' => 'Y', 'user_id' => $id)), array('$group' => array('_id' => array('TransactUsername' => '$TransactUsername', 'TransactUser_id' => '$TransactUser_id'))), array('$sort' => array('TransactUsername' => 1)), array('$limit' => 20)))); return $RequestFriend; }
use app\models\Parameters; use app\models\Pages; use app\models\Orders; use app\models\Trades; use lithium\core\Environment; use lithium\data\Connections; $Comm = Parameters::find('first'); $howmany = 100; $tradesV = Trades::find('first', array('conditions' => array('SecondType' => 'Virtual'), 'limit' => $howmany, 'order' => array('order' => 1))); $first_currency = substr($tradesV['trade'], 0, 3); $second_currency = substr($tradesV['trade'], 4, 3); $tradesVF = Trades::find('all', array('conditions' => array('SecondType' => 'Fiat'), 'limit' => $howmany, 'order' => array('order' => -1))); $trades = Trades::find('all', array('limit' => $howmany, 'order' => array('order' => 1))); $mongodb = Connections::get('default')->connection; $Rates = Orders::connection()->connection->command(array('aggregate' => 'orders', 'pipeline' => array(array('$project' => array('_id' => 0, 'Action' => '$Action', 'PerPrice' => '$PerPrice', 'Completed' => '$Completed', 'FirstCurrency' => '$FirstCurrency', 'SecondCurrency' => '$SecondCurrency', 'TransactDateTime' => '$Transact.DateTime')), array('$match' => array('Completed' => 'Y')), array('$group' => array('_id' => array('FirstCurrency' => '$FirstCurrency', 'SecondCurrency' => '$SecondCurrency', 'year' => array('$year' => '$TransactDateTime'), 'month' => array('$month' => '$TransactDateTime'), 'day' => array('$dayOfMonth' => '$TransactDateTime')), 'min' => array('$min' => '$PerPrice'), 'avg' => array('$avg' => '$PerPrice'), 'max' => array('$max' => '$PerPrice'), 'last' => array('$last' => '$PerPrice'))), array('$sort' => array('_id.year' => -1, '_id.month' => -1, '_id.day' => -1, '_id.hour' => -1)), array('$limit' => count($trades))))); ?> <p> </p> <div class="container-fluid"> <div class="row placeholders"> <?php foreach ($tradesVF as $tradeVF) { if (substr($tradeVF['trade'], 0, 3) == $second_currency) { ?> <div class="col-xs-6 col-sm-6 placeholder" style="text-align:center"> <h4><?php echo $tradeVF['trade']; ?> </h4> <?php foreach ($Rates['result'] as $rate) {
public function commission() { if ($this->__init() == false) { $this->redirect('ex::dashboard'); } if ($this->request->data) { $StartDate = new MongoDate(strtotime($this->request->data['StartDate'])); $EndDate = new MongoDate(strtotime($this->request->data['EndDate'])); } else { $StartDate = new MongoDate(strtotime(gmdate('Y-m-d H:i:s', mktime(0, 0, 0, gmdate('m', time()), gmdate('d', time()), gmdate('Y', time())) - 60 * 60 * 24 * 30))); $EndDate = new MongoDate(strtotime(gmdate('Y-m-d H:i:s', mktime(0, 0, 0, gmdate('m', time()), gmdate('d', time()), gmdate('Y', time())) + 60 * 60 * 24 * 1))); } $mongodb = Connections::get('default')->connection; $Commissions = Orders::connection()->connection->command(array('aggregate' => 'orders', 'pipeline' => array(array('$project' => array('_id' => 0, 'Action' => '$Action', 'Amount' => '$Amount', 'Completed' => '$Completed', 'CommissionAmount' => '$Commission.Amount', 'CommissionCurrency' => '$Commission.Currency', 'FirstCurrency' => '$FirstCurrency', 'SecondCurrency' => '$SecondCurrency', 'DateTime' => '$DateTime', 'username' => '$username')), array('$match' => array('DateTime' => array('$gte' => $StartDate, '$lte' => $EndDate), 'Completed' => 'Y', 'username' => array('$nin' => array('SiiCrypto.comUserA', 'SiiCrypto.comUserB', 'SiiCrypto.comUserC', 'SiiCrypto.comUserD')))), array('$group' => array('_id' => array('CommissionCurrency' => '$CommissionCurrency', 'year' => array('$year' => '$DateTime'), 'month' => array('$month' => '$DateTime'), 'day' => array('$dayOfMonth' => '$DateTime')), 'CommissionAmount' => array('$sum' => '$CommissionAmount'), 'Transactions' => array('$sum' => 1))), array('$sort' => array('_id.year' => -1, '_id.month' => -1, '_id.day' => -1)), array('$limit' => 30)))); $new = array(); $days = ($EndDate->sec - $StartDate->sec) / (60 * 60 * 24); for ($i = 0; $i <= $days + 1; $i++) { $date = gmdate('Y-m-d', $EndDate->sec - $i * 60 * 60 * 24); $new[$date] = array(); } foreach ($Commissions['result'] as $UR) { $URdate = date_create($UR['_id']['year'] . "-" . $UR['_id']['month'] . "-" . $UR['_id']['day']); $urDate = date_format($URdate, "Y-m-d"); $new[$urDate]['Transactions'] = $UR['Transactions']; if ($UR['_id']['CommissionCurrency'] == 'BTC') { $new[$urDate]['BTC'] = $UR['CommissionAmount']; } if ($UR['_id']['CommissionCurrency'] == 'XGC') { $new[$urDate]['XGC'] = $UR['CommissionAmount']; } if ($UR['_id']['CommissionCurrency'] == 'GBP') { $new[$urDate]['GBP'] = $UR['CommissionAmount']; } if ($UR['_id']['CommissionCurrency'] == 'EUR') { $new[$urDate]['EUR'] = $UR['CommissionAmount']; } if ($UR['_id']['CommissionCurrency'] == 'USD') { $new[$urDate]['USD'] = $UR['CommissionAmount']; } if ($UR['_id']['CommissionCurrency'] == 'CAD') { $new[$urDate]['CAD'] = $UR['CommissionAmount']; } } $title = "Commission"; $keywords = "Admin Commission"; $description = "Admin panel for commission"; return compact('new', 'StartDate', 'EndDate', 'title', 'keywords', 'description'); }
public function Orders($FirstCurrency = "BTC", $SecondCurrency = "USD") { $mongodb = Connections::get('default')->connection; $TotalSellOrders = Orders::connection()->connection->command(array('aggregate' => 'orders', 'pipeline' => array(array('$project' => array('_id' => 0, 'Action' => '$Action', 'Amount' => '$Amount', 'Completed' => '$Completed', 'FirstCurrency' => '$FirstCurrency', 'SecondCurrency' => '$SecondCurrency', 'TotalAmount' => array('$multiply' => array('$Amount', '$PerPrice')))), array('$match' => array('Action' => 'Sell', 'Completed' => 'N', 'FirstCurrency' => $FirstCurrency, 'SecondCurrency' => $SecondCurrency)), array('$group' => array('_id' => array(), 'Amount' => array('$sum' => '$Amount'), 'TotalAmount' => array('$sum' => '$TotalAmount'))), array('$sort' => array('PerPrice' => 1))))); $TotalBuyOrders = Orders::connection()->connection->command(array('aggregate' => 'orders', 'pipeline' => array(array('$project' => array('_id' => 0, 'Action' => '$Action', 'Amount' => '$Amount', 'Completed' => '$Completed', 'FirstCurrency' => '$FirstCurrency', 'SecondCurrency' => '$SecondCurrency', 'TotalAmount' => array('$multiply' => array('$Amount', '$PerPrice')))), array('$match' => array('Action' => 'Buy', 'Completed' => 'N', 'FirstCurrency' => $FirstCurrency, 'SecondCurrency' => $SecondCurrency)), array('$group' => array('_id' => array(), 'Amount' => array('$sum' => '$Amount'), 'TotalAmount' => array('$sum' => '$TotalAmount'))), array('$sort' => array('PerPrice' => 1))))); $SellOrders = Orders::connection()->connection->command(array('aggregate' => 'orders', 'pipeline' => array(array('$project' => array('_id' => 0, 'Action' => '$Action', 'Amount' => '$Amount', 'user_id' => '$user_id', 'PerPrice' => '$PerPrice', 'Completed' => '$Completed', 'FirstCurrency' => '$FirstCurrency', 'SecondCurrency' => '$SecondCurrency')), array('$match' => array('Action' => 'Sell', 'Completed' => 'N', 'FirstCurrency' => $FirstCurrency, 'SecondCurrency' => $SecondCurrency)), array('$group' => array('_id' => array('PerPrice' => '$PerPrice'), 'Amount' => array('$sum' => '$Amount'), 'No' => array('$sum' => 1))), array('$sort' => array('_id.PerPrice' => 1))))); $BuyOrders = Orders::connection()->connection->command(array('aggregate' => 'orders', 'pipeline' => array(array('$project' => array('_id' => 0, 'Action' => '$Action', 'user_id' => '$user_id', 'Amount' => '$Amount', 'PerPrice' => '$PerPrice', 'Completed' => '$Completed', 'FirstCurrency' => '$FirstCurrency', 'SecondCurrency' => '$SecondCurrency')), array('$match' => array('Action' => 'Buy', 'Completed' => 'N', 'FirstCurrency' => $FirstCurrency, 'SecondCurrency' => $SecondCurrency)), array('$group' => array('_id' => array('PerPrice' => '$PerPrice'), 'Amount' => array('$sum' => '$Amount'), 'No' => array('$sum' => 1))), array('$sort' => array('_id.PerPrice' => -1))))); foreach ($TotalBuyOrders['result'] as $TBO) { $BuyAmount = $TBO['Amount']; $BuyTotalAmount = $TBO['TotalAmount']; } $BuyOrdersHTML = '<table class="table table-condensed table-bordered table-hover" style="font-size:12px "> <thead> <tr> <th style="text-align:center " rowspan="2">#</th> <th style="text-align:center ">Price</th> <th style="text-align:center ">' . $FirstCurrency . '</th> <th style="text-align:center ">' . $SecondCurrency . '</th> </tr> <tr> <th style="text-align:center " >Total »</th> <th style="text-align:right " >' . number_format($BuyAmount, 8) . '</th> <th style="text-align:right " >' . number_format($BuyTotalAmount, 8) . '</th> </tr> </thead> <tbody>'; $BuyOrderAmount = 0; foreach ($BuyOrders['result'] as $BO) { $BuyOrderPrice = number_format(round($BO['_id']['PerPrice'], 8), 8); $BuyOrderAmount = number_format(round($BO['Amount'], 8), 8); $BuyOrdersHTML = $BuyOrdersHTML . '<tr onClick="BuyOrderFill(' . $BuyOrderPrice . ',' . $BuyOrderAmount . ');" style="cursor:pointer" class=" tooltip-x" rel="tooltip-x" data-placement="top" title="Sell ' . $BuyOrderAmount . ' ' . $FirstCurrency . ' at ' . $BuyOrderPrice . ' ' . $SecondCurrency . '"> <td style="text-align:right">' . $BO['No'] . $BO['_id']['username'] . '</td> <td style="text-align:right">' . number_format(round($BO['_id']['PerPrice'], 8), 8) . '</td> <td style="text-align:right">' . number_format(round($BO['Amount'], 8), 8) . '</td> <td style="text-align:right">' . number_format(round($BO['_id']['PerPrice'] * $BO['Amount'], 8), 8) . '</td> </tr>'; } $BuyOrdersHTML = $BuyOrdersHTML . '</tbody> </table>'; foreach ($TotalSellOrders['result'] as $TSO) { $SellAmount = $TSO['Amount']; $SellTotalAmount = $TSO['TotalAmount']; } $SellOrdersHTML = '<table class="table table-condensed table-bordered table-hover" style="font-size:12px "> <thead> <tr> <th style="text-align:center " rowspan="2">#</th> <th style="text-align:center " >Price</th> <th style="text-align:center " >' . $FirstCurrency . '</th> <th style="text-align:center " >' . $SEcondCurrency . '</th> </tr> <tr> <th style="text-align:center " >Total »</th> <th style="text-align:right " >' . number_format($SellAmount, 8) . '</th> <th style="text-align:right " >' . number_format($SellTotalAmount, 8) . '</th> </tr> </thead> <tbody>'; $SellOrderAmount = 0; foreach ($SellOrders['result'] as $SO) { $SellOrderPrice = number_format(round($SO['_id']['PerPrice'], 8), 8); $SellOrderAmount = number_format(round($SO['Amount'], 8), 8); $SellOrdersHTML = $SellOrdersHTML . '<tr onClick="SellOrderFill(' . $SellOrderPrice . ',' . $SellOrderAmount . ');" style="cursor:pointer" class=" tooltip-x" rel="tooltip-x" data-placement="top" title="Buy ' . $SellOrderAmount . ' ' . $FirstCurrency . ' at ' . $SellOrderPrice . ' ' . $SecondCurrency . '"> <td style="text-align:right">' . $SO['No'] . $SO['_id']['user_id'] . '</td> <td style="text-align:right">' . number_format(round($SO['_id']['PerPrice'], 8), 8) . '</td> <td style="text-align:right">' . number_format(round($SO['Amount'], 8), 8) . '</td> <td style="text-align:right">' . number_format(round($SO['Amount'] * $SO['_id']['PerPrice'], 8), 8) . '</td> </tr>'; } $SellOrdersHTML = $SellOrdersHTML . ' </tbody> </table>'; return $this->render(array('json' => array('BuyOrdersHTML' => $BuyOrdersHTML, 'SellOrdersHTML' => $SellOrdersHTML))); }