src/Entity/Sales/Profile/AdBoardPlacement.php line 30

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by simpson <simpsonwork@gmail.com>
  4.  * Date: 2019-08-23
  5.  * Time: 21:03
  6.  */
  7. namespace App\Entity\Sales\Profile;
  8. use App\Entity\Profile\Profile;
  9. use App\Entity\Sales\PaidPlacementPrice;
  10. use App\Repository\ProfileAdBoardPlacementRepository;
  11. use Doctrine\ORM\Mapping as ORM;
  12. /**
  13.  * Сортировка будет выглядеть следующим образом:
  14.  * 1. Ультра вип
  15.  * 2. Вип
  16.  * 3. Анкеты с подтвержденными фото
  17.  * 4. Подтвержденные оплаченные анкеты и наши анкеты (см. ниже)
  18.  * 5. Старые анкеты с подтвержденным фото
  19.  * 6. Старые анкеты
  20.  *
  21.  * где 1 - первые страницы, 6 - последние.
  22.  *
  23.  * @see https://redminez.net/issues/26983
  24.  */
  25. #[ORM\Table(name'profile_adboard_placements')]
  26. #[ORM\Entity(repositoryClassProfileAdBoardPlacementRepository::class)]
  27. class AdBoardPlacement
  28. {
  29.     // Значение группы влияет на порядок сортировки на сайте
  30.     const POSITION_GROUP_ULTRA_VIP 200;
  31.     const POSITION_GROUP_VIP 100;
  32.     // Группы стандартных размещений
  33.     const POSITION_GROUP_STANDARD_APPROVED 60;
  34.     const POSITION_GROUP_STANDARD 50;
  35.     const POSITION_GROUP_WITHOUT_OWNER_APPROVED 40;
  36.     const POSITION_GROUP_WITHOUT_OWNER 30;
  37.     const POSITION_GROUP_FREE 10;
  38.     #[ORM\JoinColumn(name'profile_id'referencedColumnName'id')]
  39.     #[ORM\Id]
  40.     #[ORM\OneToOne(targetEntityProfile::class, inversedBy'adBoardPlacement')]
  41.     protected ?Profile $profile;
  42.     /**
  43.      * Тип размещения: ультра-вип, вип, стандарт и др.
  44.      */
  45.     #[ORM\Column(name'type'type'smallint')]
  46.     protected int $type;
  47.     #[ORM\Column(name'position_group'type'smallint')]
  48.     protected int $positionGroup;
  49.     /**
  50.      * Позиция для сортировки, меняется несколько раз в течение в часа
  51.      *
  52.      * Новые анкеты добавляются всегда с наименьшим числом (может быть и отрицательным).
  53.      * При ротации позиции увеличиваются на 2.
  54.      */
  55.     #[ORM\Column(name'position'type'integer')]
  56.     protected int $position;
  57.     /**
  58.      * Время добавления анкеты с указанным типом в список
  59.      */
  60.     #[ORM\Column(name'placed_at'type'datetimetz_immutable')]
  61.     protected \DateTimeImmutable $placedAt;
  62.     /**
  63.      * Время следующего списания за показ в списке
  64.      */
  65.     #[ORM\Column(name'placed_until'type'datetimetz_immutable')]
  66.     protected \DateTimeImmutable $placedUntil;
  67.     /**
  68.      * Цена, по которой было размещено (для продления по этой же цене)
  69.      */
  70.     #[ORM\JoinColumn(name'placement_price_id'referencedColumnName'id'nullabletrue)]
  71.     #[ORM\ManyToOne(targetEntityPaidPlacementPrice::class)]
  72.     protected ?PaidPlacementPrice $placementPrice;
  73.     #[ORM\Column(name'plan_managed'type'boolean'options: ['default' => false])]
  74.     protected bool $planManaged false;
  75.     /**
  76.      * Существует пул анкет которые не будут (скорее всего) подтверждать, но они должны иметь приоритет 4. Это анкеты у которых номера телефонов:
  77.      */
  78.     private static array $reservedPhoneNumbers = [
  79.         "+79670621036",
  80.         "+79670668029",
  81.         "+79657648078",
  82.         "+79602362794",
  83.         "+79657647505",
  84.         "+79697928815",
  85.         "+79657656744",
  86.         "+79095836840",
  87.         "+79095868490",
  88.         "+79816893783",
  89.         "+79816884190",
  90.         "+79816881721",
  91.         "+79816892844",
  92.         "+79816894385",
  93.         "+79646132419",
  94.         "+79697390357",
  95.         "+79618107602",
  96.     ];
  97.     public static function free(Profile $profileint $position, ?PaidPlacementPrice $paidPlacementPrice\DateTimeImmutable $placedAt\DateTimeImmutable $placedUntilbool $planManaged false): self
  98.     {
  99.         $positionGroup self::POSITION_GROUP_FREE;
  100.         return new static($profileAdBoardPlacementType::free(), $paidPlacementPrice$positionGroup$position$placedAt$placedUntil$planManaged);
  101.     }
  102.     public static function standard(Profile $profileint $positionPaidPlacementPrice $paidPlacementPrice\DateTimeImmutable $placedAt\DateTimeImmutable $placedUntilbool $planManaged false): self
  103.     {
  104.         if ($profile->hasOwner()) {
  105.             $positionGroup $profile->isApproved() ? self::POSITION_GROUP_STANDARD_APPROVED self::POSITION_GROUP_STANDARD;
  106.         } else {
  107.             if (in_array($profile->getPhoneNumber(), self::$reservedPhoneNumberstrue)) {
  108.                 $positionGroup self::POSITION_GROUP_STANDARD;
  109.             } else {
  110.                 $positionGroup $profile->isApproved() ? self::POSITION_GROUP_WITHOUT_OWNER_APPROVED self::POSITION_GROUP_WITHOUT_OWNER;
  111.             }
  112.         }
  113.         return new static($profileAdBoardPlacementType::standard(), $paidPlacementPrice$positionGroup$position$placedAt$placedUntil$planManaged);
  114.     }
  115.     public static function vip(Profile $profileint $positionPaidPlacementPrice $paidPlacementPrice\DateTimeImmutable $placedAt\DateTimeImmutable $placedUntilbool $planManaged false): self
  116.     {
  117.         if (!$profile->hasOwner()) {
  118.             throw new \LogicException('Profile without owner cannot be placed at VIP position');
  119.         }
  120.         $positionGroup self::POSITION_GROUP_VIP;
  121.         return new static($profileAdBoardPlacementType::vip(), $paidPlacementPrice$positionGroup$position$placedAt$placedUntil$planManaged);
  122.     }
  123.     public static function ultraVip(Profile $profileint $positionPaidPlacementPrice $paidPlacementPrice\DateTimeImmutable $placedAt\DateTimeImmutable $placedUntilbool $planManaged false): self
  124.     {
  125.         if (!$profile->hasOwner()) {
  126.             throw new \LogicException('Profile without owner cannot be placed at UltraVIP position');
  127.         }
  128.         $positionGroup self::POSITION_GROUP_ULTRA_VIP;
  129.         return new static($profileAdBoardPlacementType::ultraVip(), $paidPlacementPrice$positionGroup$position$placedAt$placedUntil$planManaged);
  130.     }
  131.     protected function __construct(Profile $profileAdBoardPlacementType $type, ?PaidPlacementPrice $paidPlacementPriceint $positionGroupint $position\DateTimeImmutable $placedAt\DateTimeImmutable $placedUntilbool $planManaged false)
  132.     {
  133.         $this->profile $profile;
  134.         $this->type $type->getValue();
  135.         $this->positionGroup $positionGroup;
  136.         $this->position $position;
  137.         $this->placedAt $placedAt;
  138.         $this->placedUntil $placedUntil;
  139.         $this->placementPrice $paidPlacementPrice;
  140.         $this->planManaged $planManaged;
  141.     }
  142.     /**
  143.      * Продление показа анкеты в выдаче на сайте
  144.      */
  145.     public function prolong(\DateTimeImmutable $placedUntil): void
  146.     {
  147.         $this->placedUntil $placedUntil;
  148.     }
  149.     public function getProfile(): Profile
  150.     {
  151.         return $this->profile;
  152.     }
  153.     public function getType(): AdBoardPlacementType
  154.     {
  155.         return new AdBoardPlacementType($this->type);
  156.     }
  157.     public function getPositionGroup(): int
  158.     {
  159.         return $this->positionGroup;
  160.     }
  161.     public function getPosition(): int
  162.     {
  163.         return $this->position;
  164.     }
  165.     public function getPlacedAt(): \DateTimeImmutable
  166.     {
  167.         return $this->placedAt;
  168.     }
  169.     public function getPlacedUntil(): \DateTimeImmutable
  170.     {
  171.         return $this->placedUntil;
  172.     }
  173.     public function getPlacementPrice(): ?PaidPlacementPrice
  174.     {
  175.         return $this->placementPrice;
  176.     }
  177.     public function isPlanManaged(): bool
  178.     {
  179.         return $this->planManaged;
  180.     }
  181.     public function markAsPlanManaged(bool $planManaged): void
  182.     {
  183.         $this->planManaged $planManaged;
  184.     }
  185.     public function clearProfile():void
  186.     {
  187.         $this->profile null;
  188.     }
  189. }