src/Controller/Website/CronController.php line 982

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.                             if(empty($userSubscription->getDateLastPayment())){
  488.                                 $transactionOrigin TransactionEnum::ORIGIN_INTERNAL;
  489.                             }
  490.                             $installments $userSubscription->getInstallments();
  491.                             if(empty($installments)){
  492.                                 $installments UserSubscriptionEnum::YES;
  493.                             }
  494.                             
  495.                             if($paymentMethod == $card){
  496.                                 $freeInstallments $userSubscription->getInstallmentsFree();
  497.                                 if(
  498.                                     empty($freeInstallments) || 
  499.                                     $freeInstallments == UserSubscriptionEnum::YES
  500.                                 ){
  501.                                     $freeInstallments $poRepository->getFreeInstallment(
  502.                                         $userSubscription->getProductOffer()
  503.                                     );
  504.                                 }
  505.                                 $installmentsOptions $pagarMeTransaction->calculateInstallments([
  506.                                     'amount' => $amountCents,
  507.                                     'free_installments' => $freeInstallments,
  508.                                     'max_installments' => $installments,
  509.                                     'interest_rate' => $paymentConfig->installmentInterest
  510.                                 ]);
  511.                                 $amountCents $installmentsOptions->{$installments}->amount;
  512.                             }
  513.                             $data $transactionService->createTransactionEAD(
  514.                                 $userSubscription->getUser(),
  515.                                 $userSubscription->getUserCheckoutInfo(),
  516.                                 $amountCents,
  517.                                 $paymentMethod,
  518.                                 $installments,
  519.                                 $items,
  520.                                 $userCard,
  521.                                 null,
  522.                                 null,
  523.                                 null,
  524.                                 null,
  525.                                 $transactionOrigin,
  526.                                 "cron"
  527.                             );
  528.                             if(!empty($data['errorMessage'])){
  529.                                 $userSubscription->setErrorMessage($data['errorMessage']);
  530.                                 $this->em->flush();
  531.                             }else if(
  532.                                 $isRenew && 
  533.                                 !empty($userSubscription->getDateLastPayment())
  534.                             ){
  535.                                 $notificationService->create(
  536.                                     $userSubscription->getProduct()->getUser(), 
  537.                                     $userSubscription->getUser(),
  538.                                     NotificationEnum::ORIGIN_USER_SUBSCRIPTION_RENEW,
  539.                                     $userSubscription->getId()
  540.                                 );
  541.                                 $notificationService->create(
  542.                                     $userSubscription->getUser(), 
  543.                                     $userSubscription->getProduct()->getUser(),
  544.                                     NotificationEnum::ORIGIN_USER_SUBSCRIPTION_RENEW,
  545.                                     $userSubscription->getId()
  546.                                 );
  547.                     
  548.                                 $usRepository->sendEmailUserSubscription(
  549.                                     $userSubscription
  550.                                     UserSubscriptionEnum::SUBSCRIPTION_RENEW
  551.                                 );
  552.                             }
  553.                         }
  554.                     }catch(\Exception $e){
  555.                         $discordService->setMessage("{$this->eadDomain} - {$e->getMessage()}");
  556.                         $discordService->sendDiscord();
  557.                     }
  558.                 }
  559.             }
  560.         }
  561.         $class = [
  562.             Banner::class,
  563.             Category::class,
  564.             City::class,
  565.             Country::class,
  566.             Course::class,
  567.             CourseCertificate::class,
  568.             CourseCertificateTemplate::class,
  569.             CourseTeam::class,
  570.             CourseTestimonial::class,
  571.             CycleItem::class,
  572.             Enrollment::class,
  573.             Exam::class,
  574.             ExamUser::class,
  575.             Faq::class,
  576.             Forum::class,
  577.             ForumCategory::class,
  578.             Group::class,
  579.             Lesson::class,
  580.             LessonModule::class,
  581.             LessonSupport::class,
  582.             LessonXLibrary::class,
  583.             Library::class,
  584.             Newsletter::class,
  585.             Page::class,
  586.             Product::class,
  587.             ProductCharge::class,
  588.             ProductCoupon::class,
  589.             ProductOffer::class,
  590.             ProductPage::class,
  591.             ProductSuggestion::class,
  592.             ProductTeam::class,
  593.             Question::class,
  594.             Receiver::class,
  595.             ReceiverDocument::class,
  596.             State::class,
  597.             Transaction::class,
  598.             TransactionItem::class,
  599.             User::class,
  600.             UserCheckoutInfo::class,
  601.             UserCustomField::class,
  602.             UserProfile::class,
  603.             UserSubscription::class,
  604.             Webhook::class,
  605.             Trash::class
  606.         ];
  607.         foreach ($class as $key => $className) {
  608.             $repository $this->em->getRepository($className);
  609.             $repository->deleteTrashCron();
  610.         }
  611.         return $this->eadResponse([ "success" => ErrorEnum::YES ]);
  612.     }
  613.     /**
  614.      * @Route(
  615.      *      path        = "/cron/delete/log/configuration/{authToken}",
  616.      *      name        = "deleteLogConfiguration",
  617.      *      methods     = {"GET"}
  618.      * )
  619.      */
  620.     public function deleteLogConfiguration(Request $request)
  621.     {
  622.         //$token = $request->headers->get('X-AUTH-TOKEN');
  623.         $authToken $request->get('authToken');
  624.         if($authToken != $this->generalService->getTokenCron()){
  625.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  626.         }
  627.         /*if($request->get('clientToken') != $this->clientConfig->getToken()){
  628.             return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
  629.         }*/
  630.         $numberLogs $this->emEadmin->getRepository(UserLog::class)->deleteLogConfiguration();
  631.         return $this->eadResponse([ 
  632.             "success" => ErrorEnum::YES,
  633.             "configurationNumberLogs" => $numberLogs,
  634.         ]);
  635.     }
  636.     /**
  637.      * @Route(
  638.      *      path        = "/cron/callback/vimeo/{token}",
  639.      *      name        = "callbackVimeo",
  640.      *      methods     = {"GET"}
  641.      * )
  642.      */
  643.     public function callbackVimeo(Request $request)
  644.     {
  645.         $accessToken $request->get('token');
  646.         $vimeoClientAccessToken $this->configuration->get("vimeo_client_access_token");
  647.            
  648.         if(!empty($accessToken) && ($accessToken != $vimeoClientAccessToken)){
  649.             $this->configuration->set('vimeo_client_access_token'$accessToken);
  650.         }
  651.         return $this->eadResponse([ "success" => ErrorEnum::YES ]);
  652.     }
  653.     /**
  654.      * @Route(
  655.      *      path        = "/cron/token/access/rd",
  656.      *      name        = "getTokenAccessRd",
  657.      *      methods     = {"GET"}
  658.      * )
  659.      */
  660.     public function getTokenAccessRd()
  661.     {
  662.         $rdStationService $this->generalService->getService('Marketing\\RdStationService');
  663.         $rdstationAccess $this->configuration->get('rdstation_access');
  664.         $rdstationCode $this->configuration->get('rdstation_code');
  665.         if(!empty($rdstationAccess)){
  666.             $rdStationService->getTokenAccess($rdstationCodetrue);
  667.         }
  668.         return $this->eadResponse([ "success" => ErrorEnum::YES ]);
  669.     }
  670.     /**
  671.      * @Route(
  672.      *      path        = "/cron/token/access/bling",
  673.      *      name        = "getTokenAccessBling",
  674.      *      methods     = {"GET"}
  675.      * )
  676.      */
  677.     public function getTokenAccessBling()
  678.     {
  679.         $blingAuthorization $this->generalService->getService(
  680.             'Transaction\\Invoice\\BlingAuthorization'
  681.         );
  682.         $blingToken $this->configuration->get('bling_access');
  683.         $blingCode $this->configuration->get('bling_code');
  684.         if(!empty($blingToken)){
  685.             $blingAuthorization->getTokenAccess($blingCodetrue);
  686.         }
  687.         return $this->eadResponse([ "success" => ErrorEnum::YES ]);
  688.     }
  689.     /**
  690.      * @Route(
  691.      *      path        = "/cron/calculate/anticipation",
  692.      *      name        = "executeCalculateAnticipation",
  693.      *      methods     = {"GET"}
  694.      * )
  695.      */
  696.     public function executeCalculateAnticipation()
  697.     {
  698.         $transactionRepository $this->em->getRepository(Transaction::class);
  699.         $transactionRepository->updateTransactionPaidAndAnticipated();
  700.         return $this->eadResponse([ "success" => ErrorEnum::YES ]);
  701.     }
  702.     /**
  703.      * @Route(
  704.      *      path        = "/cron/ead/checkout/fee/{clientToken}",
  705.      *      name        = "getEADCheckoutFee",
  706.      *      methods     = {"GET"}
  707.      * )
  708.      */
  709.     public function getEADCheckoutFee(Request $request)
  710.     {
  711.         $token $request->headers->get('X-AUTH-TOKEN');
  712.         if($token != $this->generalService->getTokenCron()){
  713.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  714.         }
  715.         if($request->get('clientToken') != $this->clientConfig->getToken()){
  716.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  717.         }
  718.         $receiverRepository $this->em->getRepository(Receiver::class);
  719.         $transactionRepository $this->em->getRepository(Transaction::class);
  720.         $pagarMeReceiver $this->generalService->getService('PagarMe\\PagarMeReceiver');
  721.         $card TransactionEnum::PAYMENT_CARD;
  722.         $bill TransactionEnum::PAYMENT_BILL;
  723.         $pix TransactionEnum::PAYMENT_PIX;
  724.         $date1 $request->get('date1');
  725.         if(!isset($date1) && empty($date1)){
  726.             $date1 date('Y-m-d'strtotime("first day of last month"));
  727.         }  
  728.         $date2 $request->get('date2');
  729.         if(!isset($date2) && empty($date2)){
  730.             $date2 date('Y-m-d'strtotime("last day of last month"));
  731.         }
  732.         $receivers $receiverRepository->findBy([
  733.             "type" => ReceiverEnum::SCHOOL,
  734.             "accountType" => ReceiverEnum::EAD_CHECKOUT
  735.         ]);
  736.         
  737.         $data = [];
  738.         foreach ($receivers as $key => $receiver) {
  739.             $feeCard $transactionRepository->getEADFeePaymentMethod(
  740.                 $receiver->getId(), 
  741.                 $date1
  742.                 $date2
  743.                 $card
  744.             );
  745.             $feeBill $transactionRepository->getEADFeePaymentMethod(
  746.                 $receiver->getId(), 
  747.                 $date1
  748.                 $date2
  749.                 $bill
  750.             );
  751.             $feePix $transactionRepository->getEADFeePaymentMethod(
  752.                 $receiver->getId(), 
  753.                 $date1
  754.                 $date2
  755.                 $pix
  756.             );
  757.             $feeTransfer $pagarMeReceiver->getTransferFee(
  758.                 $receiver->getReceiverHash(), 
  759.                 $date1
  760.                 $date2
  761.             );
  762.             $rData = (object)[
  763.                 "feeCard" => (float)$feeCard,
  764.                 "feeBill" => (float)$feeBill,
  765.                 "feePix" => (float)$feePix,
  766.                 "feeTransfer" => $feeTransfer,
  767.                 "receiverId" => $receiver->getReceiverHash(),
  768.                 "id" => $receiver->getId(),
  769.                 "deleted" => $receiver->isLive() ? ReceiverEnum::NO ReceiverEnum::YES,
  770.             ];
  771.             $data[] = $rData;
  772.         }
  773.         return $this->eadResponse($data);
  774.     }
  775.     /**
  776.      * @Route(
  777.      *      path        = "/cron/delete/nfe/ead/checkout/{code}/{hash}",
  778.      *      name        = "deleteNfeEADCheckout",
  779.      *      methods     = {"GET"}
  780.      * )
  781.      */
  782.     public function deleteNfeEADCheckout()
  783.     {
  784.         $token $request->headers->get('AUTH-TOKEN');
  785.         if($token != $this->generalService->getTokenCron()){
  786.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  787.         }
  788.         $nfeCode $request->get('code');
  789.         $nfeHash $request->get('hash');
  790.         $receiverNfeRepository $this->em->getRepository(ReceiverNfe::class);
  791.         $receiverNfeRepository->deleteNfeEADCheckout($nfeCode$nfeHash);
  792.         $this->em->flush();
  793.         return $this->eadResponse([ "success" => ErrorEnum::YES ]);
  794.     }
  795.     /**
  796.      * @Route(
  797.      *      path        = "/email/queue/{clientToken}",
  798.      *      name        = "executeCronListEmail",
  799.      *      methods     = {"GET"}
  800.      * )
  801.      */
  802.     public function executeEmailQueue(Request $request)
  803.     {
  804.         $token $request->headers->get('AUTH-TOKEN');
  805.         if($token != $this->generalService->getTokenCron()){
  806.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  807.         }
  808.         if($request->get('clientToken') != $this->clientConfig->getToken()){
  809.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  810.         }
  811.         $taskQueueRepository $this->em->getRepository(TaskQueue::class);
  812.         $tasks $taskQueueRepository->getTaskQueue();
  813.         $date date('Y-m-d'strtotime("- 7 day"));
  814.         if($tasks){
  815.             foreach ($tasks as $key => $task) {
  816.                 try{
  817.                     if($this->configuration->checkModuleIsAbleOnPlan('notificationFunction')){
  818.                         $user $task->getUser();
  819.                         if($user->getId() != UserEnum::YES && $user->isLive()){
  820.                             if($task->getDate('Y-m-d') >= $date){
  821.                                 //$taskQueueRepository->executeTask($task);
  822.                             }
  823.                         }
  824.                     }
  825.                     $this->em->remove($task);
  826.                 }catch(Exception $e){
  827.                     $discordService $this->generalService->getService('DiscordService');
  828.                     $discordService->setChannel('debug');
  829.                     $discordService->setMessage("{$this->eadDomain} - {$e->getMessage()}");
  830.                     $discordService->sendDiscord();
  831.                 }
  832.             }
  833.             $this->em->flush();
  834.         }
  835.         if(count($tasks) == ServicesEnum::NO){
  836.             //delete cron
  837.             $cronService $this->generalService->getService('Aws\\AwsEventBridge');
  838.             $cronService->deleteApiDestination(ServicesEnum::CRON_QUEUE);
  839.         }
  840.         return $this->eadResponse([ "success" => ErrorEnum::YES ]);
  841.     }
  842.     /**
  843.      * @Route(
  844.      *      path          = "/webhook/queue/send/{clientToken}",
  845.      *      name          = "sendWebhookQueue",
  846.      *      methods       = {"GET"}
  847.      * )
  848.      */
  849.     public function sendWebhookQueue(Request $request
  850.     {
  851.         $token $request->headers->get('AUTH-TOKEN');
  852.         if($token != $this->generalService->getTokenCron()){
  853.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  854.         }
  855.         if($request->get('clientToken') != $this->clientConfig->getToken()){
  856.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  857.         }
  858.         $webhookQueueRepository $this->em->getRepository(WebhookQueue::class);
  859.         $dataSend $webhookQueueRepository->getWebhookQueue();
  860.         $webhookService $this->generalService->getService('WebhookService');
  861.         foreach ($dataSend as $key => $webhookQueue) {
  862.             $webhookService->sendWebhookQueue($webhookQueue);
  863.         }
  864.         return $this->eadResponse([ "success" => ErrorEnum::YES ]);
  865.     }
  866.     /**
  867.      * @Route(
  868.      *      path          = "/metrics/{token}",
  869.      *      name          = "getMetricsEAD",
  870.      *      methods       = {"GET"}
  871.      * )
  872.      */
  873.     public function getMetricsEAD(Request $request
  874.     {
  875.         $token $request->headers->get('AUTH-TOKEN');
  876.         /*if($token != $this->generalService->getTokenCron()){
  877.             return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
  878.         }
  879.         if($request->get('clientToken') != $this->clientConfig->getToken()){
  880.             return $this->eadResponse(null, ErrorEnum::AUTH_INVALID);
  881.         }*/
  882.         $metricsEadService $this->generalService->getService('MetricsEadService');
  883.         $data $metricsEadService->getMetrics();
  884.         return $this->eadResponse($data);
  885.     }
  886.     /**
  887.      * @Route(
  888.      *      path          = "/remove/cron/{token}",
  889.      *      name          = "removeCron",
  890.      *      methods       = {"GET"}
  891.      * )
  892.      */
  893.     public function removeCron(Request $request
  894.     {
  895.         $token $request->headers->get('AUTH-TOKEN');
  896.         if($token != $this->generalService->getTokenCron()){
  897.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  898.         }
  899.         if($request->get('clientToken') != $this->clientConfig->getToken()){
  900.             return $this->eadResponse(nullErrorEnum::AUTH_INVALID);
  901.         }
  902.         $cronService $this->generalService->getService('Aws\\AwsEventBridge');
  903.         if($cronService->deleteApiDestinationByCronName(ServicesEnum::CRON_GENERAL)){
  904.             return $this->eadResponse([ "success" => ServicesEnum::YES ]);
  905.         }
  906.         return $this->eadResponse([ "error" => ServicesEnum::YES ]);
  907.     }
  908. }