src/EventListener/OrderStatusSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Entity\Main\Orders;
  4. use App\Entity\Main\Services;
  5. use App\Entity\Main\StateFees;
  6. use App\Service\ApiService;
  7. use App\Service\ApplicationService;
  8. use App\Service\PipeBotService;
  9. use Symfony\Component\EventDispatcher\GenericEvent;
  10. class OrderStatusSubscriber
  11. {
  12.     protected $pipeBotService;
  13.     
  14.     protected $applicationService;
  15.     
  16.     protected $apiService;
  17.     
  18.     public function __construct(PipeBotService $pipeBotServiceApplicationService $applicationServiceApiService $apiService)
  19.     {
  20.         $this->pipeBotService $pipeBotService;
  21.         $this->applicationService $applicationService;
  22.         $this->apiService $apiService;
  23.     }
  24.     
  25.     public function __invoke(GenericEvent $event)
  26.     {
  27.         $orders $event->getSubject();
  28.         if ($orders instanceof Orders) {
  29.             $change $event->getArgument('em')->getUnitOfWork()->getOriginalEntityData($orders);
  30.             //Проверяем есть ли в измененых данных payed
  31.             if (isset($change['payed'])) {
  32.                 
  33.                 //Получаем старое значение и новое
  34.                 $old $change['payed'];
  35.                 $new $orders->getPayed();
  36.                 
  37.                 //Если значения разные и новое значение true
  38.                 if ($old !== $new and $new === true) {
  39.                     $stateFeesType $type $registrationNumber '';
  40.                     //Распарсиваем json что бы узнать есть ли там данные registerNumber и type
  41.                     $json json_decode($orders->getAdditionalInformation(), true);
  42.                     if(!empty($json)){
  43.                         if(!empty($json['registrationNumber'])){
  44.                             $registrationNumber $json['registrationNumber'];
  45.                         }
  46.                         if(!empty($json['type'])){
  47.                             if($orders->getStateFeeId() instanceof StateFees){
  48.                                 $stateFeesType $json['type'];
  49.                             }
  50.                             if($orders->getService() instanceof Services) {
  51.                                 $type $json['type'];
  52.                             }
  53.                         }
  54.                     }
  55.                     
  56.                     //Обрабатываем после оплаты действия которые нужно сделать с экшинами и дальнейшими шагами оплатв
  57.                     $this->apiService->ordersRules($orders$this->pipeBotService$this->applicationService$orders->getUsers(), $stateFeesType$type$registrationNumbernull);
  58.                 }
  59.             }
  60.         }
  61.     }
  62. }