Exemplo n.º 1
0
 public function createAccount()
 {
     $validator = Validator::make($data = Input::all(), User::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $data['role'] = Input::get('user_role');
     $data['country_id'] = Input::get('country');
     $data['password'] = Hash::make($data['password']);
     $data['code'] = str_random(60);
     //Activation code
     $user = User::create($data);
     if ($user) {
         $data['user_id'] = $user->id;
         if ($data['role'] == 'Agent') {
             $data['market_id'] = Market::where('market', 'All Market')->first()->id;
             $role = Role::where('name', $data['role'])->first();
             $user->attachRole($role);
             Agent::create($data);
             Mail::send('emails.auth.signup', array('first_name' => $data['first_name'], 'role' => $data['role']), function ($massage) use($user) {
                 $massage->to($user->email, $user->first_name)->subject('Thank You for Signing Up');
             });
             Mail::send('emails.auth.signup', array('first_name' => $data['first_name'], 'role' => $data['role']), function ($massage) use($user) {
                 $massage->to('*****@*****.**', 'Tharinda')->subject('Thank You for Signing Up');
             });
             Session::flash('global', 'Thank you for signing up with us as an ' . $data['role'] . '. We will contact you within 24 hours');
             return View::make('pages.message');
         }
         if ($data['role'] == 'Hotelier') {
             Mail::send('emails.auth.signup', array('first_name' => $data['first_name'], 'role' => $data['role']), function ($massage) use($user) {
                 $massage->to($user->email, $user->first_name)->subject('Thank You for Signing Up');
             });
             Session::flash('global', 'Thank you for signing up with us as an ' . $data['role'] . '. We will contact you within 24 hours');
             return View::make('pages.message');
         }
         // send email
         Mail::send('emails.auth.activate', array('link' => URL::to('account/activate', $data['code']), 'first_name' => $data['first_name']), function ($massage) use($user) {
             $massage->to($user->email, $user->first_name)->subject('Activate your account');
         });
         Session::flash('global', 'Your account has been created! We have sent you an email to activate your account');
         return View::make('pages.message');
     }
     return 'There was an error';
 }
Exemplo n.º 2
0
 public function addTradeHistory($trade_history)
 {
     $this->seller_id = $trade_history['seller_id'];
     $this->buyer_id = $trade_history['buyer_id'];
     $this->amount = $trade_history['amount'];
     $this->price = $trade_history['price'];
     $this->market_id = $trade_history['market_id'];
     $this->type = $trade_history['type'];
     $this->fee_buy = $trade_history['fee_buy'];
     $this->fee_sell = $trade_history['fee_sell'];
     $this->save();
     if ($this->id) {
         require_once app_path() . '/libraries/Pusher.php';
         $setting = new Setting();
         $pusher_app_id = $setting->getSetting('pusher_app_id', '');
         $pusher_app_key = $setting->getSetting('pusher_app_key', '');
         $pusher_app_secret = $setting->getSetting('pusher_app_secret', '');
         if ($pusher_app_id != '' && $pusher_app_key != '' && $pusher_app_secret != '') {
             $pusher = new Pusher($pusher_app_key, $pusher_app_secret, $pusher_app_id);
             $wallet = new Wallet();
             $market = Market::where('id', $this->market_id)->first();
             $from = strtoupper($wallet->getType($market->wallet_from));
             $to = strtoupper($wallet->getType($market->wallet_to));
             $message = array('channel' => 'trade.' . $this->market_id, 'trade' => array('timestamp' => strtotime($this->created_at), 'datetime' => date("Y-m-d H:i:s T", strtotime($this->created_at)), 'marketid' => $this->market_id, 'marketname' => $from . '/' . $to, 'amount' => sprintf("%.8f", $this->amount), 'price' => sprintf("%.8f", $this->price), 'total' => sprintf("%.8f", $this->amount * $this->price), 'type' => $this->type));
             $pusher->trigger('trade.' . $this->market_id, 'message', $message);
         }
         if (!$setting->getSetting('disable_points', 0)) {
             //Cong point cho nguoi mua va nguoi da gioi thieu ho
             $points = new PointsController();
             if ($this->fee_buy > 0) {
                 $points->addPointsTrade($this->buyer_id, $this->fee_buy, $this->id, $market->wallet_to);
             }
             //Cong point cho nguoi ban va nguoi da gioi thieu ho
             if ($this->fee_sell > 0) {
                 $points->addPointsTrade($this->seller_id, $this->fee_sell, $this->id, $market->wallet_to);
             }
         }
     }
     return $this->id;
 }
Exemplo n.º 3
0
 public static function supplementRate($hotel_id, $room_type_id, $specification_id, $meal_basis_id, $st_date, $ed_date)
 {
     $x = 0;
     $y = 0;
     $supplement_rates = 0;
     if (Session::has('market')) {
         $market = Session::get('market');
     } else {
         $market = 1;
     }
     $get_market_details = Market::where('id', $market)->first();
     $from_date = date('Y-m-d', strtotime(str_replace('-', '/', $st_date)));
     $to_date = date('Y-m-d', strtotime(str_replace('-', '/', $ed_date)));
     $dates = (strtotime($ed_date) - strtotime($st_date)) / 86400;
     //      dd($market.'/'.$hotel_id.'/'.$room_type_id.'/'.$specification_id.'/'.$meal_basis_id.'/'.$st_date.'/'.$ed_date);
     for ($x = 1; $x <= $dates; $x++) {
         $supplement_rate = 0;
         $get_supplement_rates = SupplementRate::where('hotel_id', $hotel_id)->where('room_type_id', $room_type_id)->where('room_specification_id', $specification_id)->where('meal_basis_id', $meal_basis_id)->where('from', '<=', $from_date)->where('to', '>', $from_date)->where('market_id', $market)->get();
         foreach ($get_supplement_rates as $get_supplement_rate) {
             $supplement_rate = $get_supplement_rate->rate;
             if ($supplement_rate > 0) {
                 $y = $y + 1;
             }
         }
         $from_date = date('Y-m-d', strtotime($from_date . ' + 1 days'));
         if ($supplement_rate > 0) {
             $supplement_rates = $supplement_rates + $supplement_rate;
         }
     }
     $room_supplement_rate = number_format($supplement_rates, 2);
     return $room_supplement_rate;
 }
Exemplo n.º 4
0
 public function triggerPusherTicket($market_id)
 {
     require_once app_path() . '/libraries/Pusher.php';
     $setting = new Setting();
     $pusher_app_id = $setting->getSetting('pusher_app_id', '');
     $pusher_app_key = $setting->getSetting('pusher_app_key', '');
     $pusher_app_secret = $setting->getSetting('pusher_app_secret', '');
     if ($pusher_app_id != '' && $pusher_app_key != '' && $pusher_app_secret != '') {
         $pusher = new Pusher($pusher_app_key, $pusher_app_secret, $pusher_app_id);
         $wallet = new Wallet();
         $market = Market::where('id', $market_id)->first();
         $from = strtoupper($wallet->getType($market->wallet_from));
         $to = strtoupper($wallet->getType($market->wallet_to));
         $order = new Order();
         $buyHighest = $order->getBuyHighest($market_id);
         $sellLowest = $order->getSellLowest($market_id);
         $topsell = array('price' => 0, 'amount' => 0);
         $topbuy = array('price' => 0, 'amount' => 0);
         if (count($sellLowest) > 0) {
             $topsell = array('amount' => sprintf("%.8f", $sellLowest->from_value), 'price' => sprintf("%.8f", $sellLowest->price));
         }
         if (count($buyHighest) > 0) {
             $topbuy = array('amount' => sprintf("%.8f", $buyHighest->from_value), 'price' => sprintf("%.8f", $buyHighest->price));
         }
         $message = array('channel' => 'ticker.' . $market_id, 'trade' => array('timestamp' => time(), 'datetime' => date("Y-m-d H:i:s T", time()), 'marketid' => $market_id, 'marketname' => $from . '/' . $to, 'topsell' => $topsell, 'topbuy' => $topbuy));
         $pusher->trigger('ticker.' . $market_id, 'message', $message);
     }
 }
Exemplo n.º 5
0
 public function index($market_id = '')
 {
     $setting = new Setting();
     $wallet = new Wallet();
     $m = Market::where('active', 1)->orderBy('id')->first();
     if ($market_id == '') {
         $market_id = $setting->getSetting('default_market', $m->id);
     }
     Session::put('market_id', $market_id);
     $market_default = Market::find($market_id);
     if (!isset($market_default->active) || $market_default->active == 0) {
         //$setting->setSetting('default_market',$m->id);
         return Redirect::to('market/' . $m->id);
     }
     $wallet_from = $market_default->wallet_from;
     $wallet_to = $market_default->wallet_to;
     $from = strtoupper($wallet->getType($wallet_from));
     $to = strtoupper($wallet->getType($wallet_to));
     //get limit amount
     $limit_day = WalletTimeLimitTrade::select('limit_amount')->where('wallet_id', $wallet_to)->where('time_limit', 'per day')->first();
     if (isset($limit_day)) {
         $data['limit_day'] = $limit_day->limit_amount;
     } else {
         $data['limit_day'] = 1000;
     }
     $limit_week = WalletTimeLimitTrade::select('limit_amount')->where('wallet_id', $wallet_to)->where('time_limit', 'per week')->first();
     if (isset($limit_week)) {
         $data['limit_week'] = $limit_week->limit_amount;
     } else {
         $data['limit_week'] = 1000;
     }
     //get amount : day
     $user = Confide::user();
     if (isset($user)) {
         $uid = $user->id;
         $select = "SELECT sum(t.to_value) as sumamount from orders t, market m where m.id=t.market_id and m.wallet_to=" . $wallet_to . " and t.user_id=" . $uid . " and t.created_at='" . date("Y-m-d") . "'";
         $selectsum = DB::select($select);
         $sumamount = $selectsum[0]->sumamount;
         $data['amount_sum_day'] = $sumamount;
     }
     if (!isset($data['amount_sum_day'])) {
         $data['amount_sum_day'] = 0;
     }
     //echo 'aaaaaaaaaaa:'; print_r($data['amount_sum_day']);
     //get name of wallet
     $wallet1 = Wallet::where('id', $wallet_from)->first();
     $wallet2 = Wallet::where('id', $wallet_to)->first();
     $data['market_from'] = $wallet1->name;
     $data['market_to'] = $wallet2->name;
     $data['coinmain'] = $from;
     $data['coinsecond'] = $to;
     //get balance
     $balance = new Balance();
     $data['balance_coinmain'] = sprintf('%.8f', $balance->getBalance($wallet_from, 0));
     $data['balance_coinsecond'] = sprintf('%.8f', $balance->getBalance($wallet_to, 0));
     //get Sell Lowest
     $data['sell_lowest'] = sprintf('%.8f', 0);
     $data['buy_highest'] = sprintf('%.8f', 0);
     $order = new Order();
     $sell_lowest = $order->getSellLowest($market_id);
     $buy_highest = $order->getBuyHighest($market_id);
     if (isset($sell_lowest->price)) {
         $data['sell_lowest'] = sprintf('%.8f', $sell_lowest->price);
     }
     if (isset($buy_highest->price)) {
         $data['buy_highest'] = sprintf('%.8f', $buy_highest->price);
     }
     //fee_buy, fee_sell
     $fee_trade = new FeeTrade();
     $fee = $fee_trade->getFeeTrade($market_id);
     $data['fee_buy'] = $fee['fee_buy'];
     $data['fee_sell'] = $fee['fee_sell'];
     //get list orders
     $num_transaction_display = $setting->getSetting('num_transaction_display', 0);
     $list_sell_orders = $order->getOrders($market_id, 'sell', $num_transaction_display);
     $list_buy_orders = $order->getOrders($market_id, 'buy', $num_transaction_display);
     $data['sell_orders'] = $list_sell_orders;
     $data['buy_orders'] = $list_buy_orders;
     //get all history
     $trade_history = Trade::where('market_id', '=', $market_id)->orderBy('created_at', 'desc')->take($num_transaction_display)->get();
     $data['trade_history'] = $trade_history;
     $data['market_id'] = $market_id;
     $current_orders_user = $order->getCurrentOrdersUser($market_id);
     if ($current_orders_user) {
         $data['current_orders_user'] = $current_orders_user;
     }
     $trade = new Trade();
     $datachart = $trade->getDatasChart($market_id, '6 hour');
     $news = Post::where('type', 'news')->take(5)->orderby('created_at', 'desc')->get();
     $data['news'] = $news;
     //price
     $data_price = $trade->getBlockPrice($market_id);
     $data["get_prices"] = $data_price['get_prices'];
     $data['lastest_price'] = $data_price['lastest_price'];
     //limit trade amount
     $limit_trade = WalletLimitTrade::where('wallet_id', $wallet_from)->first();
     if ($limit_trade) {
         $data['limit_trade'] = $limit_trade->toArray();
     } else {
         $data['limit_trade'] = array('min_amount' => 0.0001, 'max_amount' => 1000);
     }
     //get data for block statistic
     $btc_wallet = Wallet::where('type', 'BTC')->first();
     $ltc_wallet = Wallet::where('type', 'LTC')->first();
     $btc_markets = array();
     $ltc_markets = array();
     //btc market on sidebar left
     $all_market_btc = array();
     if (isset($btc_wallet->id)) {
         $btc_markets = Market::leftJoin('wallets', 'market.wallet_from', '=', 'wallets.id')->select('market.*', 'wallets.name', 'wallets.type')->where('wallet_to', $btc_wallet->id)->orderby('wallets.type')->get();
         $btc_datainfo = array();
         foreach ($btc_markets as $value) {
             $all_market_btc[] = $value->id;
             $btc_datainfo[$value->id] = Trade::where('market_id', $value->id)->orderby('created_at', 'desc')->take(2)->get()->toArray();
             //      	$total_btc = DB::table('trade_history')->select(DB::raw('SUM( amount * price ) AS total'))
             //                  ->where('market_id', '=', $value->id)->first();
             //              //echo "<pre>total_btc: "; print_r($total_btc); echo "</pre>";
             //              //echo "<pre>getQueryLog: ".dd(DB::getQueryLog())."</pre>";
             // if(isset($total_btc->total))
             // 	$ltc_datainfo[$value->id]['total'] = $total_btc->total;
             $select = "SELECT SUM( amount * price ) AS total FROM trade_history Where `market_id`='" . $value->id . "' GROUP BY market_id";
             $total_btc = DB::select($select);
             if (isset($total_btc[0])) {
                 $btc_datainfo[$value->id]['total'] = $total_btc[0]->total;
             } else {
                 $btc_datainfo[$value->id]['total'] = 0;
             }
         }
         $data['btc_datainfo'] = $btc_datainfo;
     }
     //ltc market on sidebar left
     $all_market_ltc = array();
     if (isset($ltc_wallet->id)) {
         $ltc_markets = Market::leftJoin('wallets', 'market.wallet_from', '=', 'wallets.id')->select('market.*', 'wallets.name', 'wallets.type')->where('wallet_to', $ltc_wallet->id)->orderby('wallets.type')->get();
         $ltc_datainfo = array();
         foreach ($ltc_markets as $value) {
             $all_market_ltc[] = $value->id;
             $ltc_datainfo[$value->id] = Trade::where('market_id', $value->id)->orderby('created_at', 'desc')->take(2)->get()->toArray();
             // $total_ltc = DB::table('trade_history')->select(DB::raw('SUM( amount * price ) AS total'))
             //                  ->where('market_id', '=', $value->id)->first();
             // if(isset($total_ltc->total))
             // 	$ltc_datainfo[$value->id]['total'] = $total_ltc->total;
             $select = "SELECT SUM( amount * price ) AS total FROM trade_history Where `market_id`='" . $value->id . "' GROUP BY market_id";
             $total_ltc = DB::select($select);
             if (isset($total_ltc[0])) {
                 $ltc_datainfo[$value->id]['total'] = $total_ltc[0]->total;
             } else {
                 $ltc_datainfo[$value->id]['total'] = 0;
             }
         }
         $data['ltc_datainfo'] = $ltc_datainfo;
     }
     $data['btc_markets'] = $btc_markets;
     $data['ltc_markets'] = $ltc_markets;
     $date = date("Y-m-d H:i:s", strtotime(" -24 hour"));
     //echo "+24 hours: ".$date;
     if (!empty($all_market_btc)) {
         $data['statistic_btc'] = DB::table('trade_history')->select(DB::raw('COUNT(*) as number_trade,SUM( amount * price ) AS total'))->where('created_at', '>=', $date)->whereIn('market_id', $all_market_btc)->first();
     }
     if (!empty($all_market_ltc)) {
         $data['statistic_ltc'] = DB::table('trade_history')->select(DB::raw('COUNT(*) as number_trade,SUM( amount * price ) AS total'))->where('created_at', '>=', $date)->whereIn('market_id', $all_market_ltc)->first();
     }
     $data['wallets'] = Wallet::orderby('type')->get();
     return View::make('home', $data);
 }
Exemplo n.º 6
0
 public function addToCart()
 {
     $hot_id = Input::get('hotel_id');
     if (Input::has('room_refer_id')) {
         $room_identity = Input::get('room_refer_id');
         $room_identity_array = explode("_", $room_identity);
         $hotel_id = $room_identity_array[0];
         $room_id = $room_identity_array[1];
         $room_specification_id = $room_identity_array[2];
         $meal_basis_id = $room_identity_array[3];
         $room_count = Session::get('room_count');
         $hotel_name = Hotel::where('id', $hotel_id)->first()->name;
         $hotel_address = Hotel::where('id', $hotel_id)->first()->address;
         $room_name = RoomType::where('id', $room_id)->first()->room_type;
         $room_specification = RoomSpecification::where('id', $room_specification_id)->first()->room_specification;
         $meal_basis = MealBasis::where('id', $meal_basis_id)->first()->meal_basis_name;
         $adult = RoomSpecification::where('id', $room_specification_id)->first()->adults;
         $child = RoomSpecification::where('id', $room_specification_id)->first()->children;
         $nights = Session::get('date_gap');
         $st_date = date('Y-m-d', strtotime(Session::get('st_date')));
         $ed_date = date('Y-m-d', strtotime(Session::get('ed_date')));
         $date_count = Voucher::getNights($st_date, $ed_date)->days;
         //dd($room_id.'/'.$room_specification_id.'/'.$meal_basis_id);
         $room_rate = Rate::lowestRoomRate($hotel_id, $room_id, $room_specification_id, $meal_basis_id, $st_date, $ed_date);
         $room_rate_with_tax = Rate::lowestRoomRateWithTax($hotel_id, $room_id, $room_specification_id, $meal_basis_id, $st_date, $ed_date);
         $room_cost = $room_rate_with_tax * $room_count * $date_count;
         if (Session::has('market')) {
             $market = Session::get('market');
         } else {
             $market = 1;
         }
         $get_market_details = Market::where('id', $market)->first();
         $tax_type = $get_market_details->tax_type;
         $tax = $get_market_details->tax;
         $handling_fee_type = $get_market_details->handling_fee_type;
         $handling_fee = $get_market_details->handling_fee;
         $supplement_rate = Rate::supplementRate($hotel_id, $room_id, $room_specification_id, $meal_basis_id, $st_date, $ed_date);
         if ($market == 1) {
             if ($tax_type == 0) {
                 $total_tax = $room_rate_with_tax / 100 * $tax;
             } else {
                 $total_tax = $tax;
             }
             if ($handling_fee_type == 0) {
                 $total_handling_fee = $room_rate / 100 * $handling_fee;
             } else {
                 $total_handling_fee = $handling_fee;
             }
             $hotel_handling_fee = $total_handling_fee;
             $hotel_tax = $total_tax;
         } else {
             $total_tax = 0;
             if ($handling_fee_type == 0) {
                 $total_handling_fee = $room_rate / 100 * $handling_fee;
             } else {
                 $total_handling_fee = $handling_fee;
             }
             $hotel_tax = $total_tax;
             $hotel_handling_fee = $total_handling_fee;
         }
         $rate_box_details = array('hotel_id' => $hotel_id, 'hotel_name' => $hotel_name, 'hotel_address' => $hotel_address, 'room_name' => $room_name, 'room_type_id' => $room_id, 'room_specification' => $room_specification, 'room_specification_id' => $room_specification_id, 'meal_basis' => $meal_basis, 'meal_basis_id' => $meal_basis_id, 'room_cost' => $room_cost, 'hotel_tax' => $hotel_tax, 'hotel_handling_fee' => $hotel_handling_fee, 'supplement_rate' => $supplement_rate, 'room_count' => $room_count, 'unit_price' => $room_rate_with_tax, 'hotel_room_price' => $room_rate, 'adult' => $adult, 'child' => $child, 'nights' => $nights, 'room_identity' => $room_identity, 'check_in' => $st_date, 'check_out' => $ed_date, 'unit_cost_price' => (double) $hotel_tax + (double) $room_cost);
         if (Session::has('rate_box_details_' . $hotel_id)) {
             $data = Session::get('rate_box_details_' . $hotel_id);
             $data[$room_identity] = $rate_box_details;
         } else {
             $data = [];
             $data[$room_identity] = $rate_box_details;
         }
         Session::put('rate_box_details_' . $hotel_id, $data);
     }
     //dd(Session::get('rate_box_details_'.$hotel_id));
     return Response::json($hotel_id);
 }
 public function disableMarket()
 {
     $status = Input::get('status');
     $market_id = Input::get('market_id');
     $market = Market::find($market_id);
     if (isset($market->id)) {
         Market::where('id', $market_id)->update(array('active' => $status));
         $message = Lang::get('admin_messages.disable_success');
         if (Input::get('isAjax')) {
             echo json_encode(array('status' => 'success', 'message' => $message));
             exit;
         } else {
             return Redirect::to('admin/manage/markets')->with('success', $message);
         }
     } else {
         $message = Lang::get('admin_messages.market_not_exist');
         if (Input::get('isAjax')) {
             echo json_encode(array('status' => 'error', 'message' => $message));
             exit;
         } else {
             return Redirect::to('admin/manage/markets')->with('error', $message);
         }
     }
 }