<?php
namespace App\Controller\Telegram\AgentPublicBot;
use App\DependencyInjection\JDF;
use App\Entity\Generic\User;
use App\Entity\Telegram\AgentPublicBot\Bot;
use App\Entity\Telegram\AgentPublicBot\BotAnalytics;
use App\Entity\Telegram\AgentPublicBot\BotNotification;
use App\Entity\Telegram\AgentPublicBot\BotPlan;
use App\Entity\Telegram\AgentPublicBot\BotTransaction;
use App\Entity\Telegram\AgentPublicBot\BotUser;
use App\Entity\VPN\Service\Plan;
use App\Form\Telegram\BotAdsFormType;
use App\Form\Telegram\BotInfoType;
use App\Form\UserChargeAdminType;
use App\Repository\Domains\DomainRepository;
use App\Repository\Telegram\AgentPublicBot\BotAnalyticsRepository;
use App\Repository\Telegram\AgentPublicBot\BotPlanRepository;
use App\Repository\Telegram\AgentPublicBot\BotRepository;
use App\Repository\Telegram\UserRepository;
use App\Repository\VPN\Service\ServiceRepository;
use App\Service\SettingService;
use App\Service\Telegram\AgentPublicBot\BotCampaignService;
use App\Service\Telegram\AgentPublicBot\BotService;
use App\Service\Telegram\AgentPublicBot\BotUserService;
use App\Service\TransactionService;
use App\Service\Util\DynamicPriceCalculation;
use App\Service\Util\NotificationService;
use App\Service\Util\Telegram;
use App\ViewModel\Telegram\AgentPublicBot\BotCampaignViewModel;
use App\ViewModel\Telegram\AgentPublicBot\BotUserViewModel;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Notifier\Notification\Notification;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Constraints\LessThanOrEqual;
#[IsGranted('ROLE_USER')]
#[Route('/telegram/agent-public-bot/management/{botId}')]
class ManagementController extends AbstractController
{
public ?Request $request;
public Bot $bot;
public BotUserService $botUserService;
public BotCampaignService $botCampaignService;
public EntityManagerInterface $entityManager;
public BotService $service;
public DynamicPriceCalculation $dynamicPriceCalculation;
public function __construct(DynamicPriceCalculation $dynamicPriceCalculation , BotUserService $botUserService,BotCampaignService $botCampaignService , RequestStack $requestStack, ManagerRegistry $managerRegistry, EntityManagerInterface $entityManager, Telegram $telegram, BotService $botService, TransactionService $transactionService, \App\Repository\Generic\UserRepository $agentRepository, UserRepository $userRepository)
{
$this->dynamicPriceCalculation = $dynamicPriceCalculation;
$this->botCampaignService = $botCampaignService;
$this->request = $requestStack->getCurrentRequest();
$this->botUserService = $botUserService;
$this->bot = $managerRegistry->getRepository(Bot::class)->findOneBy(['id' => $requestStack->getCurrentRequest()->get('botId')]);
$adminTelegram = new Telegram($entityManager);
$setting = new SettingService($entityManager);
$this->entityManager = $entityManager;
$this->service = $botService;
}
#[Route('/', name: 'app_telegram_agent_public_bot_management_general')]
public function app_telegram_agent_public_bot_management(ServiceRepository $serviceRepository): Response
{
/**
* @var User $user
*/
$user = $this->getUser();
if ($user->getConnectedTelegramUserId() === null || $user->getConnectedTelegramUserId() ===[]){
$this->addFlash('error' , 'لطفا ابتدا حساب خود را به تلگرام متصل فرمایید');
return $this->redirectToRoute('app_user_dashboard');
}
$botUsers = $this->getDoctrine()->getRepository(BotUser::class)->findBy(['active' => 1, 'bot' => $this->bot]);
$services = $serviceRepository->findBy(['isEnabled' => 1 , 'creatorBot' => $this->bot]);
return $this->render('panel/pages/user/telegram/agent-public-bot/management.html.twig', [
'bot' => $this->bot,
'botUsers' => count($botUsers),
'services' => ($services),
]);
}
#[Route('/edit', name: 'app_telegram_agent_public_bot_management_edit', methods: ['GET', 'POST'])]
public function app_telegram_agent_public_bot_management_edit(Request $request, DomainRepository $domainRepository, EntityManagerInterface $entityManager): Response
{
$object = $this->bot;
$user = $this->getUser();
$domains = $domainRepository->findBy(['owner' => $user, 'isConnected' => true]);
$form = $this->createForm(BotInfoType::class, $object, ['user' => $this->getUser(),'thisBot' => $this->bot , 'domains' => $domains, 'entityManager' => $entityManager]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->service->save($object);
return $this->redirectToRoute('app_telegram_agent_public_bot_management_edit', ['botId' => $object->getId()], Response::HTTP_SEE_OTHER);
}
return $this->render('panel/pages/user/telegram/agent-public-bot/management-edit.html.twig', [
'form' => $form->createView(),
'edit' => true,
'object' => $object,
'bot' => $this->bot
]);
}
#[Route('/marketing', name: 'app_telegram_agent_public_bot_management_marketing', methods: ['GET', 'POST'])]
public function app_telegram_agent_public_bot_management_marketing(Request $request, DomainRepository $domainRepository, EntityManagerInterface $entityManager): Response
{
$this->addFlash('warning' , 'این پیام ها هر روز برای کاربران ساعت ۲۰ ارسال خواهند شد');
$object = $this->bot;
$user = $this->getUser();
$form = $this->createForm(BotAdsFormType::class, $object);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->service->save($object);
return $this->redirectToRoute('app_telegram_agent_public_bot_management_marketing', ['botId' => $object->getId()], Response::HTTP_SEE_OTHER);
}
return $this->render('panel/pages/user/telegram/agent-public-bot/marketing.html.twig', [
'form' => $form->createView(),
'edit' => true,
'object' => $object,
'bot' => $this->bot
]);
}
#[Route('/analytics', name: 'app_telegram_agent_public_bot_management_analytics', methods: ['GET', 'POST'])]
public function app_telegram_agent_public_bot_management_analytics(Request $request,BotAnalyticsRepository $analyticsRepository, EntityManagerInterface $entityManager): Response
{
$now = new \DateTimeImmutable();
$jdf = new JDF();
$monthNumber = $request->query->get('month') ?: $jdf->trNum($jdf->date('m'));
$startJalali = '1404/' . $monthNumber . '/1';
$endJalali = '1404/' . $monthNumber . '/' . $jdf->trNum($jdf->date('t', '', 'fa', $monthNumber));
$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';
$startDateTime = new \DateTime($startDateTime);
$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';
$endDateTime = new \DateTime($endDateTime);
$data = [];
// var_dump(count($analyticsRepository->getBetweenDays($startDateTime, $endDateTime,$this->bot)));die;
foreach ($analyticsRepository->getBetweenDays($startDateTime, $endDateTime,$this->bot) as $item) {
/**
* @var BotAnalytics $item
*/
$data[] = [
'date' => $item->getDate(),
'lastMonthWallet' => $this->getLastMonthChargeFromDate($item->getDate() , $this->bot),
'wallet' => $item->getWalletIncrease(),
'service' => $item->getBoughtService(),
'lastMonthService' => $this->getLastMonthTotalServicesFromDate($item->getDate() , $this->bot),
'lastMonthVolume' => $this->getLastMonthVolumeFromDate($item->getDate() , $this->bot),
'v2ray' => $item->getV2ray(),
'ocServ' => $item->getOcServ(),
'open' => $item->getOpen(),
'v2rayUnlimited' => $item->getV2rayUnlimited(),
'ocServUnlimited' => $item->getOcServUnlimited(),
'openUnlimited' => $item->getOpenUnlimited(),
'vip' => $item->getVip(),
'boughtVolume' => $item->getBoughtVolume(),
'gotTest' => $item->getTestService()
];
}
return $this->render('panel/pages/user/telegram/agent-public-bot/analytics.html.twig', [
'data' => $data,
'month' => $monthNumber,
'bot' => $this->bot
]);
}
#[Route('/delete-plans', name: 'app_telegram_agent_public_bot_management_price_delete_all')]
public function deleteAttPlans(BotPlanRepository $botPlanRepository)
{
foreach ($botPlanRepository->findBy(['bot' => $this->bot]) as $item) {
$this->entityManager->remove($item);
}
$this->entityManager->flush();
return $this->redirectToRoute('app_telegram_agent_public_bot_management_price' , ['botId' => $this->bot->getId()]);
}
#[Route('/price', name: 'app_telegram_agent_public_bot_management_price', methods: ['GET', 'POST'])]
public function app_telegram_agent_public_bot_management_price(Request $request): Response
{
$object = $this->bot;
/**
* @var User $user
*/
$user = $this->getUser();
$autoPriceForm = $this->createFormBuilder()
->add('number', NumberType::class, [
'label' => 'عدد مدنظر برای اضافه شدن به قیمت ها',
])
->add('type', ChoiceType::class, [
'label' => 'نوع قیمت گذاری',
'choices' => [
'افزودن درصد ثابت به قیمت ها' => 'percentage',
'افزودن عدد ثابت به قیمت ها' => 'manual'
]
])
->add('protocols', ChoiceType::class, [
'label' => 'پروتکل مدنظر برای فروش',
'multiple' => true, // اجازه انتخاب چند گزینه
'expanded' => true, // نمایش به صورت چکباکس (اگه false باشه، multi-select میشه)
'choices' => [
'v2ray' => 'v2ray',
'cisco' => 'ocserv',
'openvpn' => 'open',
'vip' => 'vip',
]
])
->getForm();
$autoPriceForm->handleRequest($request);
if ($autoPriceForm->isSubmitted() && $autoPriceForm->isValid()) {
foreach ($this->getDoctrine()->getRepository(BotPlan::class)->findBy(['bot' => $object]) as $botPlan) {
$botPlan->setActive(false);
$botPlan->setDeletedAt(new \DateTime());
}
$this->getDoctrine()->getManager()->flush();
$protocols = [
'v2ray',
'ocserv',
'open',
'vip',
];
foreach ($protocols as $protocol) {
if (in_array($protocol , $autoPriceForm->get('protocols')->getData())) {
$condition = [
'active' => 1,
'protocol' => $protocol,
];
foreach ($this->getDoctrine()->getRepository(Plan::class)->findBy($condition) as $plan) {
if (
$plan->getServiceType() && $plan->getServiceType() !== ''
&&
$plan->getProtocol() && $plan->getProtocol() !== ''
&&
($plan->hasCisco() || $plan->hasV2ray() || $plan->hasOpenVpn())
) {
$planObject = $this->getDoctrine()->getRepository(BotPlan::class)->findOneBy(['bot' => $object, 'active' => 1, 'plan' => $plan]);
if (!$planObject) {
$planObject = new BotPlan();
}
$planObject->setBot($object);
$planObject->setPlan($plan);
$planPrice = $this->dynamicPriceCalculation->calculatePrice($user, $plan , false);
if ($autoPriceForm->get('type')->getData() == 'percentage') {
if ($autoPriceForm->get('number')->getData() >100){
$this->addFlash('error' , 'درصد نمیتواند بیشتر از ۱۰۰ باشد');
return $this->redirectToRoute('app_telegram_agent_public_bot_management_price' , ['botId' => $object->getId()], Response::HTTP_BAD_REQUEST);
}
$price = $planPrice + (($planPrice * (int)$autoPriceForm->get('number')->getData()) / 100);
} else {
$price = $planPrice + (int)$autoPriceForm->get('number')->getData();
}
$planObject->setPrice($price);
$this->getDoctrine()->getManager()->persist($planObject);
$this->getDoctrine()->getManager()->flush();
}
}
}
}
return $this->redirectToRoute('app_telegram_agent_public_bot_management_price', ['botId' => $object->getId()]);
}
$vipPlans = $this->getDoctrine()->getRepository(Plan::class)->createQueryBuilder('u')
->andWhere('u.deletedAt IS null')
->andWhere('u.active = 1')
->andWhere('u.serviceType IS NOT NULL')
->andWhere('u.protocol IS NOT NULL')
->andWhere('u.hasOpenVpn != 0 OR u.hasCisco != 0 OR u.hasV2ray != 0')
->addOrderBy('u.protocol', 'ASC')
->addOrderBy('u.days', 'ASC')
->addOrderBy('u.size', 'ASC')
->getQuery()->getResult();
$vipOptions = [
'plans' => $vipPlans,
'user' => $user,
'entityManager' => $this->getDoctrine()->getManager(),
];
$vipForm = $this->createFormBuilder()
->add('plan', EntityType::class, [
'class' => Plan::class,
'label' => 'انتخاب بسته ',
'choices' => $vipOptions['plans'],
'choice_label' => function ($plan) use ($vipOptions) {
$er = $vipOptions['entityManager'];
/**
* @var Plan $plan
* @var User $user
*/
$user = $vipOptions['user'];
$startPrice = $plan->getPrice();
// foreach ($user->getUserTrace() as $email) {
// $thisUser = $er->getRepository(User::class)->findOneBy(['email' => $email]);
// $startPrice = $startPrice + (($startPrice * $thisUser->getInterestRate()) / 100);
// }
// $title =
// "مولتی پروتکل ({$plan->formatSizeUnits($plan->getSize())})" .
// 'زمان : ' .
// $plan->getDays() . ' روز ' .
// 'حجم : ' .
// $plan->formatSizeUnits($plan->getSize()) . ' ' .
// 'قیمت : ' .
// number_format($startPrice) . ' تومان';
return $plan->__toString() ;
// number_format($this->dynamicPriceCalculation->calculatePrice($user, $plan))
// .' تومان';
}
])
->add('sellPrice', NumberType::class, [
'label' => 'قیمت فروش در ربات'
])
->getForm();
$vipForm->handleRequest($request);
if ($vipForm->isSubmitted() && $vipForm->isValid()) {
$vipPlanPrice = $this->dynamicPriceCalculation->calculatePrice($user, $vipForm->get('plan')->getData());
if (($vipPlanPrice >= $vipForm->get('sellPrice')->getData()) && !$user->hasRole('ROLE_ADMIN')) {
$this->addFlash('error', 'قیمت فروش در ربات باید افزایش یابد');
return $this->redirectToRoute('app_telegram_agent_public_bot_management_price', ['botId' => $object->getId()]);
}
$planObject = $this->getDoctrine()->getRepository(BotPlan::class)->findOneBy(['bot' => $object, 'active' => 1, 'plan' => $vipForm->get('plan')->getData()]);
if (!$planObject) {
$planObject = new BotPlan();
}
$planObject->setBot($object);
$planObject->setPrice($vipForm->get('sellPrice')->getData());
$planObject->setPlan($vipForm->get('plan')->getData());
$this->getDoctrine()->getManager()->persist($planObject);
$this->getDoctrine()->getManager()->flush();
$this->addFlash('success', 'بسته فروش به ربات اضافه شد');
return $this->redirectToRoute('app_telegram_agent_public_bot_management_price', ['botId' => $object->getId()]);
}
$botPlans = $this->getDoctrine()->getRepository(BotPlan::class)->findBy(['bot' => $object, 'active' => 1]);
foreach ($botPlans as $key => $botPlan) {
if ($botPlan->getPlan() == null || !$botPlan->getPlan()->isActive()){
unset($botPlans[$key]);
}
}
return $this->render('panel/pages/user/telegram/agent-public-bot/management-price.html.twig', [
'vipForm' => $vipForm->createView(),
'vipPlans' => $vipPlans,
'edit' => true,
'object' => $object,
'bot' => $this->bot,
'botPlans' => $botPlans,
'autoPrice' => $autoPriceForm->createView()
]);
}
public function getFilters(): array
{
return [
[
'name' => 'search',
'type' => 'text',
'label' => 'کلیدواژه',
'class' => '',
'value' => $this->request->get('search')
],
[
'name' => 'active',
'type' => 'radio',
'label' => 'وضعیت',
'class' => '',
'radio' => [
['name' => 'همه', 'value' => 'all'],
['name' => 'فعال', 'value' => 'true'],
['name' => 'غیرفعال', 'value' => 'false'],
],
'value' => $this->request->get('active')
]
];
}
public function getLists(): array
{
$array = [
[
'name' => 'name',
'label' => 'نام',
'class' => '',
],
[
'name' => 'username',
'label' => 'نام کاربری تلگرام',
'class' => '',
],
[
'name' => 'userId',
'label' => 'شناسه کاربر',
'class' => '',
],
[
'name' => 'wallet',
'label' => 'کیف پول',
'class' => '',
'type' => 'price'
],
[
'name' => 'createdAt',
'label' => 'تاریخ عضویت',
'class' => '',
'type' => 'date'
],
[
'name' => 'campaign',
'label' => 'کمپین',
'class' => '',
],
];
return $array;
}
#[Route('/users', name: 'app_telegram_agent_public_bot_management_users', methods: ['GET', 'POST'])]
public function app_telegram_agent_public_bot_management_users(Request $request): Response
{
$object = $this->bot;
/**
* @var User $user
*/
$user = $this->getUser();
$info = new BotUserViewModel($request);
$data = $this->botUserService->getList($info, $this->bot);
return $this->render('panel/pages/user/telegram/agent-public-bot/management-users.html.twig', [
'paginator' => $data,
'currentPage' => 'app_telegram_agent_public_bot_management_users',
'bot' => $this->bot,
'parameters' => $info,
'filters' => $this->getFilters(),
'lists' => $this->getLists(),
]);
}
#[Route('/notification', name: 'app_telegram_agent_public_bot_management_notification', methods: ['GET', 'POST'])]
public function app_telegram_agent_public_bot_management_notification(Request $request): Response
{
$form = $this->createFormBuilder()
->add('message', TextareaType::class, [
'label' => 'متن پیام همگانی'
])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$notification = new BotNotification();
$notification->setBot($this->bot);
$notification->setMessage($form->get('message')->getData());
$notification->setIsSent(0);
$this->entityManager->persist($notification);
$this->entityManager->flush();
$text = 'پیام شما در صف تلگرام قرار گرفت و بزودی ارسال همگانی خواهد شد....';
$this->addFlash('success', $text);
return $this->redirectToRoute('app_telegram_agent_public_bot_management_notification', ['botId' => $this->bot->getId()]);
}
return $this->render('panel/pages/user/telegram/agent-public-bot/management-users-notification.html.twig', [
'form' => $form->createView(),
'bot' => $this->bot
]);
}
#[Route('/users/{userId}', name: 'app_telegram_agent_public_bot_management_users_transaction', methods: ['GET', 'POST'])]
public function app_telegram_agent_public_bot_management_users_transaction(Request $request, $userId): Response
{
$botUser = $this->getDoctrine()->getRepository(BotUser::class)->findOneBy(['userId' => $userId, 'bot' => $this->bot]);
$form = $this->createFormBuilder()
->add('type', ChoiceType::class, [
'label' => 'نوع تراکنش',
'choices' => [
'افزایش' => 1,
'کاهش' => 0,
]
])
->add('price', NumberType::class, [
'label' => 'مبلغ به تومان'
])
->add('description', TextareaType::class, [
'label' => 'توضیحات تراکنش'
])->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isSubmitted()) {
$price = $form->getData()['price'];
$type = $form->getData()['type'];
$description = $form->getData()['description'];
$transaction = new BotTransaction();
$transaction->setBot($this->bot);
$transaction->setBotUser($botUser);
$transaction->setPrice($price);
$transaction->setType($type);
$transaction->setDescription($description);
if ($type == 1) {
$transaction->setType(1);
$transaction->setBeforeWallet($botUser->getWallet());
$transaction->setAfterWallet($botUser->getWallet() + $price);
$transaction->setPrice($price);
$transaction->setDescription($description);
$botUser->setWallet($botUser->getWallet() + $price);
} else {
$transaction->setType(0);
$transaction->setBeforeWallet($botUser->getWallet());
$transaction->setPrice($price);
$transaction->setAfterWallet($botUser->getWallet() - $price);
$botUser->setWallet($botUser->getWallet() - $price);
$transaction->setDescription($description);
}
$this->getDoctrine()->getManager()->persist($transaction);
$this->getDoctrine()->getManager()->flush();
$this->addFlash('success', 'با موفقیت ثبت شد');
return $this->redirectToRoute('app_telegram_agent_public_bot_management_users', ['botId' => $this->bot->getId()]);
}
return $this->render('panel/pages/user/telegram/agent-public-bot/management-users-transaction.html.twig', [
'form' => $form->createView(),
'user' => $botUser,
'bot' => $this->bot
]);
}
#[Route('/users-message/{userId}', name: 'app_telegram_agent_public_bot_management_users_send_message', methods: ['GET', 'POST'])]
public function app_telegram_agent_public_bot_management_users_send_message(NotificationService $notificationService ,Request $request, $userId): Response
{
$botUser = $this->getDoctrine()->getRepository(BotUser::class)->findOneBy(['userId' => $userId, 'bot' => $this->bot]);
$form = $this->createFormBuilder()
->add('message', TextareaType::class, [
'label' => 'متن'
])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
try {
$keyboard = json_encode([
"inline_keyboard" => [
[
[
"text" => "شروع",
"callback_data" => "/start"
]
]
]
]);
$this->bot('sendMessage', [
'chat_id' => $botUser->getUserId(),
'text' => $form->getData()['message'],
'reply_markup' => $keyboard
], $botUser->getBot()->getToken());
} catch (\Exception $exception) {
$notificationService->exception($exception);
$botUser->setActive(false);
$botUser->setdeletedAt(new \DateTime());
$this->getDoctrine()->getManager()->flush();
}
$text = 'پیام با موفقیت ارسال شد';
$this->addFlash('success', $text);
return $this->redirectToRoute('app_telegram_agent_public_bot_management_users', ['botId' => $this->bot->getId()]);
}
return $this->render('panel/pages/user/telegram/agent-public-bot/management-users-transaction.html.twig', [
'form' => $form->createView(),
'user' => $botUser,
'bot' => $this->bot
]);
}
public function bot($method, $data, $token)
{
$setting = new SettingService($this->entityManager);
$telegramApiUrl = 'https://api.telegram.org/bot' . $token . '/';
return file_get_contents($telegramApiUrl . $method . '?' . str_replace('&', '&', http_build_query($data)));
}
#[Route('/campaigns', name: 'app_telegram_agent_public_bot_management_campaigns', methods: ['GET', 'POST'])]
public function app_telegram_agent_public_bot_management_campaigns(Request $request): Response
{
$object = $this->bot;
/**
* @var User $user
*/
$user = $this->getUser();
$info = new BotCampaignViewModel($request);
$data = $this->botCampaignService->getList($info, $this->bot);
return $this->render('panel/pages/user/telegram/agent-public-bot/management-campaigns.html.twig', [
'paginator' => $data,
'currentPage' => 'app_telegram_agent_public_bot_management_campaigns',
'bot' => $this->bot,
'parameters' => $info,
'filters' => $this->getFilters(),
'lists' => [
[
'name' => 'title',
'label' => 'نام',
'class' => '',
],
[
'name' => 'botUsersCount',
'label' => 'تعداد کاربران',
'class' => '',
],
[
'name' => 'createdAt',
'label' => 'تاریخ ثبت کمپین',
'class' => '',
'type' => 'date'
],
],
]);
}
#[Route('/remove-plan/{planId}', name: 'app_user_agent_bot_plan_remove')]
public function app_user_agent_bot_plan_remove($planId): Response
{
$object = $this->getDoctrine()->getRepository(BotPlan::class)->find($planId);
$object->setActive(0);
$object->setDeletedAt(new \DateTime());
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('app_telegram_agent_public_bot_management_price', ['botId' => $object->getBot()->getId()], Response::HTTP_SEE_OTHER);
}
public function getLastMonthChargeFromDate($date , $bot)
{
$jdf = new JDF();
$jalaliArray = $jdf->gregorianToJalali($date->format('Y'), $date->format('m'), $date->format('d'));
$jalaliArray[1] = $jalaliArray[1] - 1;
$gregorianArray = $jdf->jalaliToGregorian($jalaliArray[0], $jalaliArray[1], $jalaliArray[2]);
$analyticsItem = $this->getDoctrine()->getRepository(BotAnalytics::class)->findOneBy([
'bot' => $bot,
'date' => new \DateTimeImmutable($gregorianArray[0] . '-' . $gregorianArray[1] . '-' . $gregorianArray[2] . ' 00:00:00')]);
return $analyticsItem ? $analyticsItem->getWalletIncrease() : 0;
}
public function getLastMonthVolumeFromDate($date , $bot)
{
$jdf = new JDF();
$jalaliArray = $jdf->gregorianToJalali($date->format('Y'), $date->format('m'), $date->format('d'));
$jalaliArray[1] = $jalaliArray[1] - 1;
$gregorianArray = $jdf->jalaliToGregorian($jalaliArray[0], $jalaliArray[1], $jalaliArray[2]);
$analyticsItem = $this->getDoctrine()->getRepository(BotAnalytics::class)->findOneBy([
'bot' => $bot,
'date' => new \DateTimeImmutable($gregorianArray[0] . '-' . $gregorianArray[1] . '-' . $gregorianArray[2] . ' 00:00:00')]);
return $analyticsItem ? $analyticsItem->getBoughtVolume() : 0;
}
public function getLastMonthTotalServicesFromDate($date , $bot)
{
$jdf = new JDF();
$jalaliArray = $jdf->gregorianToJalali($date->format('Y'), $date->format('m'), $date->format('d'));
$jalaliArray[1] = $jalaliArray[1] - 1;
$gregorianArray = $jdf->jalaliToGregorian($jalaliArray[0], $jalaliArray[1], $jalaliArray[2]);
$analyticsItem = $this->getDoctrine()->getRepository(BotAnalytics::class)->findOneBy([
'bot' => $bot,
'date' => new \DateTimeImmutable($gregorianArray[0] . '-' . $gregorianArray[1] . '-' . $gregorianArray[2] . ' 00:00:00')]);
return $analyticsItem ? $analyticsItem->getBoughtService() : 0;
}
}