Ejemplo n.º 1
0
 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);
 }