Accelerar listado ventas
This commit is contained in:
@ -74,6 +74,32 @@ class Ventas extends Controller
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function getMany(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Service\Venta $service): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $body,
|
||||
'ventas' => []
|
||||
];
|
||||
$ventas = explode(',', $body['ventas']);
|
||||
foreach ($ventas as $venta_id) {
|
||||
$redisKey = "venta:{$venta_id}";
|
||||
try {
|
||||
$venta = $this->fetchRedis($redisService, $redisKey);
|
||||
$output['ventas'] []= $venta;
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$venta = $service->getById($venta_id);
|
||||
$output['ventas'] []= $venta;
|
||||
$this->saveRedis($redisService, $redisKey, $venta);
|
||||
} catch (EmptyResult $exception) {
|
||||
$this->logger->notice($exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function porFirmar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, Service\Redis $redisService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
|
@ -376,6 +376,27 @@ class Venta extends Ideal\Repository
|
||||
->group('venta.id');
|
||||
return $this->connection->execute($query, [$venta_id])->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
public function fetchByIdForList(int $venta_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('venta.id AS id, venta.fecha AS fecha, venta.valor_uf AS valor')
|
||||
->columns('proyecto.id AS proyecto_id, proyecto.descripcion AS proyecto_descripcion')
|
||||
->columns('CONCAT_WS(" ", propietario.nombres, propietario.apellido_paterno, propietario.apellido_materno) AS propietario')
|
||||
->columns("GROUP_CONCAT(unidad.descripcion SEPARATOR ' - ') AS unidad_descripcion, tu.descripcion AS tipo_unidad_descripcion, ptu.m2 + ptu.logia + ptu.terraza AS superficie")
|
||||
->columns('tev.activa')
|
||||
->from($this->getTable())
|
||||
->joined('JOIN propietario ON propietario.rut = venta.propietario')
|
||||
->joined('JOIN propiedad_unidad pu ON pu.propiedad = venta.propiedad')
|
||||
->joined('JOIN unidad ON unidad.id = pu.unidad')
|
||||
->joined('JOIN proyecto_tipo_unidad ptu ON unidad.pt = ptu.id')
|
||||
->joined('JOIN proyecto ON proyecto.id = ptu.proyecto')
|
||||
->joined('JOIN tipo_unidad tu ON tu.id = ptu.tipo')
|
||||
->joined('JOIN (SELECT ev1.* FROM estado_venta ev1 JOIN (SELECT MAX(id) AS id, venta FROM estado_venta GROUP BY venta) ev0 ON ev0.id = ev1.id) ev ON ev.venta = venta.id')
|
||||
->joined('JOIN tipo_estado_venta tev ON ev.estado = tev.id')
|
||||
->where('venta.id = ?')
|
||||
->group('venta.id');
|
||||
return $this->connection->execute($query, [$venta_id])->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
protected function fetchIds(string $query, ?array $data = null): array
|
||||
{
|
||||
|
@ -79,6 +79,10 @@ class Venta extends Service
|
||||
{
|
||||
return $this->ventaRepository->fetchByIdForSearch($venta_id);
|
||||
}
|
||||
public function getByIdForList(int $venta_id): array
|
||||
{
|
||||
return $this->ventaRepository->fetchByIdForList($venta_id);
|
||||
}
|
||||
|
||||
protected function process(Model\Venta $venta): Model\Venta
|
||||
{
|
||||
|
Reference in New Issue
Block a user