src/Controller/Website/CronController.php line 992

Open in your IDE?
  1. <?php
  2. namespace EADPlataforma\Controller\Website;
  3. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use EADPlataforma\Entity\Banner;
  7. use EADPlataforma\Entity\Cart;
  8. use EADPlataforma\Entity\Category;
  9. use EADPlataforma\Entity\City;
  10. use EADPlataforma\Entity\Country;
  11. use EADPlataforma\Entity\Course;
  12. use EADPlataforma\Entity\CourseCertificate;
  13. use EADPlataforma\Entity\CourseCertificateTemplate;
  14. use EADPlataforma\Entity\CourseTeam;
  15. use EADPlataforma\Entity\CourseTestimonial;
  16. use EADPlataforma\Entity\Configuration;
  17. use EADPlataforma\Entity\CycleItem;
  18. use EADPlataforma\Entity\Dns;
  19. use EADPlataforma\Entity\Enrollment;
  20. use EADPlataforma\Entity\Exam;
  21. use EADPlataforma\Entity\ExamUser;
  22. use EADPlataforma\Entity\Faq;
  23. use EADPlataforma\Entity\Forum;
  24. use EADPlataforma\Entity\ForumCategory;
  25. use EADPlataforma\Entity\Group;
  26. use EADPlataforma\Entity\Lesson;
  27. use EADPlataforma\Entity\LessonLog;
  28. use EADPlataforma\Entity\LessonLogOrigin;
  29. use EADPlataforma\Entity\LessonModule;
  30. use EADPlataforma\Entity\LessonSupport;
  31. use EADPlataforma\Entity\LessonXLibrary;
  32. use EADPlataforma\Entity\Library;
  33. use EADPlataforma\Entity\Newsletter;
  34. use EADPlataforma\Entity\Page;
  35. use EADPlataforma\Entity\Product;
  36. use EADPlataforma\Entity\ProductCharge;
  37. use EADPlataforma\Entity\ProductCoupon;
  38. use EADPlataforma\Entity\ProductOffer;
  39. use EADPlataforma\Entity\ProductPage;
  40. use EADPlataforma\Entity\ProductSuggestion;
  41. use EADPlataforma\Entity\ProductTeam;
  42. use EADPlataforma\Entity\Question;
  43. use EADPlataforma\Entity\Receiver;
  44. use EADPlataforma\Entity\ReceiverDocument;
  45. use EADPlataforma\Entity\ReceiverInvoice;
  46. use EADPlataforma\Entity\ReceiverTransfer;
  47. use EADPlataforma\Entity\State;
  48. use EADPlataforma\Entity\Session;
  49. use EADPlataforma\Entity\TaskQueue;
  50. use EADPlataforma\Entity\Transaction;
  51. use EADPlataforma\Entity\TransactionItem;
  52. use EADPlataforma\Entity\User;
  53. use EADPlataforma\Entity\UserCheckoutInfo;
  54. use EADPlataforma\Entity\UserCustomField;
  55. use EADPlataforma\Entity\UserProfile;
  56. use EADPlataforma\Entity\UserSubscription;
  57. use EADPlataforma\Entity\Webhook;
  58. use EADPlataforma\Entity\WebhookQueue;
  59. use EADPlataforma\Entity\UserLog;
  60. use EADPlataforma\Entity\Trash;
  61. use EADPlataforma\Enum\CourseEnum;
  62. use EADPlataforma\Enum\ConfigurationEnum;
  63. use EADPlataforma\Enum\TransactionEnum;
  64. use EADPlataforma\Enum\ProductEnum;
  65. use EADPlataforma\Enum\ProductCouponEnum;
  66. use EADPlataforma\Enum\ProductChargeEnum;
  67. use EADPlataforma\Enum\ProductOfferEnum;
  68. use EADPlataforma\Enum\LessonModuleEnum;
  69. use EADPlataforma\Enum\EnrollmentEnum;
  70. use EADPlataforma\Enum\ExamUserEnum;
  71. use EADPlataforma\Enum\UserSubscriptionEnum;
  72. use EADPlataforma\Enum\ClientEnum;
  73. use EADPlataforma\Enum\ServicesEnum;
  74. use EADPlataforma\Enum\ReceiverEnum;
  75. use EADPlataforma\Enum\UserEnum;
  76. use EADPlataforma\Enum\TagsMarketingEnum;
  77. use EADPlataforma\Enum\NotificationEnum;
  78. use EADPlataforma\Enum\ErrorEnum;
  79. /**
  80.  * @Route(
  81.  *      path          = "",
  82.  *      schemes         = {"http|https"}
  83.  * )
  84.  * @Cache(
  85.  *      maxage          = "0",
  86.  *      smaxage         = "0",
  87.  *      expires         = "now",
  88.  *      public          = false
  89.  * )
  90.  */
  91. class CronController extends AbstractWebsiteController {
  92.     /**
  93.      * @Route(
  94.      *      path        = "/general/{clientToken}",
  95.      *      name        = "cronGeneral",
  96.      *      methods     = {"GET"}
  97.      * )
  98.      */
  99.     public function general(Request $request) {
  100.         $token $request->headers->get('AUTH-TOKEN');
  101.         if($token != $this->generalService->getTokenCron()){
  102.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  103.         }
  104.         if($request->get('clientToken') != $this->clientConfig->getToken()){
  105.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  106.         }
  107.         $discordService $this->generalService->getService('DiscordService');
  108.         $discordService->setChannel('debug');
  109.         try{
  110.             $cronService $this->generalService->getService('Aws\\AwsEventBridge');
  111.             $cronService->deleteApiDestinationByCronName(ServicesEnum::CRON_GENERAL);
  112.         }catch(Exception $e){
  113.             $discordService->setMessage("{$this->eadDomain} - {$e->getMessage()}");
  114.             $discordService->sendDiscord();
  115.         }
  116.         $usRepository $this->em->getRepository(UserSubscription::class);
  117.         $transactionRepository $this->em->getRepository(Transaction::class);
  118.         $cartRepository $this->em->getRepository(Cart::class);
  119.         $examUserRepository $this->em->getRepository(ExamUser::class);
  120.         $examUserRepository->expiredExams();
  121.         $cartRepository->updateCartsWithProductCouponExpired();
  122.         $bill TransactionEnum::PAYMENT_BILL;
  123.         $pix TransactionEnum::PAYMENT_PIX;
  124.         
  125.         $todayDate date('Y-m-d');
  126.         $lastExecutionDay $this->configuration->get('cron_date');
  127.         if(!empty($lastExecutionDay)){
  128.             $lastExecutionDay date('Y-m-d'strtotime($lastExecutionDay));
  129.             if($todayDate == $lastExecutionDay){
  130.                 return $this->eadResponse([ "success" => ErrorEnum::YES ]);
  131.             }
  132.         }
  133.         $hour rand(7,9);
  134.         $min rand(10,59);
  135.         if(!$this->configuration->checkModuleIsAbleOnPlan('unlimitedCourseFunction')){
  136.             $courseRepository $this->em->getRepository(Course::class);
  137.             $publishCourses $courseRepository->count([
  138.                 "deleted" => CourseEnum::ITEM_NO_DELETED,
  139.                 "status" => CourseEnum::PUBLISHED
  140.             ]);
  141.             if($publishCourses CourseEnum::YES){
  142.                 $coursesPublic $courseRepository->findBy([
  143.                     "deleted" => CourseEnum::ITEM_NO_DELETED,
  144.                     "status" => CourseEnum::PUBLISHED
  145.                 ]);
  146.                 $courseNew null;
  147.                 foreach ($coursesPublic as $key => $course) {
  148.                     $course->setStatus(CourseEnum::DRAFT);
  149.                     if(!$courseNew){
  150.                         $courseNew $course;
  151.                     }
  152.                     if($course->getId() > $courseNew->getId()){
  153.                         $courseNew $course;
  154.                     }
  155.                 }
  156.                 if($courseNew){
  157.                     $course->setStatus(CourseEnum::PUBLISHED);
  158.                 }
  159.                 $this->em->flush();
  160.             }
  161.         }
  162.         $this->configuration->set('cron_date'"{$todayDate} 0{$hour}:{$min}:00"false);
  163.         $this->em->getRepository(Product::class)->notifyEnrollmentByProductPeriod();
  164.         $usRepository->completeUserSubscription();
  165.         $usRepository->expiredUserSubscription();
  166.         $usRepository->canceledUserSubscription();
  167.         
  168.         $usRepository->notifyUserSubscritpionWithCardExpired();
  169.         $usRepository->alertExpireCardUserSubscription();
  170.         //$transactionRepository->updateTransactionPaidAndAnticipated();
  171.         try{
  172.             $transactionRepository->processTransactionCardWait();
  173.         }catch(Exception $e){
  174.             $discordService->setMessage("{$this->eadDomain} - {$e->getMessage()}");
  175.             $discordService->sendDiscord();
  176.         }
  177.         
  178.         try{
  179.             $transactionRepository->cancelPaymentMethod($bill);
  180.             $transactionRepository->cancelPaymentMethod($pix);
  181.         }catch(Exception $e){
  182.             $discordService->setMessage("{$this->eadDomain} - {$e->getMessage()}");
  183.             $discordService->sendDiscord();
  184.         }
  185.         try{
  186.             $transactionRepository->alertPaymentMethod($bill);
  187.             $transactionRepository->alertPaymentMethod($pix);
  188.         }catch(Exception $e){
  189.             $discordService->setMessage("{$this->eadDomain} - {$e->getMessage()}");
  190.             $discordService->sendDiscord();
  191.         }
  192.         try{
  193.             $cartRepository->alertCheckoutWait();
  194.         }catch(Exception $e){
  195.             $discordService->setMessage("{$this->eadDomain} - {$e->getMessage()}");
  196.             $discordService->sendDiscord();
  197.         }
  198.         try{
  199.             $cartRepository->alertCartWait();
  200.         }catch(Exception $e){
  201.             $discordService->setMessage("{$this->eadDomain} - {$e->getMessage()}");
  202.             $discordService->sendDiscord();
  203.         }
  204.         try{
  205.             $this->em->getRepository(ReceiverInvoice::class)->turnInExpiredInvoices();
  206.         }catch(Exception $e){
  207.             $discordService->setMessage("{$this->eadDomain} - {$e->getMessage()}");
  208.             $discordService->sendDiscord();
  209.         }
  210.         $platformStatus $this->clientConfig->getPlatformStatus();
  211.         $suspended ClientEnum::PLATFORM_STATUS_SUSPENDED;
  212.         $canceled ClientEnum::PLATFORM_STATUS_CANCELED;
  213.         /*$amountLastDay = $transactionRepository->getAmountLastDay();
  214.         if($amountLastDay >= 500){
  215.             $receiverRepository = $this->em->getRepository(Receiver::class);
  216.             $receiversNotTrustable = $receiverRepository->findBy([
  217.                 "isTrustable" => ReceiverEnum::NO,
  218.                 "deleted" => ReceiverEnum::ITEM_NO_DELETED,
  219.                 "accountType" => ReceiverEnum::EAD_CHECKOUT,
  220.             ]);
  221.             
  222.             if(!empty($receiversNotTrustable)){
  223.                 foreach ($receiversNotTrustable as $key => $receiver) {
  224.                     $receiverHash = $receiver->getReceiverHash();
  225.                     $urlAdmin = "https://eadmin.eadplataforma.com/index.php?mod=editar-recebedor-v8&recebedor_id={$receiverHash}";
  226.                     $discordService = $this->generalService->getService('DiscordService');
  227.                     $discordService->setChannel('recebedores');
  228.                     $discordService->setMessage("Recebedor sem marcação de confiável - {$urlAdmin}");
  229.                     $discordService->sendDiscord();
  230.                 }
  231.             }
  232.         }*/
  233.         $usWasCharge = [];
  234.         if($platformStatus != $suspended && $platformStatus != $canceled){
  235.             if($this->configuration->isModuleActive("product_subscription_module")){
  236.                 $transactionItemRepository $this->em->getRepository(TransactionItem::class);
  237.                 $usRepository $this->em->getRepository(UserSubscription::class);
  238.                 $productCouponRepository $this->em->getRepository(ProductCoupon::class);
  239.                 $poRepository $this->em->getRepository(ProductOffer::class);
  240.                 $transactionService $this->generalService->getService(
  241.                     'Transaction\\TransactionService'
  242.                 );
  243.                 $notificationService $this->generalService->getService('NotificationService');
  244.                 // send marketing
  245.                 $marketingService $this->generalService->getService(
  246.                     'Marketing\\MarketingService'
  247.                 );
  248.                 $baseDate $request->get('baseDate');
  249.                 if(!isset($baseDate) && empty($baseDate)){
  250.                     $baseDate date('Y-m-d');
  251.                 }
  252.                 $card TransactionEnum::PAYMENT_CARD;
  253.                 $bill TransactionEnum::PAYMENT_BILL;
  254.                 $pix TransactionEnum::PAYMENT_PIX;
  255.                 foreach ([$bill$pix] as $key => $paymentMethodType) {
  256.                     foreach ([36] as $key => $day) {
  257.                         $items $transactionItemRepository->getTransactionItemForSubscription(
  258.                             $paymentMethodType
  259.                             $day
  260.                             $baseDate
  261.                         );
  262.                         $transactionItemRepository->sendEmailTransactionItemForSubscription(
  263.                             $items
  264.                             $paymentMethodType
  265.                             $day
  266.                         );
  267.                     }
  268.                 }
  269.                 $usNoPaidCard $usRepository->getAllUserSubscriptionNoPaidCard();
  270.                 foreach ($usNoPaidCard as $key => $userSubscription) {
  271.                     $userSubscription->setStatus(UserSubscriptionEnum::STATUS_CANCELED);
  272.                     $userSubscription->setCancelReason(UserSubscriptionEnum::CANCELED_NO_PAYMENT);
  273.                     
  274.                     $userSubscription->setDateCancel($baseDate);
  275.                     $userSubscription->setDateNextPayment($baseDate);
  276.                     $this->em->flush();
  277.                     $return $userSubscription->toReturn();
  278.                     $this->userLogService->logUpdate(
  279.                         "user_subscription"
  280.                         $userSubscription->getId(), 
  281.                         $return
  282.                     );
  283.                     $marketingService->setTag(TagsMarketingEnum::TAG_CANCELED_SUBSCRIPTION);
  284.                     $marketingService->setTextComplement(
  285.                         $userSubscription->getProduct()->getTitle()
  286.                     );
  287.                     $marketingService->setUser($userSubscription->getUser());
  288.                     $marketingService->send();
  289.                     $notificationService->create(
  290.                         $userSubscription->getProduct()->getUser(), 
  291.                         $userSubscription->getUser(),
  292.                         NotificationEnum::ORIGIN_USER_SUBSCRIPTION_CANCELED,
  293.                         $userSubscription->getId()
  294.                     );
  295.                     $notificationService->create(
  296.                         $userSubscription->getUser(), 
  297.                         $userSubscription->getProduct()->getUser(),
  298.                         NotificationEnum::ORIGIN_USER_SUBSCRIPTION_CANCELED,
  299.                         $userSubscription->getId()
  300.                     );
  301.                     $usRepository->sendEmailUserSubscription(
  302.                         $userSubscription
  303.                         UserSubscriptionEnum::SUBSCRIPTION_NO_PAYMENT5
  304.                     );
  305.                 }
  306.                 $date30 date('Y-m-d'strtotime("{$baseDate} + 30 day"));
  307.                 $userSubscriptionCard $usRepository->getUserSubscriptionToRenew(
  308.                     $card
  309.                     $date30
  310.                 );
  311.                 $userSubscriptionBill $usRepository->getUserSubscriptionToRenew(
  312.                     $bill
  313.                     $date30
  314.                 );
  315.                 $userSubscriptionPix $usRepository->getUserSubscriptionToRenew(
  316.                     $pix
  317.                     $date30
  318.                 );
  319.                 
  320.                 $userSubscriptions30 array_merge(
  321.                     $userSubscriptionCard
  322.                     $userSubscriptionBill
  323.                     $userSubscriptionPix
  324.                 );
  325.                 
  326.                 foreach ($userSubscriptions30 as $key => $userSubscription) {
  327.                     if($userSubscription->getCycle() != UserSubscriptionEnum::CYCLE_MONTHLY){
  328.                         $usRepository->sendEmailUserSubscription(
  329.                             $userSubscription
  330.                             UserSubscriptionEnum::SUBSCRIPTION_RENEW_ALERT
  331.                             30
  332.                         );
  333.                     }
  334.                 }
  335.                 $date7 date('Y-m-d'strtotime("{$baseDate} + 7 day"));
  336.                 $userSubscriptionCard $usRepository->getUserSubscriptionToRenew(
  337.                     $card
  338.                     $date7
  339.                 );
  340.                 $userSubscriptionBill $usRepository->getUserSubscriptionToRenew(
  341.                     $bill
  342.                     $date7
  343.                 );
  344.                 $userSubscriptionPix $usRepository->getUserSubscriptionToRenew(
  345.                     $pix
  346.                     $date7
  347.                 );
  348.                 $userSubscriptions7 array_merge(
  349.                     $userSubscriptionCard
  350.                     $userSubscriptionBill
  351.                     $userSubscriptionPix
  352.                 );
  353.                 foreach ($userSubscriptions7 as $key => $userSubscription) {
  354.                     $usRepository->sendEmailUserSubscription(
  355.                         $userSubscription
  356.                         UserSubscriptionEnum::SUBSCRIPTION_RENEW_ALERT
  357.                         7
  358.                     );
  359.                 }
  360.                 $userSubscriptionRenewWrong $usRepository->getUserSubscriptionToRenewWrong();
  361.                 foreach ($userSubscriptionRenewWrong as $key => $userSubscription) {
  362.                     $dateRenew date(
  363.                         'Y-m-d'
  364.                         strtotime($userSubscription->getDateRenew() . ' + 1 month ')
  365.                     );
  366.                     $userSubscription->setDateRenew($dateRenew);
  367.                     $this->em->flush();
  368.                     $return $userSubscription->toReturn();
  369.                     $this->userLogService->logUpdate(
  370.                         "user_subscription"
  371.                         $userSubscription->getId(), 
  372.                         $return
  373.                     );
  374.                 }
  375.                 $userSubscriptionsRenewCard $usRepository->getUserSubscriptionToRenew(
  376.                     $card
  377.                     $baseDate
  378.                 );
  379.                 $userSubscriptionsPayCard $usRepository->getUserSubscriptionToPay(
  380.                     $card
  381.                     $baseDate
  382.                     true
  383.                 );
  384.                 $userSubscriptionsRenewBill $usRepository->getUserSubscriptionToRenew(
  385.                     $bill
  386.                     $baseDate
  387.                 );
  388.                 $userSubscriptionsPayBill $usRepository->getUserSubscriptionToPay(
  389.                     $bill
  390.                     $baseDate
  391.                     true
  392.                 );
  393.                 $userSubscriptionsRenewPix $usRepository->getUserSubscriptionToRenew(
  394.                     $pix
  395.                     $baseDate
  396.                 );
  397.                 $userSubscriptionsPayPix $usRepository->getUserSubscriptionToPay(
  398.                     $pix
  399.                     $baseDate
  400.                     true
  401.                 );
  402.                 $allUserSubscriptions array_merge(
  403.                     $userSubscriptionsRenewCard
  404.                     $userSubscriptionsPayCard,
  405.                     $userSubscriptionsRenewBill,
  406.                     $userSubscriptionsPayBill,
  407.                     $userSubscriptionsRenewPix,
  408.                     $userSubscriptionsPayPix
  409.                 );
  410.                 $pagarMeTransaction $this->generalService->getService(
  411.                     'PagarMe\\PagarMeTransaction'
  412.                 );
  413.                 $paymentConfig $this->configuration->getPaymentConfig();
  414.                 foreach ($allUserSubscriptions as $key => $userSubscription) {
  415.                     try{
  416.                         $paymentMethod $card;
  417.                         $userCard $userSubscription->getUserCard();
  418.                         
  419.                         if(empty($userCard) && $userSubscription->getPaymentMethod() == $card){
  420.                             $userCard null;
  421.                             $paymentMethod $bill;
  422.                         }else if($userSubscription->getPaymentMethod() == $bill){
  423.                             $userCard null;
  424.                             $paymentMethod $bill;
  425.                         }else if($userSubscription->getPaymentMethod() == $pix){
  426.                             $userCard null;
  427.                             $paymentMethod $pix;
  428.                         }
  429.                         $amount $userSubscription->getPrice();
  430.                         $membershipFee $userSubscription->getMembershipFee();
  431.                         $chargeNumbers $userSubscription->getChargeNumber();
  432.                         $productCoupon $userSubscription->getProductCoupon();
  433.                         $isRenew = ($userSubscription->getDateRenew() == $baseDate);
  434.                         if(
  435.                             $userSubscription->getPaymentMethod() != UserSubscriptionEnum::PAYMENT_CARD
  436.                         ){
  437.                             $dateCharge date('Y-m-d'strtotime("{$baseDate} +7 days"));
  438.                             $isRenew = ($userSubscription->getDateRenew() == $dateCharge);
  439.                         }
  440.                         $isLifetime $userSubscription->getLifetime() == UserSubscriptionEnum::YES;
  441.                         $isRenew = ($isRenew && !$isLifetime) || empty($chargeNumbers);
  442.                         if(!empty($userSubscription->getCouponKey()) && !empty($productCoupon)){
  443.                             if(
  444.                                 $userSubscription->getCouponLifetime() == UserSubscriptionEnum::YES ||
  445.                                 $chargeNumbers $userSubscription->getCouponNumberCharges()
  446.                             ){
  447.                                 if(
  448.                                     $userSubscription->getCouponApplyMembershipFee() == ProductCouponEnum::YES
  449.                                 ){
  450.                                     if($isRenew){
  451.                                         $membershipFee $productCouponRepository->applyDiscount(
  452.                                             $productCoupon
  453.                                             $membershipFee
  454.                                         );
  455.                                     }
  456.                                 }else{
  457.                                     $amount $productCouponRepository->applyDiscount(
  458.                                         $productCoupon
  459.                                         $amount
  460.                                     );
  461.                                 }
  462.                             }else{
  463.                                 $productCoupon null;
  464.                             }
  465.                         }
  466.                         if($isRenew){
  467.                             $amount $amount $membershipFee;
  468.                             $userSubscription->setChargeNumber(0);
  469.                         }
  470.                         $amountCents round($amount 100);
  471.                         $items = [
  472.                             (object)[
  473.                                 "courseId" => null,
  474.                                 "userSubscriptionId" => $userSubscription->getId(),
  475.                                 "productOfferId" => $userSubscription->getProductOffer()->getId(),
  476.                                 "productId" => $userSubscription->getProduct()->getId(),
  477.                                 "productCouponId" => (
  478.                                     $productCoupon $productCoupon->getId() : null
  479.                                 ),
  480.                                 "amount" => $amount,
  481.                                 "cartId" => null,
  482.                             ]
  483.                         ];
  484.                         if(!in_array($userSubscription->getId(), $usWasCharge)){
  485.                             $usWasCharge[] = $userSubscription->getId();
  486.                             $transactionOrigin TransactionEnum::ORIGIN_RECURRENCE;
  487.                             $recurrenceCycle "subsequent";
  488.                             $initiatedType null;
  489.                             $recurrenceModel null;
  490.                             
  491.                             if(empty($userSubscription->getDateLastPayment())){
  492.                                 $transactionOrigin TransactionEnum::ORIGIN_INTERNAL;
  493.                                 $recurrenceCycle "first";
  494.                                 $initiatedType "Retry";
  495.                             }
  496.                             $installments $userSubscription->getInstallments();
  497.                             if(empty($installments)){
  498.                                 $installments UserSubscriptionEnum::YES;
  499.                             }
  500.                             
  501.                             if($paymentMethod == $card){
  502.                                 $freeInstallments $userSubscription->getInstallmentsFree();
  503.                                 if(
  504.                                     empty($freeInstallments) || 
  505.                                     $freeInstallments == UserSubscriptionEnum::YES
  506.                                 ){
  507.                                     $freeInstallments $poRepository->getFreeInstallment(
  508.                                         $userSubscription->getProductOffer()
  509.                                     );
  510.                                 }
  511.                                 $installmentsOptions $pagarMeTransaction->calculateInstallments([
  512.                                     'amount' => $amountCents,
  513.                                     'free_installments' => $freeInstallments,
  514.                                     'max_installments' => $installments,
  515.                                     'interest_rate' => $paymentConfig->installmentInterest
  516.                                 ]);
  517.                                 $amountCents $installmentsOptions->{$installments}->amount;
  518.                             }
  519.                             $data $transactionService->createTransactionEAD(
  520.                                 $userSubscription->getUser(),
  521.                                 $userSubscription->getUserCheckoutInfo(),
  522.                                 $amountCents,
  523.                                 $paymentMethod,
  524.                                 $installments,
  525.                                 $items,
  526.                                 $userCard,
  527.                                 null,
  528.                                 null,
  529.                                 null,
  530.                                 null,
  531.                                 $transactionOrigin,
  532.                                 "cron",
  533.                                 $recurrenceCycle,
  534.                                 $initiatedType,
  535.                                 $recurrenceModel
  536.                             );
  537.                             if(!empty($data['errorMessage'])){
  538.                                 $userSubscription->setErrorMessage($data['errorMessage']);
  539.                                 $this->em->flush();
  540.                             }else if(
  541.                                 $isRenew && 
  542.                                 !empty($userSubscription->getDateLastPayment())
  543.                             ){
  544.                                 $notificationService->create(
  545.                                     $userSubscription->getProduct()->getUser(), 
  546.                                     $userSubscription->getUser(),
  547.                                     NotificationEnum::ORIGIN_USER_SUBSCRIPTION_RENEW,
  548.                                     $userSubscription->getId()
  549.                                 );
  550.                                 $notificationService->create(
  551.                                     $userSubscription->getUser(), 
  552.                                     $userSubscription->getProduct()->getUser(),
  553.                                     NotificationEnum::ORIGIN_USER_SUBSCRIPTION_RENEW,
  554.                                     $userSubscription->getId()
  555.                                 );
  556.                     
  557.                                 $usRepository->sendEmailUserSubscription(
  558.                                     $userSubscription
  559.                                     UserSubscriptionEnum::SUBSCRIPTION_RENEW
  560.                                 );
  561.                             }
  562.                         }
  563.                     }catch(\Exception $e){
  564.                         $discordService->setMessage("{$this->eadDomain} - {$e->getMessage()}");
  565.                         $discordService->sendDiscord();
  566.                     }
  567.                 }
  568.             }
  569.         }
  570.         $class = [
  571.             Banner::class,
  572.             Category::class,
  573.             City::class,
  574.             Country::class,
  575.             Course::class,
  576.             CourseCertificate::class,
  577.             CourseCertificateTemplate::class,
  578.             CourseTeam::class,
  579.             CourseTestimonial::class,
  580.             CycleItem::class,
  581.             Enrollment::class,
  582.             Exam::class,
  583.             ExamUser::class,
  584.             Faq::class,
  585.             Forum::class,
  586.             ForumCategory::class,
  587.             Group::class,
  588.             Lesson::class,
  589.             LessonModule::class,
  590.             LessonSupport::class,
  591.             LessonXLibrary::class,
  592.             Library::class,
  593.             Newsletter::class,
  594.             Page::class,
  595.             Product::class,
  596.             ProductCharge::class,
  597.             ProductCoupon::class,
  598.             ProductOffer::class,
  599.             ProductPage::class,
  600.             ProductSuggestion::class,
  601.             ProductTeam::class,
  602.             Question::class,
  603.             Receiver::class,
  604.             ReceiverDocument::class,
  605.             State::class,
  606.             Transaction::class,
  607.             TransactionItem::class,
  608.             User::class,
  609.             UserCheckoutInfo::class,
  610.             UserCustomField::class,
  611.             UserProfile::class,
  612.             UserSubscription::class,
  613.             Webhook::class,
  614.             Trash::class
  615.         ];
  616.         foreach ($class as $key => $className) {
  617.             $repository $this->em->getRepository($className);
  618.             $repository->deleteTrashCron();
  619.         }
  620.         return $this->eadResponse([ "success" => ErrorEnum::YES ]);
  621.     }
  622.     /**
  623.      * @Route(
  624.      *      path        = "/cron/delete/log/configuration/{authToken}",
  625.      *      name        = "deleteLogConfiguration",
  626.      *      methods     = {"GET"}
  627.      * )
  628.      */
  629.     public function deleteLogConfiguration(Request $request)
  630.     {
  631.         //$token = $request->headers->get('X-AUTH-TOKEN');
  632.         $authToken $request->get('authToken');
  633.         if($authToken != $this->generalService->getTokenCron()){
  634.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  635.         }
  636.         /*if($request->get('clientToken') != $this->clientConfig->getToken()){
  637.             return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
  638.         }*/
  639.         $numberLogs $this->emEadmin->getRepository(UserLog::class)->deleteLogConfiguration();
  640.         return $this->eadResponse([ 
  641.             "success" => ErrorEnum::YES,
  642.             "configurationNumberLogs" => $numberLogs,
  643.         ]);
  644.     }
  645.     /**
  646.      * @Route(
  647.      *      path        = "/cron/callback/vimeo/{token}",
  648.      *      name        = "callbackVimeo",
  649.      *      methods     = {"GET"}
  650.      * )
  651.      */
  652.     public function callbackVimeo(Request $request)
  653.     {
  654.         $accessToken $request->get('token');
  655.         $vimeoClientAccessToken $this->configuration->get("vimeo_client_access_token");
  656.            
  657.         if(!empty($accessToken) && ($accessToken != $vimeoClientAccessToken)){
  658.             $this->configuration->set('vimeo_client_access_token'$accessToken);
  659.         }
  660.         return $this->eadResponse([ "success" => ErrorEnum::YES ]);
  661.     }
  662.     /**
  663.      * @Route(
  664.      *      path        = "/cron/token/access/rd",
  665.      *      name        = "getTokenAccessRd",
  666.      *      methods     = {"GET"}
  667.      * )
  668.      */
  669.     public function getTokenAccessRd()
  670.     {
  671.         $rdStationService $this->generalService->getService('Marketing\\RdStationService');
  672.         $rdstationAccess $this->configuration->get('rdstation_access');
  673.         $rdstationCode $this->configuration->get('rdstation_code');
  674.         if(!empty($rdstationAccess)){
  675.             $rdStationService->getTokenAccess($rdstationCodetrue);
  676.         }
  677.         return $this->eadResponse([ "success" => ErrorEnum::YES ]);
  678.     }
  679.     /**
  680.      * @Route(
  681.      *      path        = "/cron/token/access/bling",
  682.      *      name        = "getTokenAccessBling",
  683.      *      methods     = {"GET"}
  684.      * )
  685.      */
  686.     public function getTokenAccessBling()
  687.     {
  688.         $blingAuthorization $this->generalService->getService(
  689.             'Transaction\\Invoice\\BlingAuthorization'
  690.         );
  691.         $blingToken $this->configuration->get('bling_access');
  692.         $blingCode $this->configuration->get('bling_code');
  693.         if(!empty($blingToken)){
  694.             $blingAuthorization->getTokenAccess($blingCodetrue);
  695.         }
  696.         return $this->eadResponse([ "success" => ErrorEnum::YES ]);
  697.     }
  698.     /**
  699.      * @Route(
  700.      *      path        = "/cron/calculate/anticipation",
  701.      *      name        = "executeCalculateAnticipation",
  702.      *      methods     = {"GET"}
  703.      * )
  704.      */
  705.     public function executeCalculateAnticipation()
  706.     {
  707.         $transactionRepository $this->em->getRepository(Transaction::class);
  708.         $transactionRepository->updateTransactionPaidAndAnticipated();
  709.         return $this->eadResponse([ "success" => ErrorEnum::YES ]);
  710.     }
  711.     /**
  712.      * @Route(
  713.      *      path        = "/cron/ead/checkout/fee/{clientToken}",
  714.      *      name        = "getEADCheckoutFee",
  715.      *      methods     = {"GET"}
  716.      * )
  717.      */
  718.     public function getEADCheckoutFee(Request $request)
  719.     {
  720.         $token $request->headers->get('X-AUTH-TOKEN');
  721.         if($token != $this->generalService->getTokenCron()){
  722.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  723.         }
  724.         if($request->get('clientToken') != $this->clientConfig->getToken()){
  725.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  726.         }
  727.         $receiverRepository $this->em->getRepository(Receiver::class);
  728.         $transactionRepository $this->em->getRepository(Transaction::class);
  729.         $pagarMeReceiver $this->generalService->getService('PagarMe\\PagarMeReceiver');
  730.         $card TransactionEnum::PAYMENT_CARD;
  731.         $bill TransactionEnum::PAYMENT_BILL;
  732.         $pix TransactionEnum::PAYMENT_PIX;
  733.         $date1 $request->get('date1');
  734.         if(!isset($date1) && empty($date1)){
  735.             $date1 date('Y-m-d'strtotime("first day of last month"));
  736.         }  
  737.         $date2 $request->get('date2');
  738.         if(!isset($date2) && empty($date2)){
  739.             $date2 date('Y-m-d'strtotime("last day of last month"));
  740.         }
  741.         $receivers $receiverRepository->findBy([
  742.             "type" => ReceiverEnum::SCHOOL,
  743.             "accountType" => ReceiverEnum::EAD_CHECKOUT
  744.         ]);
  745.         
  746.         $data = [];
  747.         foreach ($receivers as $key => $receiver) {
  748.             $feeCard $transactionRepository->getEADFeePaymentMethod(
  749.                 $receiver->getId(), 
  750.                 $date1
  751.                 $date2
  752.                 $card
  753.             );
  754.             $feeBill $transactionRepository->getEADFeePaymentMethod(
  755.                 $receiver->getId(), 
  756.                 $date1
  757.                 $date2
  758.                 $bill
  759.             );
  760.             $feePix $transactionRepository->getEADFeePaymentMethod(
  761.                 $receiver->getId(), 
  762.                 $date1
  763.                 $date2
  764.                 $pix
  765.             );
  766.             $feeTransfer $pagarMeReceiver->getTransferFee(
  767.                 $receiver->getReceiverHash(), 
  768.                 $date1
  769.                 $date2
  770.             );
  771.             $rData = (object)[
  772.                 "feeCard" => (float)$feeCard,
  773.                 "feeBill" => (float)$feeBill,
  774.                 "feePix" => (float)$feePix,
  775.                 "feeTransfer" => $feeTransfer,
  776.                 "receiverId" => $receiver->getReceiverHash(),
  777.                 "id" => $receiver->getId(),
  778.                 "deleted" => $receiver->isLive() ? ReceiverEnum::NO ReceiverEnum::YES,
  779.             ];
  780.             $data[] = $rData;
  781.         }
  782.         return $this->eadResponse($data);
  783.     }
  784.     /**
  785.      * @Route(
  786.      *      path        = "/cron/delete/nfe/ead/checkout/{code}/{hash}",
  787.      *      name        = "deleteNfeEADCheckout",
  788.      *      methods     = {"GET"}
  789.      * )
  790.      */
  791.     public function deleteNfeEADCheckout()
  792.     {
  793.         $token $request->headers->get('AUTH-TOKEN');
  794.         if($token != $this->generalService->getTokenCron()){
  795.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  796.         }
  797.         $nfeCode $request->get('code');
  798.         $nfeHash $request->get('hash');
  799.         $receiverNfeRepository $this->em->getRepository(ReceiverNfe::class);
  800.         $receiverNfeRepository->deleteNfeEADCheckout($nfeCode$nfeHash);
  801.         $this->em->flush();
  802.         return $this->eadResponse([ "success" => ErrorEnum::YES ]);
  803.     }
  804.     /**
  805.      * @Route(
  806.      *      path        = "/email/queue/{clientToken}",
  807.      *      name        = "executeCronListEmail",
  808.      *      methods     = {"GET"}
  809.      * )
  810.      */
  811.     public function executeEmailQueue(Request $request)
  812.     {
  813.         $token $request->headers->get('AUTH-TOKEN');
  814.         if($token != $this->generalService->getTokenCron()){
  815.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  816.         }
  817.         if($request->get('clientToken') != $this->clientConfig->getToken()){
  818.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  819.         }
  820.         $taskQueueRepository $this->em->getRepository(TaskQueue::class);
  821.         $tasks $taskQueueRepository->getTaskQueue();
  822.         $date date('Y-m-d'strtotime("- 7 day"));
  823.         if($tasks){
  824.             foreach ($tasks as $key => $task) {
  825.                 try{
  826.                     if($this->configuration->checkModuleIsAbleOnPlan('notificationFunction')){
  827.                         $user $task->getUser();
  828.                         if($user->getId() != UserEnum::YES && $user->isLive()){
  829.                             if($task->getDate('Y-m-d') >= $date){
  830.                                 $taskQueueRepository->executeTask($task);
  831.                             }
  832.                         }
  833.                     }
  834.                     $this->em->remove($task);
  835.                 }catch(\Exception $e){
  836.                     $discordService $this->generalService->getService('DiscordService');
  837.                     $discordService->setChannel('debug');
  838.                     $discordService->setMessage($e->getMessage());
  839.                     $discordService->sendDiscord();
  840.                 }
  841.             }
  842.             $this->em->flush();
  843.         }
  844.         if(count($tasks) == ServicesEnum::NO){
  845.             //delete cron
  846.             $cronService $this->generalService->getService('Aws\\AwsEventBridge');
  847.             $cronService->deleteApiDestination(ServicesEnum::CRON_QUEUE);
  848.         }
  849.         return $this->eadResponse([ "success" => ErrorEnum::YES ]);
  850.     }
  851.     /**
  852.      * @Route(
  853.      *      path          = "/webhook/queue/send/{clientToken}",
  854.      *      name          = "sendWebhookQueue",
  855.      *      methods       = {"GET"}
  856.      * )
  857.      */
  858.     public function sendWebhookQueue(Request $request
  859.     {
  860.         $token $request->headers->get('AUTH-TOKEN');
  861.         if($token != $this->generalService->getTokenCron()){
  862.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  863.         }
  864.         if($request->get('clientToken') != $this->clientConfig->getToken()){
  865.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  866.         }
  867.         $webhookQueueRepository $this->em->getRepository(WebhookQueue::class);
  868.         $dataSend $webhookQueueRepository->getWebhookQueue();
  869.         $webhookService $this->generalService->getService('WebhookService');
  870.         foreach ($dataSend as $key => $webhookQueue) {
  871.             $webhookService->sendWebhookQueue($webhookQueue);
  872.         }
  873.         return $this->eadResponse([ "success" => ErrorEnum::YES ]);
  874.     }
  875.     /**
  876.      * @Route(
  877.      *      path          = "/metrics/{token}",
  878.      *      name          = "getMetricsEAD",
  879.      *      methods       = {"GET"}
  880.      * )
  881.      */
  882.     public function getMetricsEAD(Request $request
  883.     {
  884.         $token $request->headers->get('AUTH-TOKEN');
  885.         /*if($token != $this->generalService->getTokenCron()){
  886.             return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
  887.         }
  888.         if($request->get('clientToken') != $this->clientConfig->getToken()){
  889.             return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
  890.         }*/
  891.         $metricsEadService $this->generalService->getService('MetricsEadService');
  892.         $data $metricsEadService->getMetrics();
  893.         return $this->eadResponse($data);
  894.     }
  895.     /**
  896.      * @Route(
  897.      *      path          = "/remove/cron/{token}",
  898.      *      name          = "removeCron",
  899.      *      methods       = {"GET"}
  900.      * )
  901.      */
  902.     public function removeCron(Request $request
  903.     {
  904.         $token $request->headers->get('AUTH-TOKEN');
  905.         if($token != $this->generalService->getTokenCron()){
  906.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  907.         }
  908.         if($request->get('clientToken') != $this->clientConfig->getToken()){
  909.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  910.         }
  911.         $cronService $this->generalService->getService('Aws\\AwsEventBridge');
  912.         if($cronService->deleteApiDestinationByCronName(ServicesEnum::CRON_GENERAL)){
  913.             return $this->eadResponse([ "success" => ServicesEnum::YES ]);
  914.         }
  915.         return $this->eadResponse([ "error" => ServicesEnum::YES ]);
  916.     }
  917. }