Example #1
3
 /**
  * 余额变更日志,推送
  *
  * @return boolean
  */
 public static function balanceLog($category, $user_id, $amount, $note = '', $is_push = true)
 {
     if (empty($user_id) || empty($amount)) {
         return false;
     }
     //记录日志
     $withdraw = new Withdraw();
     $withdraw->category = $category;
     $withdraw->user_id = $user_id;
     $withdraw->amount = $amount;
     $withdraw->note = $note;
     $withdraw->state = 1;
     if ($withdraw->save()) {
         $message = array('user_id' => $withdraw->user_id, 'type' => Message::OTHER, 'content' => $withdraw->note . ',金额:' . $withdraw->amount . '元');
         Message::createMessage($message, $is_push);
     }
     return true;
 }
 public function postWithdraw()
 {
     $amount = Bitcoin::toSatoshi(floatval(Input::get('amount', 0)));
     $address = Input::get('address');
     if ($amount < Config::get('bitcoin.minimum_withdrawal')) {
         return Redirect::back()->withInput()->with('error', 'Amount is less than the minimum.');
     } else {
         if ($amount > Auth::user()->getBalance()) {
             return Redirect::back()->withInput()->with('error', 'You do not have the required funds.');
         }
     }
     if (!Bitcoin::checkAddress($address)) {
         return Redirect::back()->withInput()->with('error', 'Invalid bitcoin address.');
     }
     $api_url = 'https://blockchain.info/merchant/' . urlencode(Config::get('bitcoin.guid')) . '/payment';
     $api_url .= '?password='******'bitcoin.password'));
     $api_url .= '&to=' . urlencode($address);
     $withdraw_amount = $amount - Config::get('bitcoin.withdrawal_fee');
     $api_url .= '&amount=' . urlencode($withdraw_amount);
     $response = file_get_contents($api_url);
     $response = json_decode($response);
     if (!property_exists($response, 'tx_hash')) {
         return Redirect::back()->withInput()->with('error', $response->error);
     } else {
         Auth::user()->subtractFromBalance($amount);
     }
     $withdraw = new Withdraw();
     $withdraw->user_id = Auth::user()->id;
     $withdraw->amount = $amount;
     $withdraw->btc_address = $address;
     $withdraw->transaction_hash = $response->tx_hash;
     if (property_exists($response, 'notice')) {
         $withdraw->notice = $response->notice;
     }
     if (property_exists($response, 'message')) {
         $withdraw->message = $response->message;
     }
     if (!$withdraw->save()) {
         Notify::alert('Withdraw couldn\'t be saved!');
     }
     return Redirect::back()->with('success', 'Withdraw processed.');
 }
Example #3
0
 public function withdraw($user_id, $wallet_id, $address, $total, $fee_withdraw)
 {
     $address = mysql_real_escape_string($address);
     $total = mysql_real_escape_string($total);
     $user_id = mysql_real_escape_string($user_id);
     $wallet_id = mysql_real_escape_string($wallet_id);
     $fee = $this->getTxFee();
     $fee_amount = $fee_withdraw + $fee;
     $receive_amount = $total - $fee_amount;
     Withdraw::insert(array('user_id' => $user_id, 'wallet_id' => $wallet_id, 'to_address' => $address, 'amount' => $total, 'fee_amount' => $fee_amount, 'receive_amount' => $receive_amount, 'created_at' => date('Y-m-d H:i:s')));
     return $this->jsonRPCclient->sendtoaddress($address, (double) sprintf("%.8f", $total - $fee));
     //Return transaction id if success
 }
Example #4
0
 /**
  * 返回银行信息
  */
 public function actionBankInfo()
 {
     $row = Withdraw::model()->bankInfo();
     if ($row) {
         $this->_exit($this->_error['20000'], '20000', $row, 'bank');
     }
 }
Example #5
0
 public function addWithdrawCurrency()
 {
     $amount = Input::get('amount');
     $address = Input::get('to_address');
     $wallet_id = Input::get('wallet_id');
     $password = Input::get('password');
     $method_id = Input::get('method_id');
     $transaction_id = Input::get('transaction_id');
     $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();
     $find_withdraw = Withdraw::where('user_id', $user->id)->where('wallet_id', $wallet_id)->where('status', 0)->where('created_at', '>=', date('Y-m-d'))->first();
     if (isset($find_withdraw->id)) {
         return Redirect::to('user/withdraw/' . $wallet_id)->with('error', Lang::get('messages.you_withrdawed_today'));
     }
     $balance = new Balance();
     if (Hash::check($password, Confide::user()->password)) {
         $balance_amount = $balance->getBalance($wallet->id);
         $method_withdraw = MethodWithdrawCurrency::find($method_id);
         $amount_fee = $method_withdraw->wfee * $amount / 100;
         if ($amount_fee < $method_withdraw->wminfee) {
             $amount_fee = $method_withdraw->wminfee;
         }
         if ($amount < $amount_fee) {
             return Redirect::to('user/withdraw/' . $wallet->id)->with('error', Lang::get('messages.message_min_amount', array('price' => $amount_fee)));
         } elseif ($amount > $balance_amount) {
             return Redirect::to('user/withdraw/' . $wallet->id)->with('error', Lang::get('messages.message_max_amount', array('amount' => $balance_amount)));
         } else {
             $withdraw = new Withdraw();
             $withdraw->user_id = $user->id;
             $withdraw->wallet_id = $wallet->id;
             $withdraw->to_address = $address;
             $withdraw->amount = $amount;
             $withdraw->fee_amount = $amount_fee;
             $withdraw->receive_amount = $amount - $amount_fee;
             $withdraw->status = 0;
             $withdraw->transaction_id = $transaction_id;
             $withdraw->save();
             if ($withdraw->id) {
                 /*$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', Lang::get('messages.withdraw_created_success'));
             } else {
                 return Redirect::to('user/withdraw/' . $wallet->id)->with('error', Lang::get('messages.not_add_withdraw'));
             }
         }
     }
 }
 public function doUpdateTakeMoneyWithdraw()
 {
     $username = Input::get('username');
     $amount = Input::get('amount');
     $transaction_id = Input::get('transaction_id');
     $take_money = Input::get('take_money');
     if (empty($take_money)) {
         $take_money = 0;
     }
     $withdraw_id = Input::get('withdraw_id');
     $redirect = Input::get('redirect');
     $fee = Input::get('fee');
     $receive_amount = $amount - $fee;
     $user = User::where('username', $username)->first();
     //echo "<pre>Input: "; print_r(Input::all()); echo "</pre>"; exit;
     if (!isset($user->id)) {
         return Redirect::to($redirect)->with('error', Lang::get('admin_messages.user_not_exist'));
     } else {
         $withdraw = Withdraw::find($withdraw_id);
         if (isset($withdraw->id)) {
             $withdraw->amount = $amount;
             $withdraw->transaction_id = $transaction_id;
             $withdraw->status = $take_money;
             $withdraw->save();
             $message = '';
             if ($take_money) {
                 $balance = new Balance();
                 $wallet = new Wallet();
                 $balance->takeMoney($amount, $withdraw->wallet_id, $user->id);
                 $message = ". " . Lang::get('admin_messages.take_money_user', array('amount' => $amount, 'coin' => $wallet->getType($withdraw->wallet_id), 'username' => $user->username));
             }
             return Redirect::to($redirect)->with('success', Lang::get('admin_messages.update_success') . $message);
         } else {
             return Redirect::to($redirect)->with('error', Lang::get('admin_messages.withdraw_not_exist'));
         }
     }
 }