public function beforeSave() { if ($this->pk()) { $cur = Wallet::get($this->pk()); if ($cur->amount != $this->amount) { $history = new Wallet\History(); $history->wallet_id = $this->pk(); $history->old = $cur->amount; $history->new = $this->amount; $history->amount = $this->amount - $cur->amount; $history->save(); } } }
public function cronUpdateDeposit() { $wallets = Wallet::get(); $balance = new Balance(); //Log::info('buy_orders_matching: market_id: '.$market_id.' -- Price: '.$price_sell, $buy_orders_matching); Log::info('********************* Start cron *****************************'); $message = '********************* Start cron *****************************'; foreach ($wallets as $wallet) { try { $wallet->connectJsonRPCclient($wallet->wallet_username, $wallet->wallet_password, $wallet->wallet_ip, $wallet->port); $listtrans = $wallet->getListTransactions(); foreach ($listtrans as $key => $value) { $transaction_id = $value['txid']; $trans = $wallet->getTransaction($transaction_id); if ($trans != null) { $account = $trans["details"][0]["account"]; $category = $trans["details"][0]["category"]; $confirms = $trans["confirmations"]; //send,receive $address_ = $trans["details"][0]["address"]; $amount = $trans["amount"]; //$message.="<br>account: ".$account." -- category:".$category." --address: ".$address_; Log::info("\n" . "transaction: ", $trans); //mail("*****@*****.**", 'Deposit Cron: ', var_export($trans, true)); $deposit = Deposit::where('transaction_id', $transaction_id)->first(); $user = User::where('username', $account)->first(); if (!empty($user)) { Log::info("\n" . "user---------: ", $user); } if (isset($deposit->id)) { //$message.="<br>user_id: ".$deposit->id; if ($deposit->paid == 0) { if ($category == "receive" && $confirms > 2 && isset($user->id)) { Deposit::where('id', $deposit->id)->update(array('paid' => 1, 'confirmations' => $confirms)); $balance->addMoney($amount, $wallet->id, $user->id); $message .= "<br>" . $amount . " " . $wallet->type . " was credited to your account"; Log::info("\n" . $amount . " " . $wallet->type . " was credited to your account"); } } else { $message .= "<br>" . $amount . " " . $wallet->type . " was already credited to your account. contact support if you need further assistance."; Log::info("\n" . $amount . " " . $wallet->type . " was already credited to your account. contact support if you need further assistance."); } } else { if ($category == "receive" && isset($user->id)) { if ($confirms > 2) { Deposit::insert(array('user_id' => $user->id, 'wallet_id' => $wallet->id, 'transaction_id' => $transaction_id, 'amount' => $amount, 'paid' => 1, 'confirmations' => $confirms, 'address' => $address_, 'created_at' => date('Y-m-d H:i:s'))); $balance->addMoney($amount, $wallet->id, $user->id); $message .= "<br>" . $amount . " " . $wallet->type . " was credited to your account"; Log::info("\n" . $amount . " " . $wallet->type . " was credited to your account"); } else { Deposit::insert(array('user_id' => $user->id, 'wallet_id' => $wallet->id, 'transaction_id' => $transaction_id, 'amount' => $amount, 'paid' => 0, 'confirmations' => $confirms, 'address' => $address_, 'created_at' => date('Y-m-d H:i:s'))); $message .= "<br>This Deposit is unconfirmed. Current confirmations:" . $confirms . ". Required : 6."; Log::info("\n" . "This Deposit is unconfirmed. Current confirmations:" . $confirms . ". Required : 6."); } } else { //$message.="<br>transaction is not a deposit or account is invalid."; Log::info("\n" . "transaction is not a deposit or account is invalid."); } } } else { //$message.="<br>We can't find any information about this deposit. contact support."; Log::info("\n" . "We can't find any information about this deposit. contact support."); } //trans } //listtrans } catch (Exception $e) { //$message.='<br>Cron Update Deposit: Caught exception: '.$e->getMessage(); Log::info("\n" . 'Cron Update Deposit: Caught exception: ' . $e->getMessage()); } } //wallets Log::info("\n" . '********************* Stop cron *****************************'); $message .= '********************* Stop cron *****************************'; $data['message'] = $message; return View::make('cronupdatedeposit', $data); }
public function viewprofile($page = '', $filter = '') { $user = Confide::user(); $user_id = $user->id; $data = array(); $data['user_id'] = $user_id; $data['user'] = $user; if ($user_id > 0) { $profile = User::leftJoin('users_roles', 'users.id', '=', 'users_roles.user_id')->join('roles', 'roles.id', '=', 'users_roles.role_id')->select('users.*', 'roles.name as rolename')->where('users.id', '=', $user_id)->get(); if ($profile) { $data['profile'] = $profile->first()->toArray(); } } $data['page'] = $page; $data['filter'] = $filter; $balance = new Balance(); $order = new Order(); $market = new Market(); $wallet = new Wallet(); $setting = new Setting(); $data['disable_points'] = $setting->getSetting('disable_points', 0); switch ($page) { case 'balances': $wallets = Wallet::orderBy('name')->get()->toArray(); foreach ($wallets as $key => $value) { $wallet_id = $value['id']; //get balance $balance_amount = $balance->getBalance($wallet_id); $wallets[$key]['balance'] = sprintf('%.8f', $balance_amount); //get PENDING DEPOSITS $deposit_pendding = Deposit::where('user_id', '=', $user_id)->where('wallet_id', '=', $wallet_id)->where('paid', '=', 0)->sum('amount'); $wallets[$key]['deposit_pendding'] = sprintf('%.8f', $deposit_pendding); //get PENDING WITHDRAWALS $withdraw_pendding = Withdraw::where('user_id', '=', $user_id)->where('wallet_id', '=', $wallet_id)->where('status', '=', 0)->sum('amount'); $wallets[$key]['withdraw_pendding'] = sprintf('%.8f', $withdraw_pendding); //get HELD FOR ORDERS //giao dich ban se giam tien cua wallet hien tai, doi voi btc/ltc (dong tien trao doi) thi giao dich mua se giam tien no //vi vay can xac dinh dau la btc/ltc, bang cach dua vao market, wallet_to trong market chinh la dong tien chinh de trao doi $wallets_to = Market::select("market.wallet_to")->distinct()->get(); $wal_to = array(); foreach ($wallets_to as $value) { $wal_to[] = $value->wallet_to; } //$wallets_to = array_column($market, 'wallet_to'); $status_active = $order->getStatusActive(); /*if(in_array($wallet_id,$wal_to)){ $held_order = Order::leftJoin('market', 'orders.market_id', '=', 'market.id') ->where('market.wallet_to','=',$wallet_id) ->where('orders.user_id','=',$user_id) ->whereIn('status', $status_active) ->sum('to_value'); }else{*/ $held_order = Order::leftJoin('market', 'orders.market_id', '=', 'market.id')->where('market.wallet_from', '=', $wallet_id)->where('orders.user_id', '=', $user_id)->where('type', '=', 'sell')->whereIn('status', $status_active)->sum('from_value'); //} $wallets[$key]['held_order'] = sprintf('%.8f', $held_order); } //echo "<pre>ggg?: "; print_r($wallets); echo "</pre>"; $data['balances'] = $wallets; break; case 'orders': $record_per_page = 15; if (empty($_GET['pager_page'])) { $pager_page = 1; } else { $pager_page = $_GET['pager_page']; } $data['cur_page'] = $pager_page; $offset_start = ($pager_page - 1) * $record_per_page; $select = "select a.*, b.wallet_from as `from`, b.wallet_to as `to` from orders a left join market b on a.market_id=b.id where a.user_id='" . $user_id . "' "; if ($filter != '') { $data['current_coin'] = $wallet->getType($filter); $select .= " AND (b.wallet_to='" . $filter . "' OR b.wallet_from='" . $filter . "') "; } if (isset($_GET['do_filter'])) { if (!empty($_GET['market'])) { $select .= " AND a.market_id='" . $_GET['market'] . "'"; } if ($_GET['status'] != '') { $select .= " AND a.status='" . $_GET['status'] . "'"; } if ($_GET['type'] != '') { $select .= " AND a.type='" . $_GET['type'] . "'"; } } $select_count = $select; $total_records = DB::select($select_count); $data['total_pages'] = ceil(count($total_records) / $record_per_page); $select .= " order by `created_at` desc limit " . $offset_start . "," . $record_per_page; $ordershistory = DB::select($select); //echo "<pre>ordershistory: "; print_r($ordershistory); echo "</pre>"; //echo "<pre>".dd(DB::getQueryLog())."</pre>"; $data['ordershistories'] = $ordershistory; $markets = Market::get(); $market_wallet = array(); foreach ($markets as $value) { $market_wallet[$value->id] = $market->getWalletType($value->id); } $data['markets'] = $market_wallet; break; case 'trade-history': $record_per_page = 15; if (empty($_GET['pager_page'])) { $pager_page = 1; } else { $pager_page = $_GET['pager_page']; } $data['cur_page'] = $pager_page; $offset_start = ($pager_page - 1) * $record_per_page; $select = "select a.*, b.wallet_from as `from`, b.wallet_to as `to` from trade_history a left join market b on a.market_id=b.id where (a.seller_id='" . $user_id . "' OR a.buyer_id ='" . $user_id . "') "; if ($filter != '') { $data['current_coin'] = $wallet->getType($filter); $select .= " AND (b.wallet_to='" . $filter . "' OR b.wallet_from='" . $filter . "') "; } if (isset($_GET['do_filter'])) { if (!empty($_GET['market'])) { $select .= " AND a.market_id='" . $_GET['market'] . "'"; } if (!empty($_GET['type'])) { $select .= " AND a.type='" . $_GET['type'] . "'"; } } $select_count = $select; $total_records = DB::select($select_count); //echo "<pre>total_records: "; print_r($total_records); echo "</pre>"; exit; $data['total_pages'] = ceil(count($total_records) / $record_per_page); $select .= " order by `created_at` desc limit " . $offset_start . "," . $record_per_page; $trades = DB::select($select); $data['tradehistories'] = $trades; $markets = Market::get(); $market_wallet = array(); foreach ($markets as $value) { $market_wallet[$value->id] = $market->getWalletType($value->id); } $data['markets'] = $market_wallet; break; case 'deposits': $deposits = Deposit::leftJoin('wallets', 'deposits.wallet_id', '=', 'wallets.id')->select('deposits.*', 'wallets.name', 'wallets.type')->where('user_id', '=', $user_id); if ($filter != '') { $data['current_coin'] = $wallet->getType($filter); $deposits = $deposits->where('deposits.wallet_id', '=', $filter); } if (isset($_POST['do_filter'])) { if (isset($_POST['wallet']) && $_POST['wallet'] != '') { $deposits = $deposits->where('wallet_id', '=', $_POST['wallet']); } if ($_POST['status'] != '') { $deposits = $deposits->where('paid', '=', $_POST['status']); } } $deposits = $deposits->orderBy('created_at', 'desc')->get(); //echo "<pre>_POST: "; print_r($_POST); echo "</pre>"; //echo "<pre>"; echo dd(DB::getQueryLog()); echo "</pre>"; $data['deposits'] = $deposits; $wallets = Wallet::select('id', 'type', 'name')->get(); $data['wallets'] = $wallets; break; case 'withdrawals': $withdrawals = Withdraw::leftJoin('wallets', 'withdraws.wallet_id', '=', 'wallets.id')->select('withdraws.*', 'wallets.name', 'wallets.type')->where('user_id', '=', $user_id); if ($filter != '') { $data['current_coin'] = $wallet->getType($filter); $withdrawals = $withdrawals->where('withdraws.wallet_id', '=', $filter); } if (isset($_POST['do_filter'])) { if ($_POST['wallet'] != '') { $withdrawals = $withdrawals->where('wallet_id', '=', $_POST['wallet']); } if ($_POST['status'] != '') { $withdrawals = $withdrawals->where('status', '=', $_POST['status']); } } $withdrawals = $withdrawals->orderBy('created_at', 'desc')->get(); //echo "<pre>_POST: "; print_r($_POST); echo "</pre>"; //echo "<pre>"; echo dd(DB::getQueryLog()); echo "</pre>"; $data['withdrawals'] = $withdrawals; $wallets = Wallet::select('id', 'type', 'name')->get(); $data['wallets'] = $wallets; break; case 'viewtranferin': $record_per_page = 15; if (empty($_GET['pager_page'])) { $pager_page = 1; } else { $pager_page = $_GET['pager_page']; } $data['cur_page'] = $pager_page; $offset_start = ($pager_page - 1) * $record_per_page; //$offset_end = ($pager_page*$record_per_page)-1; $select = "select a.*, b.type, b.name , c.username from transfer_history a left join wallets b on a.wallet_id=b.id left join users c on a.receiver=c.id where a.receiver='" . $user_id . "'"; $select_count = "select count(*) as total from transfer_history a where a.receiver='" . $user_id . "'"; if ($filter != '') { $data['current_coin'] = $wallet->getType($filter); $select .= " AND a.wallet_id='" . $filter . "'"; } $where = ''; if (isset($_GET['do_filter'])) { if ($where == '') { if (!empty($_GET['wallet'])) { $where = $where . " AND a.wallet_id='" . $_GET['wallet'] . "'"; } } } $select_count = $select_count . " " . $where . " order by `created_at` desc"; $total_records = DB::select($select_count); //echo "<pre>total_records: "; print_r($total_records); echo "</pre>"; exit; $data['total_pages'] = ceil($total_records[0]->total / $record_per_page); $select .= " " . $where . " order by `created_at` desc limit " . $offset_start . "," . $record_per_page; $transferins = DB::select($select); $data['transferins'] = $transferins; $wallets_temp = Wallet::get(); $wallets = array(); foreach ($wallets_temp as $wallet) { $wallets[$wallet->id] = $wallet; } $data['wallets'] = $wallets; break; case 'viewtranferout': $record_per_page = 2; if (empty($_GET['pager_page'])) { $pager_page = 1; } else { $pager_page = $_GET['pager_page']; } $data['cur_page'] = $pager_page; $offset_start = ($pager_page - 1) * $record_per_page; //$offset_end = ($pager_page*$record_per_page)-1; $select = "select a.*, b.type, b.name , c.username from transfer_history a left join wallets b on a.wallet_id=b.id left join users c on a.sender=c.id where a.sender='" . $user_id . "'"; $select_count = "select count(*) as total from transfer_history a where a.sender='" . $user_id . "'"; if ($filter != '') { $data['current_coin'] = $wallet->getType($filter); $select .= " AND a.wallet_id='" . $filter . "'"; } $where = ''; if (isset($_GET['do_filter'])) { if ($where == '') { if (!empty($_GET['wallet'])) { $where = $where . " AND a.wallet_id='" . $_GET['wallet'] . "'"; } } } $select_count = $select_count . " " . $where . " order by `created_at` desc"; $total_records = DB::select($select_count); //echo "<pre>total_records: "; print_r($total_records); echo "</pre>"; $data['total_pages'] = ceil($total_records[0]->total / $record_per_page); $select .= " " . $where . " order by `created_at` desc limit " . $offset_start . "," . $record_per_page; $transferouts = DB::select($select); $data['transferouts'] = $transferouts; $wallets_temp = Wallet::get(); $wallets = array(); foreach ($wallets_temp as $wallet) { $wallets[$wallet->id] = $wallet; } $data['wallets'] = $wallets; break; case 'dashboard': $total_trades = Trade::where('seller_id', $user_id)->orwhere('buyer_id', $user_id)->get()->toArray(); $data['total_trades'] = count($total_trades); $order = new Order(); $total_openordes = Order::where('user_id', $user_id)->whereIn('status', $order->getStatusActive())->get()->toArray(); $data['total_openordes'] = count($total_openordes); $twentyfourhours = date('Y-m-d H:i:s', strtotime('-24 hour')); $deposit_twentyfourhours = Deposit::where('user_id', $user_id)->where('created_at', ">=", $twentyfourhours)->get()->toArray(); $data['deposit_twentyfourhours'] = count($deposit_twentyfourhours); $withdraw_twentyfourhours = Withdraw::where('user_id', $user_id)->where('created_at', ">=", $twentyfourhours)->get()->toArray(); $data['withdraw_twentyfourhours'] = count($withdraw_twentyfourhours); $deposit_pendings = Deposit::where('user_id', $user_id)->where('paid', 0)->get()->toArray(); $data['deposit_pendings'] = count($deposit_pendings); $total_referred = User::where('referral', $user->username)->get()->toArray(); $data['total_referred'] = count($total_referred); //echo "<pre>total_referred: "; print_r($total_referred); echo "</pre>"; break; case "ecoinstraderpoint": $setting = new Setting(); $data['point_per_btc'] = $setting->getSetting('point_per_btc', 1); $data['percent_point_reward_trade'] = $setting->getSetting('percent_point_reward_trade', 0); $data['percent_point_reward_referred_trade'] = $setting->getSetting('percent_point_reward_referred_trade', 0); break; case "verify": $userinfo = UserInformation::where('user_id', $user_id)->first(); //echo "<pre>userinfo: "; print_r($userinfo); echo "</pre>"; $data['userinfo'] = $userinfo; break; } return View::make('user.profile', $data); }
public function doTest() { //BrainSocket::message('doTest', array('message'=>Wallet::get()->toArray())); echo json_encode(Wallet::get()->toArray()); exit; }
public function routePage($page = '', $pager_page = '') { $markets = Market::where('active', 1)->get(); $market_wallet = array(); foreach ($markets as $market) { $market_wallet[$market->id] = $market->getWalletType($market->id); } $data['markets'] = $market_wallet; switch ($page) { case 'fee': $data['fee_trades'] = FeeTrade::leftJoin('market', 'fee_trade.market_id', '=', 'market.id')->leftJoin('wallets', 'market.wallet_from', '=', 'wallets.id')->select('fee_trade.*', 'market.wallet_from', 'wallets.name', 'wallets.type')->orderby('wallets.name', 'asc')->get(); //echo "<pre>fee_trades: "; print_r($fee_trades); echo "</pre>"; //echo "<pre>markets: "; print_r($markets); echo "</pre>";exit; return View::make('admin.setting_fee', $data); break; case 'fee-withdraw': $data['fee_withdraws'] = FeeWithdraw::leftjoin('wallets', 'fee_withdraw.wallet_id', '=', 'wallets.id')->select('fee_withdraw.*', 'wallets.type', 'wallets.name')->orderby('wallets.type')->get(); return View::make('admin.setting_fee_withdraw', $data); break; case 'limit-trade': $record_per_page = 15; $total = WalletLimitTrade::count(); if ($pager_page == '') { $pager_page = 1; } $data['total_pages'] = ceil($total / $record_per_page); //15 user per page $data['cur_page'] = $pager_page; $offset_start = ($pager_page - 1) * $record_per_page; $data['wallets'] = Wallet::orderby('type')->get(); $data['limit_trades'] = WalletLimitTrade::leftjoin('wallets', 'wallet_limittrade.wallet_id', '=', 'wallets.id')->select('wallet_limittrade.*', 'wallets.type as wallet_type', 'wallets.name as wallet_name')->skip($offset_start)->take($record_per_page)->orderby('wallet_type')->get(); return View::make('admin.limittrade.setting_limittrade', $data); break; //add newbie //add newbie case 'time-limit-trade': $record_per_page = 15; $total = WalletTimeLimitTrade::count(); if ($pager_page == '') { $pager_page = 1; } $data['total_pages'] = ceil($total / $record_per_page); //15 user per page $data['cur_page'] = $pager_page; $offset_start = ($pager_page - 1) * $record_per_page; $data['wallets'] = Wallet::orderby('type')->get(); $data['limit_trades'] = WalletTimeLimitTrade::leftjoin('wallets', 'wallet_timelimittrade.wallet_id', '=', 'wallets.id')->select('wallet_timelimittrade.*', 'wallets.type as wallet_type', 'wallets.name as wallet_name')->skip($offset_start)->take($record_per_page)->orderby('wallet_type')->get(); return View::make('admin.limittrade.setting_timelimittrade', $data); break; case 'statistic-coin-exchanged': $select = "SELECT mk.wallet_from, mk.wallet_to, sum(amount) as total_amount from trade_history a left join market mk on a.market_id=mk.id"; $select_maincoin = "SELECT mk.wallet_from, mk.wallet_to, sum(amount*price) as total_amount from trade_history a left join market mk on a.market_id=mk.id"; $where = ''; if (isset($_GET['filter_time']) && $_GET['filter_time'] != '') { switch ($_GET['filter_time']) { case 'hourly': $hourly = date('Y-m-d H:i:s', strtotime('-1 hour')); $where = $where == '' ? " Where a.created_at>='" . $hourly . "'" : $where . " Where a.created_at>='" . $hourly . "'"; break; case 'daily': $daily = date('Y-m-d H:i:s', strtotime('-24 hour')); $where = $where == '' ? " Where a.created_at>='" . $daily . "'" : $where . " Where a.created_at>='" . $daily . "'"; break; case 'weekly': $thisweek = date('Y-m-d', strtotime('-7 day')); $where = $where == '' ? " Where a.created_at>='" . $thisweek . "'" : $where . " Where a.created_at>='" . $thisweek . "'"; break; case 'monthly': $thismonth = date('Y-m-1', strtotime('-1 month')); $where = $where == '' ? " Where a.created_at>='" . $thismonth . "'" : $where . " Where a.created_at>='" . $thismonth . "'"; break; } } $select .= " " . $where . " group by mk.wallet_from"; $coins_exchanged = DB::select($select); $data['coins_exchanged'] = $coins_exchanged; $select_maincoin .= " " . $where . " group by mk.wallet_to"; $maincoins_exchanged = DB::select($select_maincoin); $data['maincoins_exchanged'] = $maincoins_exchanged; // echo "<pre>"; print_r($fees); echo "</pre>"; $wallets_temp = Wallet::get(); $wallets = array(); foreach ($wallets_temp as $wallet) { $wallets[$wallet->id] = $wallet; } $data['wallets'] = $wallets; return View::make('admin.statistics.statistic_coin_exchanged', $data); break; case 'statistic-fees': $select = "SELECT mk.wallet_from, mk.wallet_to, sum(fee_sell) as fee_sell, sum(fee_buy) as fee_buy from trade_history a left join market mk on a.market_id=mk.id"; $where = ''; if (isset($_GET['filter_time']) && $_GET['filter_time'] != '') { switch ($_GET['filter_time']) { case 'hourly': $hourly = date('Y-m-d H:i:s', strtotime('-1 hour')); $where = $where == '' ? " Where a.created_at>='" . $hourly . "'" : $where . " Where a.created_at>='" . $hourly . "'"; break; case 'daily': $daily = date('Y-m-d H:i:s', strtotime('-24 hour')); $where = $where == '' ? " Where a.created_at>='" . $daily . "'" : $where . " Where a.created_at>='" . $daily . "'"; break; case 'weekly': $thisweek = date('Y-m-d', strtotime('-7 day')); $where = $where == '' ? " Where a.created_at>='" . $thisweek . "'" : $where . " Where a.created_at>='" . $thisweek . "'"; break; case 'monthly': $thismonth = date('Y-m-1', strtotime('-1 month')); $where = $where == '' ? " Where a.created_at>='" . $thismonth . "'" : $where . " Where a.created_at>='" . $thismonth . "'"; break; } } $select .= " " . $where . " group by a.market_id order by `created_at` desc"; $fees = DB::select($select); $data['fees'] = $fees; // echo "<pre>"; print_r($fees); echo "</pre>"; $wallets_temp = Wallet::get(); $wallets = array(); foreach ($wallets_temp as $wallet) { $wallets[$wallet->id] = $wallet; } $data['wallets'] = $wallets; return View::make('admin.statistics.statistic_fees', $data); break; case 'statistic-fee-withdraw': $select = "SELECT w.type, w.name, sum(fee_amount) as total_fee from withdraws a left join wallets w on a.wallet_id=w.id"; $where = ''; if (isset($_GET['filter_time']) && $_GET['filter_time'] != '') { switch ($_GET['filter_time']) { case 'hourly': $hourly = date('Y-m-d H:i:s', strtotime('-1 hour')); $where = $where == '' ? " Where a.created_at>='" . $hourly . "'" : $where . " Where a.created_at>='" . $hourly . "'"; break; case 'daily': $daily = date('Y-m-d H:i:s', strtotime('-24 hour')); $where = $where == '' ? " Where a.created_at>='" . $daily . "'" : $where . " Where a.created_at>='" . $daily . "'"; break; case 'weekly': $thisweek = date('Y-m-d', strtotime('-7 day')); $where = $where == '' ? " Where a.created_at>='" . $thisweek . "'" : $where . " Where a.created_at>='" . $thisweek . "'"; break; case 'monthly': $thismonth = date('Y-m-1', strtotime('-1 month')); $where = $where == '' ? " Where a.created_at>='" . $thismonth . "'" : $where . " Where a.created_at>='" . $thismonth . "'"; break; } } $select .= " " . $where . " group by a.wallet_id"; $withdraw_fees = DB::select($select); $data['withdraw_fees'] = $withdraw_fees; return View::make('admin.statistics.statistic_fee_withdraw', $data); break; case 'add-page': $data['type'] = 'page'; return View::make('admin.pages.add_post', $data); break; case 'add-news': $data['type'] = 'news'; return View::make('admin.pages.add_post', $data); break; case 'all-page': $data['type'] = 'page'; $record_per_page = 15; $total = Post::where('type', $data['type'])->count(); if ($pager_page == '') { $pager_page = 1; } $data['total_pages'] = ceil($total / $record_per_page); //15 user per page $data['cur_page'] = $pager_page; $offset_start = ($pager_page - 1) * $record_per_page; $posts = Post::where('type', $data['type'])->skip($offset_start)->take($record_per_page)->get(); $data['posts'] = $posts; return View::make('admin.pages.all_posts', $data); break; case 'all-news': $data['type'] = 'news'; $record_per_page = 15; $total = Post::where('type', $data['type'])->count(); if ($pager_page == '') { $pager_page = 1; } $data['total_pages'] = ceil($total / $record_per_page); //15 user per page $data['cur_page'] = $pager_page; $offset_start = ($pager_page - 1) * $record_per_page; $posts = Post::where('type', $data['type'])->skip($offset_start)->take($record_per_page)->get(); $data['posts'] = $posts; return View::make('admin.pages.all_posts', $data); break; case 'users': $record_per_page = 15; $total_users = User::count(); if ($pager_page == '') { $pager_page = 1; } $data['total_pages'] = ceil($total_users / $record_per_page); //15 user per page $data['cur_page'] = $pager_page; $offset_start = ($pager_page - 1) * $record_per_page; //$offset_end = ($pager_page*$record_per_page)-1; $users = User::skip($offset_start)->take($record_per_page)->get()->toArray(); foreach ($users as $key => $value) { $user = USer::find($value['id']); $users[$key]['roles'] = $user->roles->toArray(); //echo "<pre>roles:"; print_r($user->roles->toArray()); echo "</pre>"; } //echo "<pre>"; print_r($users); echo "</pre>"; $roles = Role::get(); $data['users'] = $users; $data['roles'] = $roles; return View::make('admin.user.manage_users', $data); break; case 'orders': $record_per_page = 15; if ($pager_page == '') { $pager_page = 1; } $data['cur_page'] = $pager_page; $offset_start = ($pager_page - 1) * $record_per_page; //$offset_end = ($pager_page*$record_per_page)-1; $select = "select a.*, b.wallet_from as `from`, b.wallet_to as `to`, c.username from orders a left join market b on a.market_id=b.id left join users c on a.user_id=c.id"; $select_count = "select count(*) as total from orders a"; $where = ''; if (isset($_GET['do_filter'])) { if ($where == '') { if (!empty($_GET['market'])) { $where = $where == '' ? " Where a.market_id='" . $_GET['market'] . "'" : $where . " AND a.market_id='" . $_GET['market'] . "'"; } } if ($_GET['status'] != '') { $where = $where == '' ? " Where a.status='" . $_GET['status'] . "'" : $where . " AND a.status='" . $_GET['status'] . "'"; } if ($_GET['type'] != '') { $where = $where == '' ? " Where a.type='" . $_GET['type'] . "'" : $where . " AND a.type='" . $_GET['type'] . "'"; } } $select_count = $select_count . " " . $where . " order by `created_at` desc"; $total_records = DB::select($select_count); //echo "<pre>total_records: "; print_r($total_records); echo "</pre>"; exit; $data['total_pages'] = ceil($total_records[0]->total / $record_per_page); $select .= " " . $where . " order by `created_at` desc limit " . $offset_start . "," . $record_per_page; $ordershistory = DB::select($select); $data['ordershistories'] = $ordershistory; return View::make('admin.orders', $data); break; case 'trade-histories': $record_per_page = 15; if ($pager_page == '') { $pager_page = 1; } $data['cur_page'] = $pager_page; $offset_start = ($pager_page - 1) * $record_per_page; $select = "select a.*, b.wallet_from as `from`, b.wallet_to as `to`,c.username as seller, d.username as buyer from trade_history a left join market b on a.market_id=b.id left join users c on a.seller_id=c.id left join users d on a.buyer_id=d.id"; $select_count = "select count(*) as total from trade_history a"; $where = ''; if (isset($_GET['do_filter'])) { if ($where == '') { if (!empty($_GET['market'])) { $where = $where == '' ? " Where a.market_id='" . $_GET['market'] . "'" : $where . " AND a.market_id='" . $_GET['market'] . "'"; } } if ($_GET['type'] != '') { $where = $where == '' ? " Where a.type='" . $_GET['type'] . "'" : $where . " AND a.type='" . $_GET['type'] . "'"; } if ($_GET['time'] != '') { switch ($_GET['time']) { case 'today': $where = $where == '' ? " Where a.created_at>='" . date("Y-m-d") . "'" : $where . " Where a.created_at>='" . date("Y-m-d") . "'"; break; case 'thisweek': $thisweek = date('Y-m-d', strtotime('this week')); $where = $where == '' ? " Where a.created_at>='" . $thisweek . "'" : $where . " Where a.created_at>='" . $thisweek . "'"; break; case 'thismonth': $thismonth = date('Y-m-1', strtotime('this month')); $where = $where == '' ? " Where a.created_at>='" . $thismonth . "'" : $where . " Where a.created_at>='" . $thismonth . "'"; break; } } } $select_count = $select_count . " " . $where . " order by `created_at` desc"; $total_records = DB::select($select_count); //echo "<pre>total_records: "; print_r($total_records); echo "</pre>"; exit; $data['total_pages'] = ceil($total_records[0]->total / $record_per_page); $select .= " " . $where . " order by `created_at` desc limit " . $offset_start . "," . $record_per_page; $trades = DB::select($select); $data['tradehistories'] = $trades; return View::make('admin.trade_histories', $data); break; case 'coins-voting': $coinvotes = DB::table('coin_votes')->get(); $wallet = Wallet::where('type', 'BTC')->first(); if (isset($wallet->id)) { try { $wallet->connectJsonRPCclient($wallet->wallet_username, $wallet->wallet_password, $wallet->wallet_ip, $wallet->port); foreach ($coinvotes as $key => $value) { $num_vote = Vote::where('coinvote_id', '=', $value->id)->count(); //echo "<pre>getreceivedbyaccount"; print_r($wallet->getReceivedByAddress($value->btc_address)); echo "</pre>";//$value->label_address $btc_payment = $wallet->getReceivedByAddress($value->btc_address); //'12X9jVe4S8pAqJ7EoKN7B4YwMQpzfgArtX' $num_payment = floor($btc_payment / 0.0001); //echo "btc_payment: ".$btc_payment; //echo "<br>num_payment: ".$num_payment; $coinvotes[$key]->balance = $num_payment; $coinvotes[$key]->num_vote = $num_vote + $num_payment; } } catch (Exception $e) { $data['error_message'] = "Not connect to this"; //'Caught exception: '.$e->getMessage()."\n"; // } //echo "<pre>coinvotes"; print_r($coinvotes); echo "</pre>"; $data['coinvotes'] = $coinvotes; } else { $data['not_wallet'] = "Please add BTC wallet before add the vote coin."; } return View::make('admin.coins_voting', $data); break; case 'funds': $wallets = Wallet::leftjoin('fee_withdraw', 'fee_withdraw.wallet_id', '=', 'wallets.id')->orderby('type')->get(); $balances = array(); $fee_withdraws = array(); foreach ($wallets as $wallet) { try { $wallet->connectJsonRPCclient($wallet->wallet_username, $wallet->wallet_password, $wallet->wallet_ip, $wallet->port); $balances[$wallet->id] = $wallet->getBalance(); $fee_withdraws[$wallet->id] = $wallet->getTxFee(); UserAddressDeposit::insert(array('user_id' => $user->id, 'wallet_id' => $wallet->id, 'addr_deposit' => $address)); } catch (Exception $e) { $data['error_message'] = 'Caught exception: ' . $e->getMessage() . "\n"; //"Not connect to this wallet";//'Caught exception: '.$e->getMessage()."\n"; } } $data['wallets'] = $wallets; $data['balances'] = $balances; $data['fee_withdraws'] = $fee_withdraws; //echo "<pre>fee_withdraws"; print_r($fee_withdraws); echo "</pre>"; return View::make('admin.funds', $data); break; case 'withdraws-queue': $record_per_page = 20; if ($pager_page == '') { $pager_page = 1; } $data['cur_page'] = $pager_page; $offset_start = ($pager_page - 1) * $record_per_page; if (isset($_GET['do_filter'])) { $withdraws = Withdraw::leftjoin('users', 'users.id', '=', 'withdraws.user_id'); if ($_GET['wallet_id'] != '') { $withdraws->where('wallet_id', $_GET['wallet_id']); } if ($_GET['status'] != '') { $withdraws->where('status', $_GET['status']); } if ($_GET['username'] != '') { $withdraws->where('users.username', $_GET['username']); } $withdraws->select('withdraws.*', 'users.username', 'users.id as user_id'); } else { $withdraws = Withdraw::leftjoin('users', 'users.id', '=', 'withdraws.user_id')->select('withdraws.*', 'users.username'); } $total_records = $withdraws->get(); //echo "<br>total_records: ".count($total_records); $data['total_pages'] = ceil(count($total_records) / $record_per_page); //echo "<br>total_records: ".$data['total_pages']; $withdraws = $withdraws->skip($offset_start)->take($record_per_page)->orderby("created_at", "desc")->get(); $wallets = Wallet::orderby('type')->get()->toArray(); $new_wallet = array(); foreach ($wallets as $key => $value) { $new_wallet[$value['id']] = $value; } $data['wallets'] = $new_wallet; $data['withdraws'] = $withdraws; $data['users'] = User::orderBy('username')->get(); return View::make('admin.withdraws_queue', $data); break; case 'deposits-queue': $record_per_page = 20; if ($pager_page == '') { $pager_page = 1; } $data['cur_page'] = $pager_page; $offset_start = ($pager_page - 1) * $record_per_page; if (isset($_GET['do_filter'])) { $deposits = Deposit::leftjoin('users', 'users.id', '=', 'deposits.user_id'); if ($_GET['wallet_id'] != '') { $deposits->where('wallet_id', $_GET['wallet_id']); } if ($_GET['status'] != '') { $deposits->where('paid', $_GET['status']); } if ($_GET['username'] != '') { $deposits->where('users.username', $_GET['username']); } $deposits->select('deposits.*', 'users.username', 'users.id as user_id'); } else { $deposits = Deposit::leftjoin('users', 'users.id', '=', 'deposits.user_id')->select('deposits.*', 'users.username'); } $total_records = $deposits->get(); //echo "<br>total_records: ".count($total_records); $data['total_pages'] = ceil(count($total_records) / $record_per_page); //echo "<br>total_records: ".$data['total_pages']; $deposits = $deposits->skip($offset_start)->take($record_per_page)->orderby("created_at", "desc")->get(); $wallets = Wallet::orderby('type')->get()->toArray(); $new_wallet = array(); foreach ($wallets as $key => $value) { $new_wallet[$value['id']] = $value; } $data['wallets'] = $new_wallet; $data['deposits'] = $deposits; $data['users'] = User::orderBy('username')->get(); return View::make('admin.deposits_queue', $data); break; case 'wallets': $record_per_page = 15; $total_users = Wallet::count(); if ($pager_page == '') { $pager_page = 1; } $data['total_pages'] = ceil($total_users / $record_per_page); //15 user per page $data['cur_page'] = $pager_page; $offset_start = ($pager_page - 1) * $record_per_page; $wallets = Wallet::skip($offset_start)->take($record_per_page)->orderby('name')->get(); $data['wallets'] = $wallets; return View::make('admin.wallet.manage_wallets', $data); break; case 'markets': $record_per_page = 15; $total_users = Market::count(); if ($pager_page == '') { $pager_page = 1; } $data['total_pages'] = ceil($total_users / $record_per_page); //15 user per page $data['cur_page'] = $pager_page; $offset_start = ($pager_page - 1) * $record_per_page; $markets = Market::skip($offset_start)->take($record_per_page)->get(); $data['markets'] = $markets; $wallets_temp = Wallet::orderby('type')->get(); $wallets = array(); foreach ($wallets_temp as $wallet) { $wallets[$wallet->id] = $wallet; } $data['wallets'] = $wallets; return View::make('admin.manage_markets', $data); break; case 'balance-wallets': $record_per_page = 15; $total_users = Wallet::count(); if ($pager_page == '') { $pager_page = 1; } $data['total_pages'] = ceil($total_users / $record_per_page); //15 user per page $data['cur_page'] = $pager_page; $offset_start = ($pager_page - 1) * $record_per_page; $wallets = Wallet::skip($offset_start)->take($record_per_page)->orderby('name')->get(); $amount_transaction = array(); $balances = array(); foreach ($wallets as $wallet) { //get total deposit $total_deposit = Deposit::where('wallet_id', $wallet->id)->where('paid', 1)->sum('amount'); $total_withdraw = Withdraw::where('wallet_id', $wallet->id)->where('status', 1)->sum('receive_amount'); $amount_transaction[$wallet->id] = array('total_amount_deposit' => $total_deposit, 'total_amount_withdraw' => $total_withdraw); try { $wallet->connectJsonRPCclient($wallet->wallet_username, $wallet->wallet_password, $wallet->wallet_ip, $wallet->port); $balances[$wallet->id] = $wallet->getBalance(); } catch (Exception $e) { $balances[$wallet->id] = Lang::get('messages.cannot_connect'); } } $data['wallets'] = $wallets; $data['amount_transaction'] = $amount_transaction; $data['balances'] = $balances; return View::make('admin.wallet.manage_wallets_balance', $data); break; case "login-histories": $record_per_page = 15; if ($pager_page == '') { $pager_page = 1; } $data['cur_page'] = $pager_page; $offset_start = ($pager_page - 1) * $record_per_page; //$offset_end = ($pager_page*$record_per_page)-1; $select = "select a.*, b.username from login_history a left join users b on a.user_id=b.id"; $select_count = "select count(*) as total from login_history as a"; $where = ''; if (isset($_GET['do_filter'])) { if ($where == '') { if (!empty($_GET['user'])) { $where = $where == '' ? " Where a.user_id='" . $_GET['user'] . "'" : $where . " AND a.user='******'user'] . "'"; } } } $select_count = $select_count . " " . $where; $total_records = DB::select($select_count); //echo "<pre>total_records: "; print_r($total_records); echo "</pre>"; exit; $data['total_pages'] = ceil($total_records[0]->total / $record_per_page); $select .= " " . $where . " order by `date` desc limit " . $offset_start . "," . $record_per_page; $login_histories = DB::select($select); $data['login_histories'] = $login_histories; $users = User::orderby('username')->get(); $data['users'] = $users; return View::make('admin.user.login_histories', $data); break; case 'method-deposit': $record_per_page = 15; $total_users = MethodDepositCurrency::count(); if ($pager_page == '') { $pager_page = 1; } $data['total_pages'] = ceil($total_users / $record_per_page); //15 user per page $data['cur_page'] = $pager_page; $offset_start = ($pager_page - 1) * $record_per_page; $MethodDepositCurrency = MethodDepositCurrency::skip($offset_start)->take($record_per_page)->get(); $data['MethodDepositCurrency'] = $MethodDepositCurrency; return View::make('admin.method-deposit-currency.manage_method_deposit', $data); break; case 'method-withdraw': $record_per_page = 15; $total_users = MethodWithdrawCurrency::count(); if ($pager_page == '') { $pager_page = 1; } $data['total_pages'] = ceil($total_users / $record_per_page); //15 user per page $data['cur_page'] = $pager_page; $offset_start = ($pager_page - 1) * $record_per_page; $MethodWithdrawCurrency = MethodWithdrawCurrency::skip($offset_start)->take($record_per_page)->get(); $data['MethodWithdrawCurrency'] = $MethodWithdrawCurrency; return View::make('admin.method-withdraw-currency.manage_method_withdraw', $data); break; default: $setting = new Setting(); //$data['bg_color']=$setting->getSetting('bg_color',''); $data['site_mode'] = $setting->getSetting('site_mode', 0); //$data['bg_file']=$setting->getSetting('bg_file',''); $data['disable_withdraw'] = $setting->getSetting('disable_withdraw', 0); $data['recaptcha_publickey'] = $setting->getSetting('recaptcha_publickey', ''); $data['recaptcha_privatekey'] = $setting->getSetting('recaptcha_privatekey', ''); $data['amount_btc_per_vote'] = $setting->getSetting('amount_btc_per_vote', 0.0001); //pusher app $data['pusher_app_id'] = $setting->getSetting('pusher_app_id', ''); $data['pusher_app_key'] = $setting->getSetting('pusher_app_key', ''); $data['pusher_app_secret'] = $setting->getSetting('pusher_app_secret', ''); //default_market $m_default = Market::where('active', 1)->orderBy('id')->first(); $market_default_id = isset($m_default->id) ? $m_default->id : 0; $data['default_market'] = $setting->getSetting('default_market', $market_default_id); //setting points $data['disable_points'] = $setting->getSetting('disable_points', 0); $data['point_per_btc'] = $setting->getSetting('point_per_btc', 1); $data['percent_point_reward_trade'] = $setting->getSetting('percent_point_reward_trade', 0); $data['percent_point_reward_referred_trade'] = $setting->getSetting('percent_point_reward_referred_trade', 0); $data['max_amount_funds'] = $setting->getSetting('max_amount_funds', 1000); //echo "<pre>data: "; print_r($data); echo "</pre>"; exit; return View::make('admin.setting', $data); break; } }