src/Entity/Order.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\OrderRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use \Ramsey\Uuid\UuidInterface;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10. * @ORM\Entity(repositoryClass=OrderRepository::class)
  11. * @ORM\Table(name="`order`")
  12. */
  13. class Order
  14. {
  15. const STATUSES = [
  16. 'Не определен' => 'undefined',
  17. 'Создан' => 'created',
  18. 'Успешно' => 'succeeded',
  19. 'Отменен' => 'canceled',
  20. ];
  21. public const STATUS_UNDEFINED = 'undefined';
  22. public const STATUS_CREATED = 'created';
  23. public const STATUS_SUCCEEDED = 'succeeded';
  24. public const STATUS_CANCELED = 'canceled';
  25. public const FIELDS = [
  26. 'Виджет' => 'widgetName',
  27. 'Создан' => 'createdAt',
  28. 'Дата изменения' => 'updatedAt',
  29. 'Кому' => 'recipientType',
  30. 'Способ Отправки' => 'deliveryType',
  31. 'Имя получателя' => 'recipientName',
  32. 'Имя отправителя' => 'senderName',
  33. '№ заказа Тибериума' => 'tiberiumOrderId',
  34. '№ заказа' => 'trackingNumber',
  35. '№ заказа Виджета' => 'widgetOrderId',
  36. 'Статус' => 'getStatusText',
  37. 'E-mail Отправителя' => 'senderEmail',
  38. 'E-mail/Телефон Получателя' => 'recipientEmail',
  39. 'ID Платежа' => 'paymentDataId',
  40. 'Кол-во' => 'quantity',
  41. 'Стоимость руб.' => 'amount',
  42. 'Сумма руб.' => 'summ',
  43. 'Тип создания' => 'type'
  44. ];
  45. public const TYPE_MANUAL = 'manual';
  46. public const TYPE_SENDING = 'sending';
  47. public const TYPES = [
  48. 'Вручную' => self::TYPE_MANUAL,
  49. 'Рассылка' => self::TYPE_SENDING,
  50. ];
  51. /**
  52. * @var UuidInterface $id
  53. * @ORM\Id
  54. * @ORM\Column(type="uuid", unique=true)
  55. * @ORM\GeneratedValue(strategy="CUSTOM")
  56. * @ORM\CustomIdGenerator(class="\Ramsey\Uuid\Doctrine\UuidGenerator")
  57. */
  58. private $id;
  59. /**
  60. * @ORM\ManyToOne(targetEntity=Widget::class, inversedBy="orders", fetch="EAGER", cascade={"persist"})
  61. * @ORM\JoinColumn(nullable=false)
  62. */
  63. private $widget;
  64. /**
  65. * Человекочитаемый номер заказа. Используется для передачи в Кассу при оплате. Передается клиентам в отбивках по заказу
  66. * формат хххх-хххх-хххх
  67. *
  68. * @ORM\Column(type="string", length=50)
  69. */
  70. private ?string $trackingNumber;
  71. /**
  72. * @ORM\Column(type="datetime_immutable")
  73. */
  74. private $createdAt;
  75. /**
  76. * @ORM\Column(type="string", length=255)
  77. * @Assert\Choice(callback="getStatuses", message="Choose a valid status.")
  78. */
  79. private $paymentStatus;
  80. /**
  81. * @ORM\Column(type="datetime_immutable", nullable=true)
  82. */
  83. private $updatedAt;
  84. /**
  85. * @ORM\OneToMany(targetEntity=OrderItem::class, mappedBy="widgetOrder")
  86. */
  87. private $orderItems;
  88. /**
  89. * @ORM\Column(type="string", length=255, nullable=true)
  90. */
  91. private $paymentToken;
  92. /**
  93. * @ORM\Column(type="json", nullable=true)
  94. */
  95. private $paymentData = [];
  96. /**
  97. * @ORM\OneToMany(targetEntity=HistorySend::class, mappedBy="orderId", orphanRemoval=true)
  98. */
  99. private $historySends;
  100. /**
  101. * @ORM\Column(type="string", length=255, nullable=true)
  102. */
  103. private $type;
  104. public function __toString(): string
  105. {
  106. return $this->id->toString();
  107. }
  108. public function __construct()
  109. {
  110. $this->orderItems = new ArrayCollection();
  111. $this->historySends = new ArrayCollection();
  112. }
  113. /**
  114. * @return string[]
  115. */
  116. public function getStatuses(): array
  117. {
  118. return self::STATUSES;
  119. }
  120. public function getId(): ?UuidInterface
  121. {
  122. return $this->id;
  123. }
  124. public function getWidget(): ?Widget
  125. {
  126. return $this->widget;
  127. }
  128. public function setWidget(?Widget $widget): self
  129. {
  130. $this->widget = $widget;
  131. return $this;
  132. }
  133. public function getCreatedAt(): ?\DateTimeImmutable
  134. {
  135. return $this->createdAt;
  136. }
  137. public function setCreatedAt(\DateTimeImmutable $createdAt): self
  138. {
  139. $this->createdAt = $createdAt;
  140. return $this;
  141. }
  142. public function getPaymentStatus(): ?string
  143. {
  144. return $this->paymentStatus;
  145. }
  146. public function setPaymentStatus(string $paymentStatus): self
  147. {
  148. $this->paymentStatus = $paymentStatus;
  149. return $this;
  150. }
  151. public function getStatusText(): ? string
  152. {
  153. return array_search($this->paymentStatus, Order::STATUSES)??self::STATUSES['Не определен'];
  154. }
  155. public function getUpdatedAt(): ?\DateTimeImmutable
  156. {
  157. return $this->updatedAt;
  158. }
  159. public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  160. {
  161. $this->updatedAt = $updatedAt;
  162. return $this;
  163. }
  164. /**
  165. * @return Collection|OrderItem[]
  166. */
  167. public function getOrderItems(): Collection
  168. {
  169. return $this->orderItems;
  170. }
  171. public function addOrderItem(OrderItem $orderItem): self
  172. {
  173. if (!$this->orderItems->contains($orderItem)) {
  174. $this->orderItems[] = $orderItem;
  175. $orderItem->setWidgetOrder($this);
  176. }
  177. return $this;
  178. }
  179. public function removeOrderItem(OrderItem $orderItem): self
  180. {
  181. if ($this->orderItems->removeElement($orderItem)) {
  182. // set the owning side to null (unless already changed)
  183. if ($orderItem->getWidgetOrder() === $this) {
  184. $orderItem->setWidgetOrder(null);
  185. }
  186. }
  187. return $this;
  188. }
  189. public function getPaymentToken(): ?string
  190. {
  191. return $this->paymentToken;
  192. }
  193. public function setPaymentToken(?string $paymentToken): self
  194. {
  195. $this->paymentToken = $paymentToken;
  196. return $this;
  197. }
  198. /**
  199. * @return string[]|null
  200. */
  201. public function getPaymentData(): ?array
  202. {
  203. return $this->paymentData;
  204. }
  205. public function setPaymentData(?array $paymentData): self
  206. {
  207. $this->paymentData = $paymentData;
  208. return $this;
  209. }
  210. /**
  211. * @return Collection|HistorySend[]
  212. */
  213. public function getHistorySends(): Collection
  214. {
  215. return $this->historySends;
  216. }
  217. public function addHistorySend(HistorySend $historySend): self
  218. {
  219. if (!$this->historySends->contains($historySend)) {
  220. $this->historySends[] = $historySend;
  221. $historySend->setOrder($this);
  222. }
  223. return $this;
  224. }
  225. public function removeHistorySend(HistorySend $historySend): self
  226. {
  227. if ($this->historySends->removeElement($historySend)) {
  228. // set the owning side to null (unless already changed)
  229. if ($historySend->getOrder() === $this) {
  230. $historySend->setOrder(null);
  231. }
  232. }
  233. return $this;
  234. }
  235. /**
  236. * @return string|null
  237. */
  238. public function getType(): ?string
  239. {
  240. return $this->type;
  241. }
  242. /**
  243. * @param string|null $type
  244. * @return $this
  245. */
  246. public function setType(?string $type): self
  247. {
  248. if (in_array($type, [self::TYPE_MANUAL, self::TYPE_SENDING, null])) {
  249. $this->type = $type;
  250. }
  251. return $this;
  252. }
  253. /**
  254. * @return bool
  255. */
  256. public function isPaymentSucceeded(): bool
  257. {
  258. return $this->getPaymentStatus() === self::STATUS_SUCCEEDED;
  259. }
  260. /**
  261. * @return string|null
  262. */
  263. public function getTrackingNumber(): ?string
  264. {
  265. return $this->trackingNumber;
  266. }
  267. /**
  268. * @param string|null $trackingNumber
  269. * @return $this
  270. */
  271. public function setTrackingNumber(?string $trackingNumber): self
  272. {
  273. $this->trackingNumber = $trackingNumber;
  274. return $this;
  275. }
  276. }