src/Dto/OnlineOrder/OnlineOrderDto.php line 16

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Slivki\Dto\OnlineOrder;
  4. use DateTimeImmutable;
  5. use JsonSerializable;
  6. use OpenApi\Annotations as OA;
  7. use Nelmio\ApiDocBundle\Annotation\Model;
  8. use Slivki\Enum\DeviceTypeEnum;
  9. use Slivki\Enum\Order\DeliveryType;
  10. use Slivki\Enum\Order\PaymentType;
  11. use Slivki\Enum\Order\OrderPartnerStatus;
  12. final class OnlineOrderDto implements JsonSerializable
  13. {
  14.     private BuyerDto $buyer;
  15.     /**
  16.      * @OA\Property(
  17.      *     property="paidAt",
  18.      *     type="string",
  19.      *     format="date-time",
  20.      *     description="Дата покупки",
  21.      *     example="2023-02-18 10:30:23",
  22.      * )
  23.      */
  24.     private DateTimeImmutable $paidAt;
  25.     /**
  26.      * @OA\Property(
  27.      *     property="paymentType",
  28.      *     type="string",
  29.      *     description="Тип оплаты",
  30.      *     enum={"Online","Наличные","Терминал","SlivkiPay"},
  31.      * )
  32.      */
  33.     private PaymentType $paymentType;
  34.     /**
  35.      * @OA\Property(
  36.      *     property="deviceType",
  37.      *     type="string",
  38.      *     description="Тип оплаты",
  39.      *     enum={"Сайт","Мобильная версия сайта","Приложение"},
  40.      * )
  41.      */
  42.     private DeviceTypeEnum $deviceType;
  43.     /**
  44.      * @OA\Property(
  45.      *     property="deliveryType",
  46.      *     type="string",
  47.      *     description="Тип оплаты",
  48.      *     enum={"Доставка","Самовывоз"},
  49.      * )
  50.      */
  51.     private DeliveryType $deliveryType;
  52.     /**
  53.      * @OA\Property(
  54.      *     type="array",
  55.      *     description="Адреса с расстояниями до них",
  56.      *     @OA\Items(ref=@Model(type=OrderItemDto::class)),
  57.      * )
  58.      *
  59.      * @var array<OrderItemDto>
  60.      */
  61.     private array $composition;
  62.     /**
  63.      * @OA\Property(
  64.      *     type="array",
  65.      *     description="Промокоды",
  66.      *     @OA\Items(type="string"),
  67.      * )
  68.      *
  69.      * @var array<string>
  70.      */
  71.     private array $codes;
  72.     /**
  73.      * @OA\Property(
  74.      *     property="amount",
  75.      *     type="number",
  76.      *     format="float",
  77.      *     description="Сумма (BYN)",
  78.      *     example="100.50",
  79.      * )
  80.      */
  81.     private float $amount;
  82.     /**
  83.      * @OA\Property(
  84.      *     property="orderId",
  85.      *     description="Id заказа",
  86.      *     example="123456",
  87.      * )
  88.      */
  89.     private int $orderId;
  90.     /**
  91.      * @OA\Property(
  92.      *     property="comment",
  93.      *     description="Адрес",
  94.      *     example="Не входить убьет!",
  95.      *     nullable=true,
  96.      * )
  97.      */
  98.     private ?string $comment;
  99.     /**
  100.      * @OA\Property(
  101.      *     property="preOrderAt",
  102.      *     type="string",
  103.      *     format="date-time",
  104.      *     description="Предзаказ на время",
  105.      *     example="2023-02-18 10:30:23",
  106.      *     nullable=true,
  107.      * )
  108.      */
  109.     private ?DateTimeImmutable $preOrderAt;
  110.     /**
  111.      * @OA\Property(
  112.      *     property="deliveryPrice",
  113.      *     type="number",
  114.      *     format="float",
  115.      *     description="Стоимость доставки (BYN)",
  116.      *     example="5.50",
  117.      *     nullable=true,
  118.      * )
  119.      */
  120.     private ?float $deliveryPrice;
  121.     /**
  122.      * @OA\Property(
  123.      *     property="address",
  124.      *     description="Адрес",
  125.      *     example="Минск, ул. Янки Купалы, 25",
  126.      *     nullable=true,
  127.      * )
  128.      */
  129.     private ?string $address;
  130.     /**
  131.      * @OA\Property(
  132.      *     property="partnerStatus",
  133.      *     nullable=true,
  134.      *     type="string",
  135.      *     enum=OrderPartnerStatus::LABELS,
  136.      *     example="Новый",
  137.      *     description="Статус заказа установленный партнером (Новый, Принят, Выполнен, Отменен)",
  138.      * )
  139.      */
  140.     private ?string $partnerStatus;
  141.     public function __construct(
  142.         BuyerDto $buyer,
  143.         DateTimeImmutable $paidAt,
  144.         PaymentType $paymentType,
  145.         DeviceTypeEnum $deviceType,
  146.         DeliveryType $deliveryType,
  147.         array $composition,
  148.         array $codes,
  149.         float $amount,
  150.         int $orderId,
  151.         ?string $comment,
  152.         ?DateTimeImmutable $preOrderAt,
  153.         ?float $deliveryPrice,
  154.         ?string $address,
  155.         ?string $partnerStatus
  156.     ) {
  157.         $this->buyer $buyer;
  158.         $this->paidAt $paidAt;
  159.         $this->paymentType $paymentType;
  160.         $this->deviceType $deviceType;
  161.         $this->deliveryType $deliveryType;
  162.         $this->composition $composition;
  163.         $this->codes $codes;
  164.         $this->amount $amount;
  165.         $this->orderId $orderId;
  166.         $this->comment $comment;
  167.         $this->preOrderAt $preOrderAt;
  168.         $this->deliveryPrice $deliveryPrice;
  169.         $this->address $address;
  170.         $this->partnerStatus $partnerStatus;
  171.     }
  172.     public function getBuyer(): BuyerDto
  173.     {
  174.         return $this->buyer;
  175.     }
  176.     public function getPaidAt(): DateTimeImmutable
  177.     {
  178.         return $this->paidAt;
  179.     }
  180.     public function getPaymentType(): PaymentType
  181.     {
  182.         return $this->paymentType;
  183.     }
  184.     public function getDeviceType(): DeviceTypeEnum
  185.     {
  186.         return $this->deviceType;
  187.     }
  188.     public function getDeliveryType(): DeliveryType
  189.     {
  190.         return $this->deliveryType;
  191.     }
  192.     public function getComposition(): array
  193.     {
  194.         return $this->composition;
  195.     }
  196.     public function getCodes(): array
  197.     {
  198.         return $this->codes;
  199.     }
  200.     public function getAmount(): float
  201.     {
  202.         return $this->amount;
  203.     }
  204.     public function getOrderId(): int
  205.     {
  206.         return $this->orderId;
  207.     }
  208.     public function getComment(): ?string
  209.     {
  210.         return $this->comment;
  211.     }
  212.     public function getPreOrderAt(): ?DateTimeImmutable
  213.     {
  214.         return $this->preOrderAt;
  215.     }
  216.     public function getDeliveryPrice(): ?float
  217.     {
  218.         return $this->deliveryPrice;
  219.     }
  220.     public function getAddress(): ?string
  221.     {
  222.         return $this->address;
  223.     }
  224.     public function getPartnerStatus(): ?string
  225.     {
  226.         return $this->partnerStatus;
  227.     }
  228.     public function jsonSerialize(): array
  229.     {
  230.         return [
  231.             'buyer' => $this->buyer,
  232.             'paidAt' => $this->paidAt->format('Y-m-d H:i:s'),
  233.             'paymentType' => PaymentType::names()[$this->paymentType->getValue()],
  234.             'deviceType' => DeviceTypeEnum::names()[$this->deviceType->getValue()],
  235.             'deliveryType' => DeliveryType::names()[$this->deliveryType->getValue()],
  236.             'composition' => $this->composition,
  237.             'codes' => $this->codes,
  238.             'amount' => $this->amount,
  239.             'orderId' => $this->orderId,
  240.             'preOrderAt' => null === $this->preOrderAt null $this->preOrderAt->format('Y-m-d H:i:s'),
  241.             'deliveryPrice' => $this->deliveryPrice,
  242.             'address' => $this->address,
  243.             'partnerStatus' => $this->partnerStatus,
  244.         ];
  245.     }
  246. }