Esempio n. 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;
 }
Esempio n. 2
1
 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.');
 }
Esempio n. 3
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'));
             }
         }
     }
 }