src/Entity/Telegram/AgentPublicBot/BotPlan.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Telegram\AgentPublicBot;
  3. use App\Entity\BaseEntity;
  4. use App\Entity\VPN\Service\Plan;
  5. use App\Repository\Telegram\AgentPublicBot\BotPlanRepository;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  9. #[ORM\Entity(repositoryClassBotPlanRepository::class)]
  10. class BotPlan extends BaseEntity
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\Column(type'guid'uniquetrue)]
  14.     #[ORM\GeneratedValue(strategy'CUSTOM')]
  15.     #[ORM\CustomIdGenerator(class: UuidGenerator::class)]
  16.     private ?string $id null;
  17.     #[ORM\ManyToOne(inversedBy'botPlans')]
  18.     #[ORM\JoinColumn(nullablefalse)]
  19.     private ?Bot $bot null;
  20.     #[ORM\Column(typeTypes::BIGINT)]
  21.     private ?string $price null;
  22.     #[ORM\ManyToOne(inversedBy'botPlans')]
  23.     private ?Plan $plan null;
  24.     public function getId(): ?string
  25.     {
  26.         return $this->id;
  27.     }
  28.     public function getBot(): ?Bot
  29.     {
  30.         return $this->bot;
  31.     }
  32.     public function setBot(?Bot $bot): static
  33.     {
  34.         $this->bot $bot;
  35.         return $this;
  36.     }
  37.     public function getV2rayMultiPlan(): ?V2rayMultiPlan
  38.     {
  39.         return $this->v2rayMultiPlan;
  40.     }
  41.     public function setV2rayMultiPlan(?V2rayMultiPlan $v2rayMultiPlan): static
  42.     {
  43.         $this->v2rayMultiPlan $v2rayMultiPlan;
  44.         return $this;
  45.     }
  46.     public function getPrice(): ?string
  47.     {
  48.         return $this->price;
  49.     }
  50.     public function setPrice(string $price): static
  51.     {
  52.         $this->price $price;
  53.         return $this;
  54.     }
  55.     public function toTelegramStringV2rayMulti(Bot $bot)
  56.     {
  57.         if ($this->getVipPlan() !== null){
  58.             if ($bot->getOffPercent() && $bot->getOffPercent() > 0){
  59.                 $title =
  60.                     'زمان : '.
  61.                     $this->getVipPlan()->getDays().' روز '.
  62.                     'حجم : '.
  63.                     $this->formatSizeUnits$this->getVipPlan()->getSize()).' '.
  64.                     'قیمت : '.
  65.                     number_format($this->getPrice() - ( ($bot->getOffPercent() * $this->getPrice()) / 100  ) ) . ' تومان' .
  66.                 " پس از {$bot->getOffPercent()} درصد تخفیف "
  67.                 ;
  68.             }else{
  69.                 $title =
  70.                     'زمان : '.
  71.                     $this->getVipPlan()->getDays().' روز '.
  72.                     'حجم : '.
  73.                     $this->formatSizeUnits$this->getVipPlan()->getSize()).' '.
  74.                     'قیمت : '.
  75.                     number_format($this->getPrice()) . ' تومان';
  76.             }
  77.         }
  78.         if ($this->getV2rayMultiPlan() !== null){
  79.             if ($bot->getOffPercent() && $bot->getOffPercent() > 0){
  80.                 $title =
  81.                     'زمان : '.
  82.                     $this->getV2rayMultiPlan()->getDays().' روز '.
  83.                     'حجم : '.
  84.                     $this->formatSizeUnits$this->getV2rayMultiPlan()->getSize()).' '.
  85.                     'قیمت : '.
  86.                     number_format($this->getPrice() - ( ($bot->getOffPercent() * $this->getPrice()) / 100  ) ) . ' تومان' .
  87.                 " پس از {$bot->getOffPercent()} درصد تخفیف "
  88.                 ;
  89.             }else{
  90.                 $title =
  91.                     'زمان : '.
  92.                     $this->getV2rayMultiPlan()->getDays().' روز '.
  93.                     'حجم : '.
  94.                     $this->formatSizeUnits$this->getV2rayMultiPlan()->getSize()).' '.
  95.                     'قیمت : '.
  96.                     number_format($this->getPrice()) . ' تومان';
  97.             }
  98.         }
  99.         if ($this->getCiscoPlan() !== null){
  100.             if ($bot->getOffPercent() && $bot->getOffPercent() > 0){
  101.                 $title =
  102.                     'زمان : '.
  103.                     $this->getCiscoPlan()->getDays().' روز '.
  104.                     'حجم : '.
  105.                     $this->formatSizeUnits$this->getCiscoPlan()->getSize()).' '.
  106.                     'قیمت : '.
  107.                     number_format($this->getPrice() - ( ($bot->getOffPercent() * $this->getPrice()) / 100  ) ) . ' تومان' .
  108.                 " پس از {$bot->getOffPercent()} درصد تخفیف "
  109.                 ;
  110.             }else{
  111.                 $title =
  112.                     'زمان : '.
  113.                     $this->getCiscoPlan()->getDays().' روز '.
  114.                     'حجم : '.
  115.                     $this->formatSizeUnits$this->getCiscoPlan()->getSize()).' '.
  116.                     'قیمت : '.
  117.                     number_format($this->getPrice()) . ' تومان';
  118.             }
  119.         }
  120.         if ($this->getOpenPlan() !== null){
  121.             if ($bot->getOffPercent() && $bot->getOffPercent() > 0){
  122.                 $title =
  123.                     'زمان : '.
  124.                     $this->getOpenPlan()->getDays().' روز '.
  125.                     'حجم : '.
  126.                     $this->formatSizeUnits$this->getOpenPlan()->getSize()).' '.
  127.                     'کاربر : '.
  128.                     $this->getOpenPlan()->getUser().' '.
  129.                     'قیمت : '.
  130.                     number_format($this->getPrice() - ( ($bot->getOffPercent() * $this->getPrice()) / 100  ) ) . ' تومان' .
  131.                 " پس از {$bot->getOffPercent()} درصد تخفیف "
  132.                 ;
  133.             }else{
  134.                 $title =
  135.                     'زمان : '.
  136.                     $this->getOpenPlan()->getDays().' روز '.
  137.                     'حجم : '.
  138.                     $this->formatSizeUnits$this->getOpenPlan()->getSize()).' '.
  139.                     'کاربر : '.
  140.                     $this->getOpenPlan()->getUser().' '.
  141.                     'قیمت : '.
  142.                     number_format($this->getPrice()) . ' تومان';
  143.             }
  144.         }
  145.         return $title;
  146.     }
  147.     public function formatSizeUnits($bytes): string
  148.     {
  149.         if ($bytes >= 1073741824) {
  150.             $bytes number_format($bytes 10737418242) . ' GB';
  151.         } elseif ($bytes >= 1048576) {
  152.             $bytes number_format($bytes 10485762) . ' MB';
  153.         } elseif ($bytes >= 1024) {
  154.             $bytes number_format($bytes 10242) . ' KB';
  155.         } elseif ($bytes 1) {
  156.             $bytes $bytes ' bytes';
  157.         } elseif ($bytes == 1) {
  158.             $bytes $bytes ' byte';
  159.         } else {
  160.             $bytes '0 bytes';
  161.         }
  162.         return $bytes;
  163.     }
  164.     public function getPlan(): ?Plan
  165.     {
  166.         return $this->plan;
  167.     }
  168.     public function setPlan(?Plan $plan): static
  169.     {
  170.         $this->plan $plan;
  171.         return $this;
  172.     }
  173. }