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.     /**
  74.      * Существует пул анкет которые не будут (скорее всего) подтверждать, но они должны иметь приоритет 4. Это анкеты у которых номера телефонов:
  75.      */
  76.     private static array $reservedPhoneNumbers = [
  77.         "+79670621036",
  78.         "+79670668029",
  79.         "+79657648078",
  80.         "+79602362794",
  81.         "+79657647505",
  82.         "+79697928815",
  83.         "+79657656744",
  84.         "+79095836840",
  85.         "+79095868490",
  86.         "+79816893783",
  87.         "+79816884190",
  88.         "+79816881721",
  89.         "+79816892844",
  90.         "+79816894385",
  91.         "+79646132419",
  92.         "+79697390357",
  93.         "+79618107602",
  94.     ];
  95.     public static function free(Profile $profileint $position, ?PaidPlacementPrice $paidPlacementPrice\DateTimeImmutable $placedAt\DateTimeImmutable $placedUntil): self
  96.     {
  97.         $positionGroup self::POSITION_GROUP_FREE;
  98.         return new static($profileAdBoardPlacementType::free(), $paidPlacementPrice$positionGroup$position$placedAt$placedUntil);
  99.     }
  100.     public static function standard(Profile $profileint $positionPaidPlacementPrice $paidPlacementPrice\DateTimeImmutable $placedAt\DateTimeImmutable $placedUntil): self
  101.     {
  102.         if ($profile->hasOwner()) {
  103.             $positionGroup $profile->isApproved() ? self::POSITION_GROUP_STANDARD_APPROVED self::POSITION_GROUP_STANDARD;
  104.         } else {
  105.             if (in_array($profile->getPhoneNumber(), self::$reservedPhoneNumberstrue)) {
  106.                 $positionGroup self::POSITION_GROUP_STANDARD;
  107.             } else {
  108.                 $positionGroup $profile->isApproved() ? self::POSITION_GROUP_WITHOUT_OWNER_APPROVED self::POSITION_GROUP_WITHOUT_OWNER;
  109.             }
  110.         }
  111.         return new static($profileAdBoardPlacementType::standard(), $paidPlacementPrice$positionGroup$position$placedAt$placedUntil);
  112.     }
  113.     public static function vip(Profile $profileint $positionPaidPlacementPrice $paidPlacementPrice\DateTimeImmutable $placedAt\DateTimeImmutable $placedUntil): self
  114.     {
  115.         if (!$profile->hasOwner()) {
  116.             throw new \LogicException('Profile without owner cannot be placed at VIP position');
  117.         }
  118.         $positionGroup self::POSITION_GROUP_VIP;
  119.         return new static($profileAdBoardPlacementType::vip(), $paidPlacementPrice$positionGroup$position$placedAt$placedUntil);
  120.     }
  121.     public static function ultraVip(Profile $profileint $positionPaidPlacementPrice $paidPlacementPrice\DateTimeImmutable $placedAt\DateTimeImmutable $placedUntil): self
  122.     {
  123.         if (!$profile->hasOwner()) {
  124.             throw new \LogicException('Profile without owner cannot be placed at UltraVIP position');
  125.         }
  126.         $positionGroup self::POSITION_GROUP_ULTRA_VIP;
  127.         return new static($profileAdBoardPlacementType::ultraVip(), $paidPlacementPrice$positionGroup$position$placedAt$placedUntil);
  128.     }
  129.     protected function __construct(Profile $profileAdBoardPlacementType $type, ?PaidPlacementPrice $paidPlacementPriceint $positionGroupint $position\DateTimeImmutable $placedAt\DateTimeImmutable $placedUntil)
  130.     {
  131.         $this->profile $profile;
  132.         $this->type $type->getValue();
  133.         $this->positionGroup $positionGroup;
  134.         $this->position $position;
  135.         $this->placedAt $placedAt;
  136.         $this->placedUntil $placedUntil;
  137.         $this->placementPrice $paidPlacementPrice;
  138.     }
  139.     /**
  140.      * Продление показа анкеты в выдаче на сайте
  141.      */
  142.     public function prolong(\DateTimeImmutable $placedUntil): void
  143.     {
  144.         $this->placedUntil $placedUntil;
  145.     }
  146.     public function getProfile(): Profile
  147.     {
  148.         return $this->profile;
  149.     }
  150.     public function getType(): AdBoardPlacementType
  151.     {
  152.         return new AdBoardPlacementType($this->type);
  153.     }
  154.     public function getPositionGroup(): int
  155.     {
  156.         return $this->positionGroup;
  157.     }
  158.     public function getPosition(): int
  159.     {
  160.         return $this->position;
  161.     }
  162.     public function getPlacedAt(): \DateTimeImmutable
  163.     {
  164.         return $this->placedAt;
  165.     }
  166.     public function getPlacedUntil(): \DateTimeImmutable
  167.     {
  168.         return $this->placedUntil;
  169.     }
  170.     public function getPlacementPrice(): ?PaidPlacementPrice
  171.     {
  172.         return $this->placementPrice;
  173.     }
  174.     public function clearProfile():void
  175.     {
  176.         $this->profile null;
  177.     }
  178. }