Пример #1
0
 function addgaleria(Request $request, Response $response)
 {
     $response = $response->withHeader('Content-type', 'application/json');
     $data = json_decode($request->getBody(), true);
     try {
         $id = $request->getAttribute("id");
         $galeria = new Galeria();
         $galeria->logo = $data['logo'];
         $galeria->idSucursal = $data['idsucursal'];
         $galeria->fecha = fechaHoraActual();
         $galeria->save();
         $respuesta = json_encode(array('msg' => "Guardado correctamente", "std" => 1));
         $response = $response->withStatus(200);
     } catch (Exception $err) {
         $respuesta = json_encode(array('msg' => "error", "std" => 0, "err" => $err->getMessage()));
         $response = $response->withStatus(404);
     }
     $response->getBody()->write($respuesta);
     return $response;
 }
Пример #2
0
 public function cambiarEstadoTurno(Request $request, Response $response)
 {
     $response = $response->withHeader('Content-type', 'application/json');
     $data = json_decode($request->getBody(), true);
     $id = $request->getAttribute("id");
     $idEmpleado = $request->getAttribute("idEmpleado");
     $idServicio = $request->getAttribute("idServicio");
     $banTerminado = false;
     try {
         $turno = Turno::select("turno.*", "cliente.idPush", "servicio.nombre as servicio", "empleado.nombres as empleado1", "empleado.apellidos as empleado2")->join("cliente", "cliente.id", "=", "turno.idCliente")->join("servicio", "servicio.id", "=", "turno.idServicio")->join("empleado", "empleado.id", "=", "turno.idEmpleado")->where("turno.id", "=", $id)->first();
         $turno->estadoTurno = $data['estadoTurno'];
         if ($turno->estadoTurno == "TERMINADO") {
             $turno->fechaFinal = fechaHoraActual();
             $banTerminado = true;
         }
         if ($turno->estadoTurno == "ATENDIENDO") {
             $turno->fechaInicio = fechaHoraActual();
         }
         if ($turno->estadoTurno == "CONFIRMADO") {
             $payload = array('title' => "Turno movil", 'msg' => "Tu turno ha sido aceptado.", 'std' => 0, 'idServicio' => "0");
             $notification = array('body' => "Tu turno ha sido aceptado.", 'title' => "Aceptación de turno.");
             enviarNotificacion(array($turno->idPush), $payload);
             enviarNotificacionIos($turno->idPush, $notification);
         }
         if ($turno->estadoTurno == "CANCELADO") {
             $payload = array('title' => "Turno movil", 'msg' => "Tu turno ha sido aceptado.", 'std' => 0, 'idServicio' => "0");
             $notification = array('body' => "Tu turno no ha sido aceptado.", 'title' => "Cancelación de turno.");
             enviarNotificacion(array($turno->idPush), $payload);
             enviarNotificacionIos($turno->idPush, $notification);
         }
         $turno->save();
         if ($banTerminado) {
             //ENVIAR NOTIFICACIONES A LOS CLIENTES
             $turnos = Turno::select("turno.*", "cliente.idPush")->join("cliente", "cliente.id", "=", "turno.idCliente")->where(function ($query) {
                 $query->where("turno.estadoTurno", "=", "CONFIRMADO")->orwhere("turno.estadoTurno", "=", "ATENDIENDO");
             })->where("turno.idEmpleado", "=", $idEmpleado)->where("turno.idServicio", "=", $idServicio)->where("turno.tipoTurno", "<>", 2)->orderBy('turno.fechaSolicitud', 'asc')->get();
             for ($i = 0; $i < count($turnos); $i++) {
                 $query = "SELECT " . "(COALESCE(AVG(TIMESTAMPDIFF(SECOND,fechaInicio,fechaFinal)),0) * turnosFaltantes.faltantes) as tiempoEstimado " . "FROM " . "( " . "  SELECT " . "    count(t.id) as faltantes " . "    FROM " . "    turno as t " . "    WHERE " . "    t.idEmpleado = " . $idEmpleado . " AND " . "    t.idServicio = " . $idServicio . " AND " . "    t.fechaSolicitud < '" . $turnos[$i]->fechaSolicitud . "' AND " . "    t.estadoTurno <> 'TERMINADO' AND t.estadoTurno <> 'CANCELADO'" . ") as turnosFaltantes, " . "turno " . "WHERE " . "idEmpleado = " . $idEmpleado . " AND " . "idServicio = " . $idServicio . " AND " . "estadoTurno = 'TERMINADO' LIMIT 1";
                 $dataTiempo = DB::select(DB::raw($query));
                 if (count($dataTiempo) > 0) {
                     //VARIFICAR SI YA PASO UN TIEMPO PARAMETRIZDO PARA AVISARLE
                     $tiempo = ceil($dataTiempo[0]->tiempoEstimado / 60);
                     if ($tiempo < 5) {
                         try {
                             $tu = Turno::select("*")->where("id", "=", $turnos[$i]->id)->first();
                             $tu->avisado = 1;
                             $tu->save();
                         } catch (Exception $err) {
                         }
                     }
                     //ANVIAR NOTIFICACION
                     $payload = array('title' => "Turno movil", 'msg' => "Ya esta cerca tu turno, solo falta " . $tiempo . " minutos", 'std' => 0, 'idServicio' => "0");
                     $notification = array('body' => "Ya esta cerca tu turno, solo falta " . $tiempo . " minutos", 'title' => "Informacion de Turno.");
                     enviarNotificacion(array($turnos[$i]->idPush), $payload);
                     enviarNotificacionIos($turnos[$i]->idPush, $notification);
                     //array_push($vec, $turnos[$i]->idPush);
                 }
             }
             //BUSCAR PRECIO DEL SERVICIO
             $valorServicio = ServiciosSucursal::select("*")->where("idServicio", "=", $turno->idServicio)->where("idSucursal", "=", $turno->idSucursal)->first();
             $valor = $valorServicio->precio;
             if ($turno->tipoTurno == 2) {
                 $valor = $valorServicio->precioVIP;
             }
             if ($valor != null && $valor != 0) {
                 //INSERTAR EN INGRESOS
                 try {
                     $ingreso = new Ingreso();
                     $ingreso->idServicio = $turno->idServicio;
                     $ingreso->idEmpleado = $turno->idEmpleado;
                     $ingreso->valor = $valor;
                     $ingreso->save();
                 } catch (Exception $ex) {
                 }
             }
             //ENVIAR NOTIFICACION PARA QUE EL CLIENTE CALIFIQUE EL SERVICIO
             $payload = array('title' => "Turno movil", 'msg' => "Califica el servicio", 'std' => 10, 'idServicio' => $turno->idServicio, 'idSucursal' => $turno->idSucursal, 'idEmpleado' => $turno->idEmpleado, 'empleado' => $turno->empleado1 . " " . $turno->empleado2, 'servicio' => $turno->servicio);
             enviarNotificacion(array($turno->idPush), $payload);
         }
         $respuesta = json_encode(array('msg' => "Modificado correctamente", "std" => 1));
         $response = $response->withStatus(200);
     } catch (Exception $err) {
         $respuesta = json_encode(array('msg' => "error", "std" => 0, "err" => $err->getMessage()));
         $response = $response->withStatus(404);
     }
     $response->getBody()->write($respuesta);
     return $response;
 }