✏️ 正在编辑: ReprocessamentoService.php
路径:
/srv/systems_dir/yuppiecred/application/Modules/Callcenter/Service/ReprocessamentoService.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php namespace Modules\Callcenter\Service; use Carbon\Carbon; use Modules\Core\Exception\FiltroInvalidoException; use Modules\Mail\Notificador\Send; use Zend_Controller_Request_Abstract as Request; use Doctrine\Common\Collections\ArrayCollection; use Modules\Callcenter\Dto\{ReprocessamentoDto, AtendimentosResetadosDto}; use Modules\Callcenter\Model\DbTable\{ReprocessamentoTable, AtendimentosResetadosTable}; class ReprocessamentoService { /** @var string */ public const ERRO = 'Ocorreu um erro durante a solicitação', INFORME_PERIODO = 'Informe um périodo válido.', PERIODO_INVALIDO = 'Périodo deve ser de no máximo 90 dias.' ; /** @var ReprocessamentoTable */ private $table; /** @var \Model_CallcenterBase */ private $modelCallcenter; /** @var AtendimentosResetadosTable */ private $resetadosTable; public function __construct() { $this->table = new ReprocessamentoTable(); $this->resetadosTable = new AtendimentosResetadosTable(); $this->modelCallcenter = new \Model_CallcenterBase(); } /** * @param array $data * @return array */ public function save(array $data): array { $estrategiaDto = new ReprocessamentoDto($data); return $this->table->saveRow($estrategiaDto->toArray(true)); } /** * @param int $campanha * @return ReprocessamentoDto */ public function getByCampanhaId(int $campanha): ReprocessamentoDto { $estrategia = $this->table->findByCampanhaId($campanha); if ($estrategia->getId()) { return $estrategia; } return new ReprocessamentoDto( $this->table->saveRow(['campanha_id' => $campanha]) ); } public function reprocessarAtendimentos() { $campanhas = $this->table->whereAutomatizarTrue(); $campanhasReprocessar = $campanhas->filter(function ($index) { /** @var $index ReprocessamentoDto */ return $index->getCampanhaId() && $index->isPercentualAtingido() && !$index->isLimitReprocessamentosAtingido(); }); $campanhasReprocessar->map(function ($index) { $this->resetarAtendimentosCampanha($index); }); } /** * @param ReprocessamentoDto $dto */ public function resetarAtendimentosCampanha(ReprocessamentoDto $dto) { $atendimentosDto = new AtendimentosResetadosDto([]); try { $fields = $dto->toArray(); $fields['campanha_id'] = $dto->getCampanhaId()->getId(); $atendimentosDto->setValue('campanha_id', $fields['campanha_id']); $atendimentosDto->setValue('filtros_usados', $dto->toJson()); $atendimentosDto->setValue('clientes_resetados', $this->modelCallcenter->resetarVariosClientes($fields)); $atendimentosDto->setValue('automatizacao', 1); $atendimentosDto->setValue('retorno_discador', $this->enviarDiscador($dto)); Send::campanhaPercentual( $dto->getCampanhaId()->getNomeId(), $dto->getPercentualCampanha(), $atendimentosDto->getClientesResetados() ); } catch (\Throwable $throwable) { $atendimentosDto->setValue('erro', $throwable->getMessage()); } $atendimentosDto->setValue('data_processo', Carbon::now()->format('Y-m-d H:i:s')); $resetadosLog = $this->resetadosTable->createRow($atendimentosDto->toArray(true)); $resetadosLog->save(); } /** * @return ArrayCollection */ public function historicoCampanhasResetadas(Request $request): ArrayCollection { if (!$request->isPost()) { return new ArrayCollection(); } $fields = $this->validarFiltroHistorico($request); return $this->resetadosTable->historico($fields); } /** * @param ReprocessamentoDto $dto * @return string|null */ public function enviarDiscador(ReprocessamentoDto $dto): ?string { if ($dto->getEnviarDiscador()) { return (new CallcenterDiscadorService())->enviarCampanhaDiscador($dto->getCampanhaId()->getId()); } return null; } /** * @param Request $request * @return array */ public function validarFiltroHistorico(Request $request): array { $fields = array_filter($request->getPost(), function ($index) { return $index !== "" && !is_null($index); }); unset($fields['buscar']); if (empty($fields)) { throw new FiltroInvalidoException(); } if (empty($fields['data_reprocessado_de']) || empty($fields['data_reprocessado_a'])) { throw new FiltroInvalidoException(self::INFORME_PERIODO); } $fields['data_reprocessado_de'] = Carbon::createFromFormat( 'd/m/Y H:i:s', $fields['data_reprocessado_de'] . '00:00:00' ); $fields['data_reprocessado_a'] = Carbon::createFromFormat( 'd/m/Y H:i:s', $fields['data_reprocessado_a'] . '99:99:99' ); if ($fields['data_reprocessado_de']->diffInDays($fields['data_reprocessado_a']) > 90) { throw new FiltroInvalidoException(self::PERIODO_INVALIDO); } return $fields; } }
💾 保存文件
← 返回文件管理器