src/Controller/User/VPN/Service/ServiceController.php line 186

Open in your IDE?
  1. <?php
  2. namespace App\Controller\User\VPN\Service;
  3. use App\Entity\Generic\User;
  4. use App\Entity\Telegram\AgentPublicBot\Bot;
  5. use App\Entity\VPN\Service\Plan;
  6. use App\Entity\VPN\Service\Service;
  7. use App\Form\VPN\Service\Service\LimitedOcServType;
  8. use App\Form\VPN\Service\Service\LimitedOpenType;
  9. use App\Form\VPN\Service\Service\LimitedV2rayType;
  10. use App\Form\VPN\Service\Service\LimitedVipType;
  11. use App\Form\VPN\Service\Service\RollbackType;
  12. use App\Form\VPN\Service\Service\UnlimitedOcServType;
  13. use App\Form\VPN\Service\Service\UnlimitedOpenType;
  14. use App\Form\VPN\Service\Service\UnlimitedV2rayType;
  15. use App\Repository\VPN\V2ray\ServerRepository;
  16. use App\Service\TransactionService;
  17. use App\Service\Util\ByteConvert;
  18. use App\Service\Util\DynamicPriceCalculation;
  19. use App\Service\VPN\Service\ServiceService;
  20. use App\ViewModel\VPN\Service\ServiceViewModel;
  21. use Doctrine\ORM\EntityManagerInterface;
  22. use Doctrine\Persistence\ManagerRegistry;
  23. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  24. use Symfony\Component\Form\Extension\Core\Type\TextType;
  25. use Symfony\Component\HttpFoundation\Request;
  26. use Symfony\Component\HttpFoundation\RequestStack;
  27. use Symfony\Component\HttpFoundation\Response;
  28. use Symfony\Component\Routing\Annotation\Route;
  29. #[Route('/panel/user/vpn/service')]
  30. class ServiceController extends AbstractController
  31. {
  32.     public ServiceService $service;
  33.     public ?Request $request;
  34.     public TransactionService $transaction;
  35.     public EntityManagerInterface $em;
  36.     public DynamicPriceCalculation $dynamicPriceCalculation;
  37.     public function __construct(ServiceService $serviceRequestStack $requestStackEntityManagerInterface $emTransactionService $transactionDynamicPriceCalculation $dynamicPriceCalculation)
  38.     {
  39.         $this->dynamicPriceCalculation $dynamicPriceCalculation;
  40.         $this->em $em;
  41.         $this->transaction $transaction;
  42.         $this->service $service;
  43.         $this->request $requestStack->getCurrentRequest();
  44.     }
  45.     #[Route('/'name'app_panel_user_vpn_service_index'methods: ['GET'])]
  46.     public function index(Request $request): Response
  47.     {
  48.         /**
  49.          * @var User $user
  50.          */
  51.         $user $this->getUser();
  52.         if ($user->getConnectedTelegramUserId() === null || $user->getConnectedTelegramUserId() === []) {
  53.             $this->addFlash('error''لطفا ابتدا حساب خود را به تلگرام متصل فرمایید');
  54.             return $this->redirectToRoute('app_user_dashboard');
  55.         }
  56.         $info = new ServiceViewModel($request);
  57.         $data $this->service->getListUser($info$user);
  58.         return $this->render('panel/pages/user/vpn/service/list.html.twig', [
  59.             'paginator' => $data,
  60.             'currentPage' => 'app_panel_user_vpn_service_index',
  61.             'parameters' => $info,
  62.             'filters' => $this->getFilters(),
  63.             'lists' => $this->getLists(),
  64.         ]);
  65.     }
  66.     public function getFilters(): array
  67.     {
  68.         $userBots $this->getDoctrine()->getRepository(Bot::class)->findBy(['active' => 1'owner' => $this->getUser()]);
  69.         $botsList = [];
  70.         $botsList[] = ['name' => 'همه''value' => 'all'];
  71.         foreach ($userBots as $item) {
  72.             $botsList[] = ['name' => $item->getDescription(), 'value' => $item->getId()];
  73.         }
  74.         return [
  75.             [
  76.                 'name' => 'clientId',
  77.                 'type' => 'text',
  78.                 'label' => 'شناسه سرویس',
  79.                 'class' => '',
  80.                 'value' => $this->request->get('clientId')
  81.             ],
  82.             [
  83.                 'name' => 'username',
  84.                 'type' => 'text',
  85.                 'label' => 'نام کاربری',
  86.                 'class' => '',
  87.                 'value' => $this->request->get('username')
  88.             ],
  89.             [
  90.                 'name' => 'botId',
  91.                 'type' => 'radio',
  92.                 'label' => 'ربات تلگرام',
  93.                 'class' => '',
  94.                 'radio' => $botsList,
  95.                 'value' => $this->request->get('botId')
  96.             ],
  97.             [
  98.                 'name' => 'active',
  99.                 'type' => 'radio',
  100.                 'label' => 'وضعیت',
  101.                 'class' => '',
  102.                 'radio' => [
  103.                     ['name' => 'همه''value' => 'all'],
  104.                     ['name' => 'فعال''value' => 'true'],
  105.                     ['name' => 'غیرفعال''value' => 'false'],
  106.                 ],
  107.                 'value' => $this->request->get('active')
  108.             ],
  109.             [
  110.                 'name' => 'serviceType',
  111.                 'type' => 'radio',
  112.                 'label' => 'نوع سرویس',
  113.                 'class' => '',
  114.                 'radio' => [
  115.                     ['name' => 'همه''value' => 'all'],
  116.                     ['name' => 'حجمی''value' => 'sized'],
  117.                     ['name' => 'نامحدود''value' => 'unlimited'],
  118.                 ],
  119.                 'value' => $this->request->get('serviceType')
  120.             ],
  121.             [
  122.                 'name' => 'protocol',
  123.                 'type' => 'radio',
  124.                 'label' => 'نوع پروتکل',
  125.                 'class' => '',
  126.                 'radio' => [
  127.                     ['name' => 'همه''value' => 'all'],
  128.                     ['name' => 'V2ray''value' => 'v2ray'],
  129.                     ['name' => 'OpenVPN''value' => 'open'],
  130.                     ['name' => 'Cisco''value' => 'ocserv'],
  131.                     ['name' => 'VIP مولتی''value' => 'vip'],
  132.                 ],
  133.                 'value' => $this->request->get('protocol')
  134.             ],
  135.         ];
  136.     }
  137.     public function getLists(): array
  138.     {
  139.         $array = [
  140.             [
  141.                 'name' => 'v1ListService',
  142.                 'label' => 'سرویس',
  143.                 'class' => '',
  144.                 'type' => 'serviceDetail',
  145.                 'mobile' => true
  146.             ],
  147.             [
  148.                 'name' => 'v2InfoService',
  149.                 'label' => 'اطلاعات دسترسی',
  150.                 'class' => '',
  151.                 'type' => 'serviceSubDetail',
  152.                 'withoutPassword' => 'app_vpn_service_panel_no_password',
  153.                 'withPassword' => 'app_vpn_service_panel_no_password',
  154.                 'mobile' => true,
  155.                 'charge' => 'app_panel_user_vpn_service_charge',
  156. //                'rollback' => 'app_panel_user_vpn_service_rollback',
  157.                 'status' => 'app_panel_user_vpn_service_status',
  158.                 'disableHourly' => 'app_panel_user_vpn_service_index',
  159.                 'enableHourly' => 'app_panel_user_vpn_service_index',
  160.                 'username' => 'app_panel_user_vpn_service_edit'
  161.             ],
  162.         ];
  163.         return $array;
  164.     }
  165.     #[Route('/new'name'app_panel_user_vpn_service_new'methods: ['GET''POST'])]
  166.     public function new(Request $requestByteConvert $byteConvertServerRepository $serverRepository\App\Repository\VPN\OpenVPN\ServerRepository $openServerREpo\App\Repository\VPN\OcServ\ServerRepository $ocServerRepository): Response
  167.     {
  168.         /**
  169.          * @var User $user
  170.          */
  171.         $user $this->getUser();
  172.         /**
  173.          * @var User $user
  174.          */
  175.         $user $this->getUser();
  176.         if ($user->getConnectedTelegramUserId() === null || $user->getConnectedTelegramUserId() === []) {
  177.             $this->addFlash('error''لطفا ابتدا حساب خود را به تلگرام متصل فرمایید');
  178.             return $this->redirectToRoute('app_user_dashboard');
  179.         }
  180.         $formTypes = [
  181.             'sizedVip' => LimitedVipType::class,
  182.             'sizedV2ray' => LimitedV2rayType::class,
  183.             'unlimitedV2ray' => UnlimitedV2rayType::class,
  184.             'sizedOcServ' => LimitedOcServType::class,
  185.             'unlimitedOcServ' => UnlimitedOcServType::class,
  186.             'sizedOpen' => LimitedOpenType::class,
  187.             'unlimitedOpen' => UnlimitedOpenType::class,
  188.         ];
  189.         $forms = [];
  190.         foreach ($formTypes as $formName => $formClass) {
  191.             switch ($formName) {
  192.                 case 'unlimitedV2ray':
  193.                     $locations = [];
  194.                     foreach ($serverRepository->findBy(['active' => 1]) as $server) {
  195.                         $locations[$this->countryCodeToFlag($server->getCountry()->getCode()) . $server->getCountry()->getTitle()] = $server->getCountry()->getCode();
  196.                     }
  197.                     $form $this->createForm($formClassnull, [
  198.                         'clientId' => $this->service->getFreeClientId(),
  199.                         'locations' => $locations
  200.                     ]);
  201.                     break;
  202.                 case 'unlimitedOcServ':
  203.                     $locations = [];
  204.                     foreach ($ocServerRepository->findBy(['active' => 1]) as $server) {
  205.                         $locations[$this->countryCodeToFlag($server->getCountry()->getCode()) . $server->getCountry()->getTitle()] = $server->getCountry()->getCode();
  206.                     }
  207.                     $form $this->createForm($formClassnull, [
  208.                         'clientId' => $this->service->getFreeClientId(),
  209.                         'locations' => $locations
  210.                     ]);
  211.                     break;
  212.                 case 'unlimitedOpen':
  213.                     $locations = [];
  214.                     foreach ($openServerREpo->findBy(['active' => 1]) as $server) {
  215.                         $locations[$this->countryCodeToFlag($server->getCountry()->getCode()) . $server->getCountry()->getTitle()] = $server->getCountry()->getCode();
  216.                     }
  217.                     $form $this->createForm($formClassnull, [
  218.                         'clientId' => $this->service->getFreeClientId(),
  219.                         'locations' => $locations
  220.                     ]);
  221.                     break;
  222.                 case 'sizedV2ray':
  223.                 case 'sizedOpen':
  224.                 case 'sizedOcServ':
  225.                 case 'sizedVip':
  226.                     $form $this->createForm($formClassnull, [
  227.                         'clientId' => $this->service->getFreeClientId()
  228.                     ]);
  229.                     break;
  230.             }
  231.             $form->handleRequest($request);
  232.             switch ($formName) {
  233.                 case 'sizedVip':
  234.                 case 'sizedV2ray':
  235.                 case 'unlimitedV2ray':
  236.                 case 'sizedOcServ':
  237.                 case 'unlimitedOcServ':
  238.                 case 'sizedOpen':
  239.                 case 'unlimitedOpen':
  240.                     if ($form->isSubmitted() && $form->isValid()) {
  241.                         $queryArray $form->getData();
  242.                         unset($queryArray['username']);
  243.                         unset($queryArray['password']);
  244.                         $queryArray['size'] = $byteConvert->toByte($queryArray['size'] . 'GB');
  245.                         $queryArray['active'] = 1;
  246.                         $targetPlan $this->em->getRepository(Plan::class)->findOneBy($queryArray);
  247.                         if (!$targetPlan) {
  248.                             $this->addFlash('error''این بسته در حال حاضر ارائه نمیشود');
  249.                             return $this->redirectToRoute('app_panel_user_vpn_service_new');
  250.                         }
  251. //                        var_dump($queryArray);die;
  252. //                      TODO:Check User Interest Rate For Price
  253. //                        $price = $targetPlan->getPrice();
  254.                         $price $this->dynamicPriceCalculation->calculatePrice($user$targetPlan);
  255.                         $allBalance $user->getWallet() + $user->getGiftWallet();
  256.                         if ($allBalance >= $price){
  257.                             if ($user->getWallet() < $price) {
  258.                                 $neededPrice $price $user->getWallet();
  259.                                 $user->setGiftWallet($user->getGiftWallet() - $neededPrice);
  260.                                 $this->transaction->createTransaction($user$neededPrice,
  261.                                     "دریافت مبلغ از کیف پول هدیه"
  262.                                     10null0null'gift');
  263.                             }
  264.                             $serviceData $form->getData();
  265.                             $serviceData['clientId'] = $form->get('clientId')->getData();
  266.                             if ($form->has('country')) {
  267. //                                var_dump($form->get('country')->getData());die;
  268.                                 $country $form->get('country')->getData() ?: null;
  269.                             } else {
  270.                                 $country 'all';
  271.                             }
  272.                             $service $this->service->createService($targetPlan$serviceData$user$country);
  273.                             $this->transaction->createTransaction($user$price,
  274.                                 "خرید سرویس جدید {$service->getClientId()}"
  275.                                 00);
  276.                             $this->addFlash('success''سرویس مد نظر با موفقیت ثبت شد');
  277.                             return $this->redirectToRoute('app_panel_user_vpn_service_index');
  278.                         }else {
  279.                             $this->addFlash('error''موجودی کیف پول شما با جمع کیف پول هدیه کافی نمی باشد');
  280.                             return $this->redirectToRoute('app_panel_user_vpn_service_new');
  281.                         }
  282.                     }
  283.                     break;
  284.                 default:
  285.                     // Handle any default case if necessary
  286.                     break;
  287.             }
  288.             $forms[$formName] = $form->createView();
  289.         }
  290.         return $this->render('panel/pages/user/vpn/service/enter.html.twig', [
  291.             'sizedVipForm' => $forms['sizedVip'] ?? '',
  292.             'sizedV2rayForm' => $forms['sizedV2ray'] ?? '',
  293.             'unlimitedV2rayForm' => $forms['unlimitedV2ray'] ?? '',
  294.             'sizedOcServForm' => $forms['sizedOcServ'] ?? '',
  295.             'unlimitedOcServForm' => $forms['unlimitedOcServ'] ?? '',
  296.             'sizedOpenForm' => $forms['sizedOpen'] ?? '',
  297.             'unlimitedOpenForm' => $forms['unlimitedOpen'] ?? '',
  298.         ]);
  299.     }
  300.     #[Route('/charge/{id}'name'app_panel_user_vpn_service_charge'methods: ['GET''POST'])]
  301.     public function charge(Request $requestByteConvert $byteConvertServerRepository $serverRepository\App\Repository\VPN\OpenVPN\ServerRepository $openServerREpo\App\Repository\VPN\OcServ\ServerRepository $ocServerRepositoryService $service)
  302.     {
  303.         /**
  304.          * @var User $user
  305.          */
  306.         $user $this->getUser();
  307. //        var_dump($user->getWallet());die;
  308.         $formTypes = [
  309.             'sizedVip' => LimitedVipType::class,
  310.             'sizedV2ray' => LimitedV2rayType::class,
  311.             'unlimitedV2ray' => UnlimitedV2rayType::class,
  312.             'sizedOcServ' => LimitedOcServType::class,
  313.             'unlimitedOcServ' => UnlimitedOcServType::class,
  314.             'sizedOpen' => LimitedOpenType::class,
  315.             'unlimitedOpen' => UnlimitedOpenType::class,
  316.         ];
  317.         $forms = [];
  318.         foreach ($formTypes as $formName => $formClass) {
  319.             switch ($formName) {
  320.                 case 'unlimitedV2ray':
  321.                     $locations = [];
  322.                     foreach ($serverRepository->findBy(['active' => 1]) as $server) {
  323.                         $locations[$this->countryCodeToFlag($server->getCountry()->getCode()) . $server->getCountry()->getTitle()] = $server->getCountry()->getCode();
  324.                     }
  325.                     $form $this->createForm($formClassnull, [
  326.                         'clientId' => $service->getClientId(),
  327.                         'locations' => $locations
  328.                     ]);
  329.                     break;
  330.                 case 'unlimitedOcServ':
  331.                     $locations = [];
  332.                     foreach ($ocServerRepository->findBy(['active' => 1]) as $server) {
  333.                         $locations[$this->countryCodeToFlag($server->getCountry()->getCode()) . $server->getCountry()->getTitle()] = $server->getCountry()->getCode();
  334.                     }
  335.                     $form $this->createForm($formClassnull, [
  336.                         'clientId' => $service->getClientId(),
  337.                         'locations' => $locations
  338.                     ]);
  339.                     break;
  340.                 case 'unlimitedOpen':
  341.                     $locations = [];
  342.                     foreach ($openServerREpo->findBy(['active' => 1]) as $server) {
  343.                         $locations[$this->countryCodeToFlag($server->getCountry()->getCode()) . $server->getCountry()->getTitle()] = $server->getCountry()->getCode();
  344.                     }
  345.                     $form $this->createForm($formClassnull, [
  346.                         'clientId' => $service->getClientId(),
  347.                         'locations' => $locations
  348.                     ]);
  349.                     break;
  350.                 case 'sizedV2ray':
  351.                 case 'sizedOpen':
  352.                 case 'sizedOcServ':
  353.                 case 'sizedVip':
  354.                     $form $this->createForm($formClassnull, [
  355.                         'clientId' => $service->getClientId(),
  356.                     ]);
  357.                     break;
  358.             }
  359.             $form->remove('username');
  360.             $form->remove('password');
  361.             $form->remove('note');
  362.             $form->handleRequest($request);
  363.             switch ($formName) {
  364.                 case 'sizedV2ray':
  365.                 case 'sizedVip':
  366.                 case 'unlimitedV2ray':
  367.                 case 'sizedOcServ':
  368.                 case 'unlimitedOcServ':
  369.                 case 'sizedOpen':
  370.                 case 'unlimitedOpen':
  371.                     if ($form->isSubmitted() && $form->isValid()) {
  372.                         $queryArray $form->getData();
  373. //                        unset($queryArray['username']);
  374. //                        unset($queryArray['password']);
  375.                         $queryArray['size'] = $byteConvert->toByte($queryArray['size'] . 'GB');
  376.                         $queryArray['active'] = 1;
  377.                         $targetPlan $this->em->getRepository(Plan::class)->findOneBy($queryArray);
  378.                         if (!$targetPlan) {
  379.                             $this->addFlash('error''این بسته در حال حاضر ارائه نمیشود');
  380.                             return $this->redirectToRoute('app_panel_user_vpn_service_charge', ['id' => $service->getId()]);
  381.                         }
  382. //                      TODO:Check User Interest Rate For Price
  383.                         $buyPrice $this->dynamicPriceCalculation->calculatePrice($user$targetPlan);
  384.                         if ($user->getWallet() >= $buyPrice) {
  385.                             $serviceData $form->getData();
  386.                             $serviceData['clientId'] = $form->get('clientId')->getData();
  387.                             $this->service->chargeService($service$targetPlan$serviceData$user);
  388.                             $this->transaction->createTransaction($user$buyPrice"تمدید سرویس {$service->getClientId()}",
  389.                                 0
  390.                             );
  391.                             $this->addFlash('success''سرویس مد نظر با موفقیت تمدید شد');
  392.                             return $this->redirectToRoute('app_panel_user_vpn_service_index');
  393.                         } else {
  394.                             $this->addFlash('error''موجودی کیف پول شما کافی نمی باشد');
  395.                             return $this->redirectToRoute('app_panel_user_vpn_service_charge', ['id' => $service->getId()]);
  396.                         }
  397.                     }
  398.                     break;
  399.                 default:
  400.                     // Handle any default case if necessary
  401.                     break;
  402.             }
  403.             $forms[$formName] = $form->createView();
  404.         }
  405.         return $this->render('panel/pages/user/vpn/service/enter.html.twig', [
  406.             'sizedVipForm' => $forms['sizedVip'] ?? '',
  407.             'sizedV2rayForm' => $forms['sizedV2ray'] ?? '',
  408.             'unlimitedV2rayForm' => $forms['unlimitedV2ray'] ?? '',
  409.             'sizedOcServForm' => $forms['sizedOcServ'] ?? '',
  410.             'unlimitedOcServForm' => $forms['unlimitedOcServ'] ?? '',
  411.             'sizedOpenForm' => $forms['sizedOpen'] ?? '',
  412.             'unlimitedOpenForm' => $forms['unlimitedOpen'] ?? '',
  413.             'charge' => 1
  414.         ]);
  415.     }
  416.     #[Route('/edit/{id}'name'app_panel_user_vpn_service_edit'methods: ['GET''POST'])]
  417.     public function edit(Request $requestByteConvert $byteConvertServerRepository $serverRepository\App\Repository\VPN\OpenVPN\ServerRepository $openServerREpo\App\Repository\VPN\OcServ\ServerRepository $ocServerRepositoryService $service)
  418.     {
  419.         /**
  420.          * @var User $user
  421.          */
  422.         $user $this->getUser();
  423.         $form $this->createFormBuilder()
  424.             ->add('username'TextType::class, [
  425.                 'label' => 'نام کاربری',
  426.                 'data' => $service->getUsername()
  427.             ])->getForm();
  428.         $form->handleRequest($request);
  429.         if ($form->isSubmitted() && $form->isValid()) {
  430.             $service->setUsername($form->get('username')->getData());
  431.             $this->em->flush();
  432.             $this->addFlash('success''بروز شد');
  433.             return $this->redirectToRoute('app_panel_user_vpn_service_index');
  434.         }
  435.         return $this->render('panel/pages/user/vpn/service/edit.html.twig', [
  436.             'form' => $form->createView()
  437.         ]);
  438.     }
  439.     #[Route('/status/{id}'name'app_panel_user_vpn_service_status'methods: ['GET''POST'])]
  440.     public function changeStatus(Service $service)
  441.     {
  442.         if (!$service->isActive()) {
  443.             $this->addFlash('error''سرویس به پایان رسیده است نمیتواند وضعیتش تغییر پیدا کند');
  444.             return $this->redirectToRoute('app_panel_user_vpn_service_index');
  445.         }
  446.         $service->setIsEnabled(!$service->isEnabled());
  447.         $this->em->persist($service);
  448.         $this->em->flush();
  449.         return $this->redirectToRoute('app_panel_user_vpn_service_index');
  450.     }
  451.     #[Route('/rollback/{id}'name'app_panel_user_vpn_service_rollback'methods: ['GET''POST'])]
  452.     public function rollback(Service $serviceRequest $request)
  453.     {
  454.         $form $this->createForm(RollbackType::class);
  455.         $form->handleRequest($request);
  456.         if ($form->isSubmitted() && $form->isValid()) {
  457.             $service->setActive(0);
  458.             $service->setRollbackNote($form->get('reason')->getData());
  459.             $this->transaction->createTransaction($service->getOwner(), $service->getTotalPrice(), 1'مرجوع سرویس با شناسه : ' $service->getClientId(), $service'rollback'0);
  460.             $this->addFlash('success''با موفقیت انجام شد');
  461.             return $this->redirectToRoute('app_panel_user_vpn_service_index');
  462.         }
  463.         return $this->render('panel/pages/user/vpn/service/rollback.html.twig', [
  464.             'form' => $form->createView(),
  465.             'rollback' => 1
  466.         ]);
  467.     }
  468.     #[Route('/get-price-ajax'name'app_panel_user_vpn_service_get_price_ajax'methods: ['GET''POST'])]
  469.     public function getPriceAjax(ByteConvert $byteConvertRequest $request)
  470.     {
  471.         /**
  472.          * @var User $user
  473.          */
  474.         $user $this->getUser();
  475.         $queryArray $request->request->all();
  476.         unset($queryArray['country']);
  477.         unset($queryArray['password']);
  478.         unset($queryArray['username']);
  479.         unset($queryArray['price']);
  480.         unset($queryArray['_token']);
  481.         $queryArray['size'] = $byteConvert->toByte($queryArray['size'] . 'GB');
  482.         $queryArray['active'] = 1;
  483.         $targetPlan $this->em->getRepository(Plan::class)->findOneBy($queryArray);
  484. //        return $this->json(['res' => $queryArray]);
  485.         if (!$targetPlan) {
  486.             return $this->json(['message' => 'این بسته در حال حاضر ارائه نمیشود']);
  487.         } else {
  488.             if ($targetPlan->getServiceType() === 'unlimited') {
  489.                 $price $this->dynamicPriceCalculation->calculatePrice($user$targetPlan);
  490.                 return $this->json(['message' =>
  491.                     'با احتساب نمایندگی سطح ' .
  492.                     $this->dynamicPriceCalculation->getUserLevel($user$targetPlan)
  493.                     .
  494.                     ' شما قیمت : ' .
  495.                     number_format($price) .
  496.                     ' تومان'
  497.                 ]);
  498.             } else {
  499.                 $price $this->dynamicPriceCalculation->calculatePrice($user$targetPlan);
  500.                 return $this->json(['message' =>
  501.                     'با احتساب نمایندگی سطح ' .
  502.                     $this->dynamicPriceCalculation->getUserLevel($user$targetPlan)
  503.                     .
  504.                     ' شما قیمت از ' .
  505.                     number_format($targetPlan->getPrice()) . ' تومان' .
  506.                     ' به ' .
  507.                     number_format($price) .
  508.                     ' تومان' .
  509.                     ' کاهش یافت'
  510.                 ]);
  511.             }
  512.         }
  513.     }
  514.     public function countryCodeToFlag($countryCode)
  515.     {
  516.         // Convert country code to uppercase
  517.         $countryCode strtoupper($countryCode);
  518.         // Offset between uppercase ASCII and regional indicator symbols
  519.         $offset 127397;
  520.         // Convert each character of the country code to its flag emoji equivalent
  521.         $flagEmoji '';
  522.         for ($i 0$i strlen($countryCode); $i++) {
  523.             $flagEmoji .= $this->emoji_convert_unicode(ord($countryCode[$i]) + $offset);
  524.         }
  525.         return $flagEmoji;
  526.     }
  527. // Function to convert Unicode code point to emoji character
  528.     public function emoji_convert_unicode($unicode)
  529.     {
  530.         return mb_convert_encoding('&#' intval($unicode) . ';''UTF-8''HTML-ENTITIES');
  531.     }
  532. }