src/Controller/Cronjob/Panel/PanelCronController.php line 47

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Cronjob\Panel;
  3. use App\DependencyInjection\jDateTime;
  4. use App\DependencyInjection\JDF;
  5. use App\Entity\Analytics;
  6. use App\Repository\AnalyticsRepository;
  7. use App\Repository\Generic\UserRepository;
  8. use App\Repository\Telegram\Public\TelegramPaymentRepository;
  9. use App\Repository\TransactionRepository;
  10. use App\Repository\VPN\Service\ServiceRepository;
  11. use App\Service\SettingService;
  12. use App\Service\TransactionService;
  13. use App\Service\Util\NotificationService;
  14. use DateTime;
  15. use DateTimeImmutable;
  16. use Doctrine\ORM\EntityManagerInterface;
  17. use Exception;
  18. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  19. use Symfony\Component\DomCrawler\Crawler;
  20. use Symfony\Component\HttpFoundation\JsonResponse;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\HttpFoundation\RequestStack;
  23. use Symfony\Component\Routing\Annotation\Route;
  24. use Symfony\Contracts\HttpClient\HttpClientInterface;
  25. class PanelCronController extends AbstractController
  26. {
  27.     public TransactionService $service;
  28.     public \App\Service\Util\Telegram $telegram;
  29.     public ?Request $request;
  30.     private $client;
  31.     private EntityManagerInterface $entityManager;
  32.     public function __construct(\App\Service\Util\Telegram $telegramTransactionService $serviceRequestStack $requestStackHttpClientInterface $clientEntityManagerInterface $em, private HttpClientInterface $clientProcessor)
  33.     {
  34.         $this->service $service;
  35.         $this->request $requestStack->getCurrentRequest();
  36.         $this->client $client;
  37.         $this->entityManager $em;
  38.         $this->telegram $telegram;
  39.     }
  40.     #[Route('/cronjob/panel/dollar/cron'name'app_cronjob_panel_dollar')]
  41.     public function dollar(NotificationService $notificationService): JsonResponse
  42.     {
  43.         $haveError false;
  44.         try {
  45.             $ch curl_init();
  46.             curl_setopt($chCURLOPT_URL'https://api-v2.arzinja.app/api/v1/market/all-market?page=1&per_page=1&base_asset=TRX&provider_type=otc');
  47.             curl_setopt($chCURLOPT_RETURNTRANSFER1);
  48.             curl_setopt($chCURLOPT_CUSTOMREQUEST'GET');
  49.             $headers = array();
  50.             $headers[] = 'Accept: application/json, text/plain, */*';
  51.             $headers[] = 'Accept-Language: en-US,en;q=0.9,fa-IR;q=0.8,fa;q=0.7';
  52.             $headers[] = 'Dnt: 1';
  53.             $headers[] = 'Origin: https://arzinja.info';
  54.             $headers[] = 'Priority: u=1, i';
  55.             $headers[] = 'Referer: https://arzinja.info/';
  56.             $headers[] = 'Sec-Ch-Ua: \"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"';
  57.             $headers[] = 'Sec-Ch-Ua-Mobile: ?0';
  58.             $headers[] = 'Sec-Ch-Ua-Platform: \"macOS\"';
  59.             $headers[] = 'Sec-Fetch-Dest: empty';
  60.             $headers[] = 'Sec-Fetch-Mode: cors';
  61.             $headers[] = 'Sec-Fetch-Site: cross-site';
  62.             $headers[] = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36';
  63.             curl_setopt($chCURLOPT_HTTPHEADER$headers);
  64.             $tronNewData curl_exec($ch);
  65.             curl_close($ch);
  66.             $tronNewDataJson $tronNewData;
  67.             $tronDataArray json_decode($tronNewDataJsontrue);
  68.             if ($tronDataArray['success']){
  69.                 $tronSellPrice $tronDataArray['result'][0]['TRXIRT']['stats']['lastPrice'];
  70.                 $tronBuyPrice $tronDataArray['result'][0]['TRXIRT']['stats']['lastPrice'];
  71.                 $settingObject = new SettingService($this->entityManager);
  72.                 $settingObject->updateSetting('tron_buy'$tronBuyPrice);
  73.                 $settingObject->updateSetting('tron_sell'$tronSellPrice);
  74.             }
  75.             $ch curl_init();
  76.             curl_setopt($chCURLOPT_URL'https://api-v2.arzinja.app/api/v1/market/all-market?page=1&per_page=1&base_asset=usdt&provider_type=otc');
  77.             curl_setopt($chCURLOPT_RETURNTRANSFER1);
  78.             curl_setopt($chCURLOPT_CUSTOMREQUEST'GET');
  79.             $headers = array();
  80.             $headers[] = 'Accept: application/json, text/plain, */*';
  81.             $headers[] = 'Accept-Language: en-US,en;q=0.9,fa-IR;q=0.8,fa;q=0.7';
  82.             $headers[] = 'Dnt: 1';
  83.             $headers[] = 'Origin: https://arzinja.info';
  84.             $headers[] = 'Priority: u=1, i';
  85.             $headers[] = 'Referer: https://arzinja.info/';
  86.             $headers[] = 'Sec-Ch-Ua: \"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"';
  87.             $headers[] = 'Sec-Ch-Ua-Mobile: ?0';
  88.             $headers[] = 'Sec-Ch-Ua-Platform: \"macOS\"';
  89.             $headers[] = 'Sec-Fetch-Dest: empty';
  90.             $headers[] = 'Sec-Fetch-Mode: cors';
  91.             $headers[] = 'Sec-Fetch-Site: cross-site';
  92.             $headers[] = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36';
  93.             curl_setopt($chCURLOPT_HTTPHEADER$headers);
  94.             $tronNewData curl_exec($ch);
  95.             curl_close($ch);
  96.             $tronNewDataJson $tronNewData;
  97.             $tronDataArray json_decode($tronNewDataJsontrue);
  98.             if ($tronDataArray['success']){
  99.                 $tronSellPrice $tronDataArray['result'][0]['USDTIRT']['stats']['lastPrice'];
  100.                 $tronBuyPrice $tronDataArray['result'][0]['USDTIRT']['stats']['lastPrice'];
  101.                 $settingObject = new SettingService($this->entityManager);
  102.                 $settingObject->updateSetting('usdt_buy'$tronBuyPrice);
  103.                 $settingObject->updateSetting('usdt_sell'$tronSellPrice);
  104.             }
  105. //            $settingObject = new SettingService($this->entityManager);
  106. //            $settingObject->updateSetting('usd_buy', $buyPrice);
  107. //            $settingObject->updateSetting('usd', $buyPrice);
  108. //            $settingObject->updateSetting('usd_sell', $sellPrice);
  109. //            var_dump($sellPrice);die;
  110.         } catch (Exception $exception) {
  111.             $notificationService->exception($exception);
  112.             $haveError true;
  113.         }
  114.         if (!$haveError) {
  115.         }
  116.         return $this->json(['res' => true]);
  117.     }
  118.     #[Route('/cronjob/panel/analytics'name'app_cronjob_panel_analytics')]
  119.     public function analytics(ServiceRepository $serviceRepository AnalyticsRepository $analyticsRepository,  TransactionRepository $transactionRepository): JsonResponse
  120.     {
  121. //        For Main Panel
  122.         $haveError false;
  123. //        try {
  124.             $now = new DateTime(); // Get the current date
  125.             // Loop through the last 30 days
  126.             for ($i 0$i <= 3$i++) {
  127.                 // Subtract $i days from today
  128.                 $currentDate = clone $now// Clone to avoid modifying the original $now
  129.                 $currentDate->modify('-' $i ' day'); // Modify the date by subtracting $i days
  130.                 // Check if an analytics record exists for the current date
  131.                 $analyticsObject $analyticsRepository->findOneBy(['date' => $currentDate]);
  132.                 if (!$analyticsObject) {
  133.                     $analyticsObject = new Analytics();
  134.                     $analyticsObject->setDate($currentDate);
  135.                 }
  136.                 // Get the required data for the current date
  137.                 $increaseValue $transactionRepository->getIncreaseForDate($currentDate);
  138.                 $boughtVolume $transactionRepository->getBoughtVolume($currentDate);
  139.                 $totalBought 0;
  140.                 // Set the analytics data for the current date
  141.                 $analyticsObject->setVip($serviceRepository->getTotalSellForDateCount($currentDate 'sized' 'vip'));
  142.                 $analyticsObject->setOcServ($serviceRepository->getTotalSellForDateCount($currentDate 'sized' 'ocserv'));
  143.                 $analyticsObject->setOcServUnlimited($serviceRepository->getTotalSellForDateCount($currentDate 'unlimited' 'ocserv'));
  144.                 $analyticsObject->setV2ray($serviceRepository->getTotalSellForDateCount($currentDate 'sized' 'v2ray'));
  145.                 $analyticsObject->setV2rayUnlimited($serviceRepository->getTotalSellForDateCount($currentDate 'unlimited' 'v2ray'));
  146.                 $analyticsObject->setOpen($serviceRepository->getTotalSellForDateCount($currentDate 'sized' 'open'));
  147.                 $analyticsObject->setOpenUnlimited($serviceRepository->getTotalSellForDateCount($currentDate 'unlimited' 'open'));
  148.                 $analyticsObject->setBoughtVolume($boughtVolume);
  149.                 // Calculate total bought volume for the current date
  150.                 $totalBought += $analyticsObject->getVip();
  151.                 $totalBought += $analyticsObject->getV2ray();
  152.                 $totalBought += $analyticsObject->getV2rayUnlimited();
  153.                 $totalBought += $analyticsObject->getOpen();
  154.                 $totalBought += $analyticsObject->getOpenUnlimited();
  155.                 $totalBought += $analyticsObject->getOcServ();
  156.                 $totalBought += $analyticsObject->getOcServUnlimited();
  157.                 $analyticsObject->setBoughtService($totalBought);
  158.                 $analyticsObject->setWalletIncrease($increaseValue);
  159.                 // Persist the analytics data for the current date
  160.                 $this->entityManager->persist($analyticsObject);
  161.             }
  162.             // Flush all persisted data at once after the loop
  163.             $this->entityManager->flush();
  164.             $this->entityManager->clear(); // Clear to free memory after flush
  165. //        } catch (Exception $exception) {
  166. //            $haveError = true;
  167. //        }
  168. // Return success response
  169.         return $this->json(['res' => true]);
  170.     }
  171.     #[Route('/cronjob/panel/user'name'app_cronjob_panel_user')]
  172.     public function app_cronjob_panel_user(NotificationService $notificationService ServiceRepository $serviceRepository ,EntityManagerInterface $entityManager,  UserRepository $userRepository,  TransactionRepository $transactionRepository): JsonResponse
  173.     {
  174.         try {
  175.             $jdf = new JDF();
  176.             $monthNumber = (int)$jdf->trNum($jdf->date('m'));
  177.             $startJalali '1404/' $monthNumber '/1';
  178.             $endJalali '1404/' $monthNumber '/' $jdf->trNum($jdf->date('t''''fa'$monthNumber));
  179.             $startDateTime $jdf->jalaliToGregorian(explode('/'$startJalali)[0], explode('/'$startJalali)[1], explode('/'$startJalali)[2])[0] . '-' $jdf->jalaliToGregorian(explode('/'$startJalali)[0], explode('/'$startJalali)[1], explode('/'$startJalali)[2])[1] . '-' $jdf->jalaliToGregorian(explode('/'$startJalali)[0], explode('/'$startJalali)[1], explode('/'$startJalali)[2])[2] . ' 00:00:00';
  180.             $startDateTime = new \DateTime($startDateTime);
  181.             $endDateTime $jdf->jalaliToGregorian(explode('/'$endJalali)[0], explode('/'$endJalali)[1], explode('/'$endJalali)[2])[0] . '-' $jdf->jalaliToGregorian(explode('/'$endJalali)[0], explode('/'$endJalali)[1], explode('/'$endJalali)[2])[1] . '-' $jdf->jalaliToGregorian(explode('/'$endJalali)[0], explode('/'$endJalali)[1], explode('/'$endJalali)[2])[2] . ' 00:00:00';
  182.             $endDateTime = new \DateTime($endDateTime);
  183.             foreach ($userRepository->findBy(['deletedAt' => null'active' => 1]) as $user) {
  184.                 $sum $transactionRepository->getUserMonthCharge($user$startDateTime$endDateTime);
  185.                 $user->setThisMonthCharge($sum);
  186.                 $dates = [
  187.                     $serviceRepository->findOneBy(['owner' => $user'isEnabled' => 1], ['createdAt' => 'DESC'])?->getCreatedAt()->format('Y-m-d H:i:s'),
  188.                 ];
  189.                 $lastBuyString date("Y-m-j H:i:s"max(array_map('strtotime'$dates)));
  190.                 $user->setLastBuy(new DateTimeImmutable($lastBuyString));
  191.                 $user->setVpnServicesCount(count($serviceRepository->findBy(['owner' => $user'isEnabled' => 1], ['createdAt' => 'DESC'])));
  192.                 $this->entityManager->flush();
  193.             }
  194.             $this->entityManager->flush();
  195.             $this->entityManager->clear();
  196.         } catch (Exception $exception) {
  197.             $notificationService->exception($exception);
  198. //            $this->telegram->exception($exception);
  199.         }
  200.         return $this->json(['res' => true]);
  201.     }
  202. }