예제 #1
0
 private function getData($user)
 {
     $data = ['usuario' => ['id' => $user->id, 'nombre' => $user->email, 'estado' => $user->estado, 'rol' => $user->rol->nombre]];
     switch ($user->rol->nombre) {
         case 'EMPRESA':
             $empresa = Empresa::where('usuario_id', $user->id)->first();
             $data['usuario']['empresa'] = ['id' => $empresa->id, 'nombre' => $empresa->nombre, 'servicios' => $this->checkServiciosEmpresa($empresa->servicios)];
             $data['usuario']['imagen'] = $empresa->logo;
             break;
         case 'CENTRAL_EMPRESA':
             $central = Central::where('usuario_id', $user->id)->first();
             $data['usuario']['central'] = ['id' => $central->id, 'nombre' => $central->nombre, 'ciudad' => $central->ciudad, 'departamento' => $central->ciudad->departamento, 'empresa' => ['id' => $central->empresa->id, 'nombre' => $central->empresa->nombre, 'nit' => $central->empresa->nit, 'nresolucion' => $central->empresa->nresolucion, 'fecha_resolucion' => $central->empresa->fecha_resolucion, 'telefono' => $central->empresa->telefono, 'direccion' => $central->empresa->direccion, 'pjuridica' => $central->empresa->pjuridica, 'servicios' => $this->checkServiciosEmpresa($central->empresa->servicios)], 'miDireccionLa' => $central->miDireccionLa, 'miDireccionLo' => $central->miDireccionLo];
             $data['usuario']['imagen'] = $central->empresa->logo;
             break;
         case 'CLIENTE':
             $cliente = Cliente::where('usuario_id', $user->id)->first();
             $data['usuario']['nombre'] = $cliente->nombres . ' ' . $cliente->apellidos;
             $data['usuario']['email'] = $cliente->email;
             $data['usuario']['identificacion'] = $cliente->identificacion;
             $data['usuario']['telefono'] = $cliente->telefono;
             $data['usuario']['imagen'] = $cliente->imegen;
             $data['usuario']['cliente_id'] = $cliente->id;
             break;
     }
     return $data;
 }
예제 #2
0
 /**
  * Display the specified resource.
  *
  * @param  int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $cliente = Cliente::find($id);
     if (!$cliente) {
         $cliente = Cliente::where('identificacion', $id)->first();
         if (!$cliente) {
             return JsonResponse::create(["message" => 'No se encontro el cliente puede registrarlo si continua'], 400);
         }
     }
     return $cliente;
 }
 function enviarNotificacionClientes($mensaje, $cliente_id, $tipo)
 {
     $devices = null;
     $device_token = null;
     $key = env('KEY_CLIENTES');
     $reg_id = '';
     //llamar al usuario
     if (is_array($cliente_id)) {
         $devices = $cliente_id;
         $reg_id = true;
     } else {
         $reg_id = Cliente::find($cliente_id);
         if ($reg_id) {
             $reg_id->load('usuario');
             $device_token = $reg_id->usuario->reg_id;
         } else {
             $reg_id = Cliente::where('identificacion', $cliente_id)->first();
             if ($reg_id) {
                 $reg_id->load('usuario');
                 $device_token = $reg_id->usuario->reg_id;
             }
         }
     }
     if ($reg_id != false) {
         if ($devices) {
             $regId = $devices;
             $regArray = $regId;
         } else {
             $regId = $device_token;
             $regArray[] = $regId;
         }
         $msg = $mensaje;
         $message = array("title" => 'Viaja seguro', "message" => $msg, "sound" => 1, "tipo" => $tipo, "subtitle" => $tipo);
         $url = 'https://android.googleapis.com/gcm/send';
         $fields = array('registration_ids' => $regArray, 'data' => $message);
         $headers = array('Authorization: key=' . $key, 'Content-Type: application/json');
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
         $result = curl_exec($ch);
         curl_close($ch);
         return $result;
     } else {
         return 'No existe el conductor';
     }
 }
예제 #4
0
 private function verificarCliente($identificacion)
 {
     return $cliente = Cliente::where('identificacion', $identificacion)->first();
 }