src/Controller/Website/CronController.php line 892

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