public function pay($id)
 {
     \PagSeguroLibrary::init();
     \PagSeguroConfig::setEnvironment('production');
     $this->plan = Plans::find($id);
     $this->client = User::find(Auth::user()->id);
     $this->payment = Payments::create(['plan_name' => $this->plan->name, 'plan_value' => $this->plan->value, 'plan_id' => $this->plan->id, 'user_id' => $this->client->id, 'confirmed' => 0]);
     // Instantiate a new payment request
     $paymentRequest = new \PagSeguroPaymentRequest();
     // Set the currency
     $paymentRequest->setCurrency("BRL");
     /* // Add an item for this payment request
        $paymentRequest->addItem('0001', 'Sempre da Negócio - Plano '.$this->plan->name, 1, $this->plan->value);*/
     $paymentRequest->addItem($this->plan->id, 'Sempre da Negócio - Plano ' . $this->plan->name, 1, $this->plan->value);
     // Set a reference code for this payment request. It is useful to identify this payment
     // in future notifications.
     $paymentRequest->setReference($this->payment->id);
     //Create object PagSeguroShipping
     $shipping = new \PagSeguroShipping();
     //Set Type Shipping
     $type = new \PagSeguroShippingType(3);
     $shipping->setType($type);
     //Set address of client
     $data = array('postalCode' => $this->client->zipcode, 'street' => $this->client->address, 'number' => $this->client->number, 'city' => $this->client->city, 'state' => $this->client->state);
     $address = new \PagSeguroAddress($data);
     $shipping->setAddress($address);
     //Add Shipping to Payment Request
     $paymentRequest->setShipping($shipping);
     // Set your customer information.
     $phone = str_replace(['(', ')', ' ', '-'], ['', '', '', ''], $this->client->phone);
     $paymentRequest->setSender($this->client->name, $this->client->email_responsible, substr($phone, 0, 2), substr($phone, 2));
     try {
         /*
                      * #### Credentials #####
                      * Replace the parameters below with your credentials (e-mail and token)
                      * You can also get your credentials from a config file. See an example:
                      * $credentials = PagSeguroConfig::getAccountCredentials();
                     //  */
         $credentials = new \PagSeguroAccountCredentials($this->email, $this->token);
         // Register this payment request in PagSeguro to obtain the payment URL to redirect your customer.
         $onlyCheckoutCode = true;
         $code = $paymentRequest->register($credentials, $onlyCheckoutCode);
         return view('site.pages.confirma_pagamento', compact('code'));
     } catch (\PagSeguroServiceException $e) {
         die($e->getMessage());
     }
 }
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     $userUrl = str_slug($data['name']);
     $user = User::create(['name' => $data['name'], 'email' => $data['email'], 'url_name' => $userUrl, 'password' => bcrypt($data['password'])]);
     \Event::fire(new UsuarioInserido($user));
     return $user;
 }
 public function usuariosSemAnuncio()
 {
     // $adverts = User::where('password', null)->count();
     // dd($adverts);
     $advertsTotal = 1445000;
     $aaa = 0;
     $conta = 1;
     while ($conta < $advertsTotal) {
         $termino = $conta + 5000;
         $users = null;
         $users = User::where('password', null)->where('id', '>=', $conta)->where('id', '<=', $termino)->get();
         foreach ($users as $us) {
             $qnt = Advert::where('user_id', $us->id)->count();
             if ($qnt <= 0) {
                 $us->delete();
             }
         }
         $conta = $termino;
     }
     echo $aaa;
 }
 public function hotsite($id, $url_name)
 {
     $user = User::find($id);
     if ($user->typeuser_id < 5) {
         $subcategories = SubCategory::where('category_id', 1)->get();
     } else {
         $subcategories = Subcategory::where('category_id', 2)->get();
     }
     $advertUser = Advert::where('user_id', $id)->where('status', '>', '0')->orderByRaw("RAND()")->paginate(18);
     $marcas = VeiculoMarca::get();
     $advertAluga = Advert::where('user_id', $id)->where('tipo_anuncio', '=', 'aluga')->where('status', '>', '0')->count();
     $advertVenda = Advert::where('user_id', $id)->where('tipo_anuncio', '=', 'venda')->where('status', '>', '0')->count();
     if (empty($advertUser)) {
         return view('error.error404');
     } else {
         return view('site.pages.hotsite', compact('advertUser', 'user', 'advertAluga', 'advertVenda', 'subcategories', 'marcas'));
     }
 }
 public function index()
 {
     $id = Auth::user()->id;
     $user = User::find($id);
     return view('admin.perfil.index', compact($user));
 }
 public function store(Storage $storage, Requests\AdvertSaveRequest $request, AdvertImage $advertImage, User $user, AdvertImovel $advertImovel, AdvertVeiculo $advertVeiculo)
 {
     $data = $request->all();
     //aqui eu atualizo as informações do usuário
     $data['user_id'] = Auth::user()->id;
     $user = User::find($data['user_id']);
     $user->name = $request->get('nome-usuario');
     $user->phone = $request->get('telefone-usuario');
     $user->email = $request->get('email');
     if (empty($user->typeuser_id)) {
         $user->typeuser_id = $request->get('typeuser_id');
     }
     $user->update();
     $data['url_anuncio'] = str_slug($data['anuncio_titulo']);
     $features = $request->get('caracteristicas');
     $images = $request->file('anuncio_images');
     $data['preco'] = str_replace(",", ".", str_replace(".", "", $data['preco']));
     unset($data['anuncio_images']);
     unset($data['caracteristicas']);
     $anuncio = Advert::create($data);
     foreach ($images as $image) {
         $renamed = "imoveis/site/" . md5(date('Ymdhms') . $image->getClientOriginalName()) . '.' . $image->getClientOriginalExtension();
         $path = public_path() . '/galeria/' . $renamed;
         Image::make($image->getRealPath())->resize(678, 407)->save($path);
         $advertImage::create(['advert_id' => $anuncio->id, 'extension' => $renamed]);
     }
     if (!empty($features)) {
         $anuncio->features()->sync($features);
     }
     if ($data['category_id'] == 1) {
         if (empty($data['numero_quarto'])) {
             $numero_quarto = 0;
         } else {
             $numero_quarto = $data['numero_quarto'];
         }
         if (empty($data['numero_garagem'])) {
             $numero_garagem = 0;
         } else {
             $numero_garagem = $data['numero_garagem'];
         }
         if (empty($data['numero_banheiro'])) {
             $numero_banheiro = 0;
         } else {
             $numero_banheiro = $data['numero_banheiro'];
         }
         if (empty($data['area_construida'])) {
             $area_construida = 0;
         } else {
             $area_construida = $data['area_construida'];
         }
         if (empty($data['valor_condominio'])) {
             $valor_condominio = 0;
         } else {
             $valor_condominio = str_replace(",", ".", str_replace(".", "", $data['valor_condominio']));
         }
         if (empty($data['valor_iptu'])) {
             $valor_iptu = 0;
         } else {
             $valor_iptu = str_replace(",", ".", str_replace(".", "", $data['valor_iptu']));
         }
         if (empty($data['acomodacoes'])) {
             $acomodacoes = 0;
         } else {
             $acomodacoes = $data['acomodacoes'];
         }
         $advertImovel::create(['numero_quarto' => $numero_quarto, 'numero_garagem' => $numero_garagem, 'numero_banheiro' => $numero_banheiro, 'area_construida' => $area_construida, 'valor_condominio' => $valor_condominio, 'valor_iptu' => $valor_iptu, 'acomodacoes' => $acomodacoes, 'advert_id' => $anuncio->id, 'category_id' => $data['category_id']]);
     } else {
         if ($data['category_id'] == 2) {
             $tipo = $data['tipo'];
             $km = $data['km'];
             $cor = $data['cor'];
             $portas = $data['portas'];
             $cambio = $data['cambio'];
             $combustivel = $data['combustivel'];
             $placa = $data['placa'];
             $cor = $data['cor'];
             $marca = $data['marca_id'];
             $modelo = $data['modelo_id'];
             $opcionais = 0;
             if (empty($data['preco_fipe'])) {
                 $preco_fipe = 0;
             } else {
                 $preco_fipe = str_replace(",", ".", str_replace(".", "", $data['preco_fipe']));
             }
             if (empty($data['preco_min'])) {
                 $preco_min = 0;
                 $preco_leilao = 0;
             } else {
                 $preco_min = str_replace(",", ".", str_replace(".", "", $data['preco_min']));
                 $preco_leilao = $preco_min;
             }
             if (empty($data['preco_max'])) {
                 $preco_max = 0;
             } else {
                 $preco_max = str_replace(",", ".", str_replace(".", "", $data['preco_max']));
             }
             if (empty($data['variancia'])) {
                 $variancia = 0;
             } else {
                 $variancia = str_replace(",", ".", str_replace(".", "", $data['variancia']));
             }
             if (empty($data['leilao'])) {
                 $leilao = 0;
             } else {
                 $leilao = $data['leilao'];
             }
             if (empty($data['preco_fipe'])) {
                 $leilao = 0;
             } else {
                 $preco_fipe = $data['preco_fipe'];
             }
             $advertVeiculo::create(['ano' => $tipo, 'km' => $km, 'cor' => $cor, 'portas' => $portas, 'cambio' => $cambio, 'combustivel' => $combustivel, 'placa' => $placa, 'opcionais' => $opcionais, 'marca' => $marca, 'modelo' => $modelo, 'leilao' => $leilao, 'preco_fipe' => $preco_fipe, 'preco_leilao' => $preco_leilao, 'preco_min' => $preco_min, 'preco_max' => $preco_max, 'variancia' => $variancia, 'advert_id' => $anuncio->id, 'category_id' => $data['category_id']]);
         }
     }
     if ($anuncio) {
         $dataSend = ['id' => $anuncio->id, 'name' => $user->name, 'email' => $user->email, 'tipo_anuncio' => $anuncio->tipo_anuncio, 'url_anuncio' => $anuncio->url_anuncio];
         \Mail::send('emails.anuncioInserido', $dataSend, function ($message) use($dataSend) {
             $message->from('*****@*****.**', 'Sempre da Negócio');
             $message->subject('Seu anúncio encontra disponível');
             $message->to($dataSend['email']);
         });
     }
     if (auth()->user()->plans_id != null) {
         return redirect('/')->with('status', 'Parabéns!! Seu anúncio foi publicado!');
     } else {
         return redirect('/pagamento')->with('status', 'Parabéns!! Seu anúncio foi publicado!');
     }
 }