public function getFeeWithdraw($wallet_id) { $fee_withdraw = FeeWithdraw::where('wallet_id', '=', $wallet_id)->first(); if (isset($fee_withdraw->percent_fee)) { return $fee_withdraw->percent_fee; } else { return 0; } }
public function routePage($page = '') { //echo "<pre>user: "******"</pre>"; switch ($page) { case "fees": $market = new Market(); $wallet = new Wallet(); $fees_trade = FeeTrade::get()->toArray(); //echo "<pre>list_buy_orders: "; print_r($list_buy_orders); echo "</pre>"; $fees_withdraw = FeeWithdraw::leftJoin('wallets', 'fee_withdraw.wallet_id', '=', 'wallets.id')->select('fee_withdraw.*', 'wallets.type', 'wallets.name')->get(); foreach ($fees_trade as $key => $value) { $wallet_type = $market->getWalletType($value['market_id']); if (!empty($wallet_type)) { $fees_trade[$key]['wallet_from'] = $wallet_type['wallet_from']; $fees_trade[$key]['wallet_to'] = $wallet_type['wallet_to']; } } $fee['fees_trade'] = $fees_trade; $fee['fees_withdraw'] = $fees_withdraw; return View::make('fees', $fee); break; case "voting": $setting = new Setting(); $coinvotes = DB::table('coin_votes')->get(); try { $wallet = Wallet::where('type', 'BTC')->first(); $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' $amount_btc_per_vote = $setting->getSetting('amount_btc_per_vote', 0.0001); $num_payment = floor($btc_payment / $amount_btc_per_vote); //echo "btc_payment: ".$btc_payment; //echo "<br>num_payment: ".$num_payment; $coinvotes[$key]->num_vote = $num_vote + $num_payment; } } catch (Exception $e) { $data['error_message'] = Lang::get('texts.not_connect_wallet'); //'Caught exception: '.$e->getMessage()."\n"; //"Not connect to this } //echo "<pre>coinvotes"; print_r($coinvotes); echo "</pre>"; $data['coinvotes'] = $coinvotes; return View::make('voting', $data); break; case "security": return View::make('security'); break; case "api": if (isset($_REQUEST['method'])) { $method = $_REQUEST['method']; $value = $this->api($method); } else { $setting = new Setting(); $data['pusher_app_key'] = $setting->getSetting('pusher_app_key', ''); return View::make('api', $data); } print_r($value); break; case "apiprivate": $value = $this->apiprivate(); break; case "all-trades": if (Auth::guest()) { return Redirect::to('/login'); } $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; $trade_history = Trade::leftjoin('market', 'market.id', '=', 'trade_history.market_id')->select('trade_history.*', 'market.wallet_from as from', 'market.wallet_to as to'); $where = ''; if (Input::has('market')) { $fil_market = Input::get('market'); $trade_history->where("trade_history.market_id", "=", $fil_market); } if (Input::has('type')) { $fil_type = Input::get('type'); $trade_history->where("trade_history.type", "=", $fil_type); } $total_records = $trade_history->get(); $data['total_pages'] = ceil(count($total_records) / $record_per_page); $trades = $trade_history->skip($offset_start)->take($record_per_page)->orderby("created_at", "desc")->get(); #echo "<pre>trade_history"; print_r($trades->toArray()); echo "</pre>"; //echo "<pre>getQueryLog: ".dd(DB::getQueryLog())."</pre>"; $data['tradehistories'] = $trades; $market = new Market(); $markets = Market::get(); $market_wallet = array(); foreach ($markets as $value) { $market_wallet[$value->id] = $market->getWalletType($value->id); } $data['markets'] = $market_wallet; return View::make('alltrades', $data); break; case "all-news": $news = Post::where('type', 'news')->orderby('created_at', 'desc')->get(); $data['news'] = $news; return View::make('allnews', $data); break; default: return View::make('index'); break; } }
public function doWithdraw() { $amount = Input::get('amount'); $address = Input::get('address'); $wallet_id = Input::get('wallet_id'); $password = Input::get('password'); $wallet = Wallet::find($wallet_id); $setting = new Setting(); if ($setting->getSetting('disable_withdraw', 0)) { return Redirect::to('user/withdraw/' . $wallet->id)->with('notice', 'Sorry. we pause function withdrawals'); //"Not connect to this wallet." } $user = Confide::user(); $balance = new Balance(); if (Hash::check($password, Confide::user()->password)) { $balance_amount = $balance->getBalance($wallet->id); $fee_withdraw = new FeeWithdraw(); $fee = $fee_withdraw->getFeeWithdraw($wallet->id); $net_total = $amount - $fee; try { $wallet->connectJsonRPCclient($wallet->wallet_username, $wallet->wallet_password, $wallet->wallet_ip, $wallet->port); $min_amount = $wallet->getTxFee() + $fee; //$wallet->getTxFee(); if ($amount < $min_amount) { return Redirect::to('user/withdraw/' . $wallet->id)->with('error', Lang::get('messages.message_min_equal_amount', array('price' => $min_amount))); } elseif (!$wallet->enable_withdraw) { return Redirect::to('user/withdraw/' . $wallet->id)->with('error', Lang::get('user_texts.notify_withdraw_disable', array('coin' => $wallet->name))); } elseif ($balance_amount >= $net_total) { $confirmation_code = md5(uniqid(mt_rand(), true)); $withdraw = new Withdraw(); $withdraw->user_id = $user->id; $withdraw->wallet_id = $wallet->id; $withdraw->to_address = $address; $withdraw->amount = $amount; $withdraw->fee_amount = $fee; $withdraw->receive_amount = $net_total; $withdraw->status = 0; $withdraw->transaction_id = ''; $withdraw->confirmation_code = $confirmation_code; $withdraw->save(); Log::info("\n" . "Add Withdraw transaction. Send mail confirm: ", array('user_id' => $user->id, 'wallet_id' => $wallet->id, 'to_address' => $address, 'amount' => $amount, 'fee_amount' => $fee, 'receive_amount' => $net_total, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), 'status' => 0, 'transaction_id' => '', 'confirmation_code' => $confirmation_code)); if ($withdraw->id) { //send mail confirm $data_send = array('user' => $user, 'withdraw_id' => $withdraw->id, 'confirmation_code' => $confirmation_code); Mail::send('emails.confirmwithdraw', $data_send, function ($message) use($user) { $message->to($user->email)->subject('Confirmation Withdrawal'); }); return Redirect::to('user/withdraw/' . $wallet->id)->with('success', "A confirmation e-mail was sent to your e-mail. Please checking e-mail to confirm withdrawal."); } else { return Redirect::to('user/withdraw/' . $wallet->id)->with('error', "Can not insert withdraw to database."); } } else { return Redirect::to('user/withdraw/' . $wallet->id)->with('error', "Your balance are not enough."); } } catch (Exception $e) { return Redirect::to('user/withdraw/' . $wallet->id)->with('error', Lang::get('texts.not_connect_wallet')); //'Caught exception: '.$e->getMessage() } } else { return Redirect::to('user/withdraw/' . $wallet->id)->with('error', "Password invalid."); } }
public function deleteWallet() { $wallet_id = Input::get('wallet_id'); $wallet = Wallet::find($wallet_id); if (isset($wallet->id)) { $markets = Market::where("wallet_from", $wallet_id)->orwhere("wallet_to", $wallet_id)->get(); $arr_markets = array(0); foreach ($markets as $market) { $arr_markets[] = $market->id; } FeeWithdraw::where("wallet_id", $wallet_id)->delete(); WalletLimitTrade::where("wallet_id", $wallet_id)->delete(); UserAddressDeposit::where("wallet_id", $wallet_id)->delete(); Balance::where("wallet_id", $wallet_id)->delete(); Transfer::where("wallet_id", $wallet_id)->delete(); Deposit::where("wallet_id", $wallet_id)->delete(); Withdraw::where("wallet_id", $wallet_id)->delete(); Order::whereIn('market_id', $arr_markets)->delete(); Trade::whereIn('market_id', $arr_markets)->delete(); FeeTrade::whereIn('market_id', $arr_markets)->delete(); Market::where("wallet_from", $wallet_id)->orwhere("wallet_to", $wallet_id)->delete(); Wallet::where('id', $wallet_id)->delete(); $message = $wallet->type . " " . Lang::get('admin_messages.delete_success'); if (Input::get('isAjax')) { echo json_encode(array('status' => 'success', 'message' => $message)); exit; } else { return Redirect::to('admin/manage/wallets')->with('success', $message); } } else { $message = Lang::get('admin_messages.wallet_not_exist'); if (Input::get('isAjax')) { echo json_encode(array('status' => 'error', 'message' => $message)); exit; } else { return Redirect::to('admin/manage/wallets')->with('error', $message); } } }