您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

605 行
18KB

  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Gedmo\Mapping\Annotation as Gedmo;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Lc\ShopBundle\Context\DocumentInterface;
  8. use Lc\ShopBundle\Context\FilterMerchantInterface;
  9. use Lc\ShopBundle\Services\Order\OrderUtils;
  10. use Lc\ShopBundle\Model\OrderStatus ;
  11. /**
  12. * @ORM\MappedSuperclass()
  13. */
  14. abstract class OrderShop extends AbstractEntity implements FilterMerchantInterface
  15. {
  16. /**
  17. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="productFamilies")
  18. * @ORM\JoinColumn(nullable=false)
  19. */
  20. protected $merchant;
  21. /**
  22. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface", inversedBy="orders", fetch="EAGER")
  23. */
  24. protected $user;
  25. /**
  26. * @ORM\ManyToOne(targetEntity="App\Entity\Visitor", inversedBy="orders")
  27. */
  28. protected $visitor;
  29. /**
  30. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\AddressInterface")
  31. */
  32. protected $invoiceAddress;
  33. /**
  34. * @ORM\Column(type="text", nullable=true)
  35. */
  36. protected $invoiceAddressText;
  37. /**
  38. * @ORM\Column(type="datetime", nullable=true)
  39. */
  40. protected $validationDate;
  41. /**
  42. * @ORM\Column(type="text", nullable=true)
  43. */
  44. protected $comment;
  45. /**
  46. * @ORM\Column(type="boolean", nullable=true)
  47. */
  48. protected $autoPayment;
  49. /**
  50. * @ORM\Column(type="string", length=31, nullable=true)
  51. */
  52. protected $meanPayment;
  53. /**
  54. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderStatusHistoryInterface", mappedBy="orderShop", orphanRemoval=true)
  55. */
  56. protected $orderStatusHistories;
  57. /**
  58. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderPaymentInterface", mappedBy="orderShop", orphanRemoval=true)
  59. */
  60. protected $orderPayments;
  61. /**
  62. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderProductInterface", mappedBy="orderShop", cascade={"persist", "remove"}, orphanRemoval=true, fetch="EAGER")
  63. */
  64. protected $orderProducts;
  65. /**
  66. * @ORM\Column(type="text", nullable=true)
  67. */
  68. protected $deliveryInfos;
  69. /**
  70. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\OrderStatusInterface")
  71. * @ORM\JoinColumn(nullable=false)
  72. */
  73. protected $orderStatus;
  74. /**
  75. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderReductionCartInterface", mappedBy="orderShop", orphanRemoval=true)
  76. */
  77. protected $orderReductionCarts;
  78. /**
  79. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderReductionCreditInterface", mappedBy="orderShop", orphanRemoval=true)
  80. */
  81. protected $orderReductionCredits;
  82. /**
  83. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\DocumentInterface", inversedBy="orderShops")
  84. */
  85. protected $documents;
  86. /**
  87. * @Gedmo\Blameable(on="create")
  88. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface")
  89. * @ORM\JoinColumn(nullable=true)
  90. */
  91. protected $createdBy;
  92. /**
  93. * @Gedmo\Blameable(on="update")
  94. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface")
  95. * @ORM\JoinColumn(nullable=true)
  96. */
  97. protected $updatedBy;
  98. /**
  99. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\TicketInterface", mappedBy="orderShop")
  100. */
  101. protected $tickets;
  102. /**
  103. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\SectionInterface", inversedBy="orderShops")
  104. * @ORM\JoinColumn(nullable=false)
  105. */
  106. protected $section;
  107. public function __construct()
  108. {
  109. $this->orderStatusHistories = new ArrayCollection();
  110. $this->orderPayments = new ArrayCollection();
  111. $this->orderProducts = new ArrayCollection();
  112. $this->creditHistories = new ArrayCollection();
  113. $this->orderReductionCarts = new ArrayCollection();
  114. $this->orderReductionCredits = new ArrayCollection();
  115. $this->documents = new ArrayCollection();
  116. }
  117. public function __toString()
  118. {
  119. if($this->getValidationDate()) {
  120. return 'Commande du '.$this->getValidationDate()->format('d/m/Y') ;
  121. }
  122. else {
  123. return 'Commande #'.$this->getId() ;
  124. }
  125. }
  126. public function getValidationDate(): ?\DateTimeInterface
  127. {
  128. return $this->validationDate;
  129. }
  130. public function setValidationDate(\DateTimeInterface $validationDate): self
  131. {
  132. $this->validationDate = $validationDate;
  133. return $this;
  134. }
  135. public function getDateCreated()
  136. {
  137. $orderStatusHistory = $this->getOrderStatusHistory(OrderStatus::ALIAS_WAITING_DELIVERY);
  138. if ($orderStatusHistory) {
  139. return $orderStatusHistory->getCreatedAt();
  140. }
  141. return null;
  142. }
  143. public function getOrderStatusHistory($status)
  144. {
  145. $orderStatusHistories = $this->getOrderStatusHistories();
  146. if (count($orderStatusHistories) > 0) {
  147. foreach ($orderStatusHistories as $orderStatusHistory) {
  148. if ($orderStatusHistory->getOrderStatus() == $status) {
  149. return $orderStatusHistory;
  150. }
  151. }
  152. }
  153. return null;
  154. }
  155. public function getMerchant(): ?Merchant
  156. {
  157. return $this->merchant;
  158. }
  159. public function setMerchant(?Merchant $merchant): self
  160. {
  161. $this->merchant = $merchant;
  162. return $this;
  163. }
  164. public function getUser(): ?User
  165. {
  166. return $this->user;
  167. }
  168. public function setUser(?User $user): self
  169. {
  170. $this->user = $user;
  171. return $this;
  172. }
  173. public function getInvoiceAddress(): ?Address
  174. {
  175. return $this->invoiceAddress;
  176. }
  177. public function setInvoiceAddress(?Address $invoiceAddress): self
  178. {
  179. $this->invoiceAddress = $invoiceAddress;
  180. return $this;
  181. }
  182. public function getInvoiceAddressText(): ?string
  183. {
  184. return $this->invoiceAddressText;
  185. }
  186. public function setInvoiceAddressText(string $invoiceAddressText): self
  187. {
  188. $this->invoiceAddressText = $invoiceAddressText;
  189. return $this;
  190. }
  191. public function getComment(): ?string
  192. {
  193. return $this->comment;
  194. }
  195. public function setComment(?string $comment): self
  196. {
  197. $this->comment = $comment;
  198. return $this;
  199. }
  200. public function getAutoPayment(): ?bool
  201. {
  202. return $this->autoPayment;
  203. }
  204. public function setAutoPayment(bool $autoPayment): self
  205. {
  206. $this->autoPayment = $autoPayment;
  207. return $this;
  208. }
  209. public function getMeanPayment(): ?string
  210. {
  211. return $this->meanPayment;
  212. }
  213. public function setMeanPayment(string $meanPayment): self
  214. {
  215. $this->meanPayment = $meanPayment;
  216. return $this;
  217. }
  218. /**
  219. * @return Collection|OrderStatusHistory[]
  220. */
  221. public function getOrderStatusHistories(): Collection
  222. {
  223. return $this->orderStatusHistories;
  224. }
  225. public function addOrderStatusHistory(OrderStatusHistory $orderStatusHistory): self
  226. {
  227. if (!$this->orderStatusHistories->contains($orderStatusHistory)) {
  228. $this->orderStatusHistories[] = $orderStatusHistory;
  229. $orderStatusHistory->setOrderShop($this);
  230. }
  231. return $this;
  232. }
  233. public function removeOrderStatusHistory(OrderStatusHistory $orderStatusHistory): self
  234. {
  235. if ($this->orderStatusHistories->contains($orderStatusHistory)) {
  236. $this->orderStatusHistories->removeElement($orderStatusHistory);
  237. // set the owning side to null (unless already changed)
  238. if ($orderStatusHistory->getOrderShop() === $this) {
  239. $orderStatusHistory->setOrderShop(null);
  240. }
  241. }
  242. return $this;
  243. }
  244. /**
  245. * @return Collection|OrderPayment[]
  246. */
  247. public function getOrderPayments($meanPayment = null): Collection
  248. {
  249. if($meanPayment) {
  250. $orderPaymentsReturn = new ArrayCollection() ;
  251. foreach($this->orderPayments as $orderPayment) {
  252. if($orderPayment->getMeanPayment() == $meanPayment) {
  253. $orderPaymentsReturn[] = $orderPayment ;
  254. }
  255. }
  256. return $orderPaymentsReturn ;
  257. }
  258. return $this->orderPayments;
  259. }
  260. public function addOrderPayment(OrderPayment $orderPayment): self
  261. {
  262. if (!$this->orderPayments->contains($orderPayment)) {
  263. $this->orderPayments[] = $orderPayment;
  264. $orderPayment->setOrderShop($this);
  265. }
  266. return $this;
  267. }
  268. public function removeOrderPayment(OrderPayment $orderPayment): self
  269. {
  270. if ($this->orderPayments->contains($orderPayment)) {
  271. $this->orderPayments->removeElement($orderPayment);
  272. // set the owning side to null (unless already changed)
  273. if ($orderPayment->getOrderShop() === $this) {
  274. $orderPayment->setOrderShop(null);
  275. }
  276. }
  277. return $this;
  278. }
  279. /**
  280. * @return Collection|OrderProduct[]
  281. */
  282. public function getOrderProducts(): Collection
  283. {
  284. return $this->orderProducts;
  285. }
  286. public function addOrderProduct(OrderProduct $orderProduct): self
  287. {
  288. if (!$this->orderProducts->contains($orderProduct)) {
  289. $this->orderProducts[] = $orderProduct;
  290. $orderProduct->setOrderShop($this);
  291. }
  292. return $this;
  293. }
  294. public function removeOrderProduct(OrderProduct $orderProduct): self
  295. {
  296. if ($this->orderProducts->contains($orderProduct)) {
  297. $this->orderProducts->removeElement($orderProduct);
  298. // set the owning side to null (unless already changed)
  299. if ($orderProduct->getOrderShop() === $this) {
  300. $orderProduct->setOrderShop(null);
  301. }
  302. }
  303. return $this;
  304. }
  305. /**
  306. * @return Collection|CreditHistory[]
  307. */
  308. public function getCreditHistories(): Collection
  309. {
  310. return $this->creditHistories;
  311. }
  312. public function addCreditHistory(CreditHistory $creditHistory): self
  313. {
  314. if (!$this->creditHistories->contains($creditHistory)) {
  315. $this->creditHistories[] = $creditHistory;
  316. $creditHistory->setOrderShop($this);
  317. }
  318. return $this;
  319. }
  320. public function removeCreditHistory(CreditHistory $creditHistory): self
  321. {
  322. if ($this->creditHistories->contains($creditHistory)) {
  323. $this->creditHistories->removeElement($creditHistory);
  324. // set the owning side to null (unless already changed)
  325. if ($creditHistory->getOrderShop() === $this) {
  326. $creditHistory->setOrderShop(null);
  327. }
  328. }
  329. return $this;
  330. }
  331. public function getVisitor(): ?Visitor
  332. {
  333. return $this->visitor;
  334. }
  335. public function setVisitor(?Visitor $visitor): self
  336. {
  337. $this->visitor = $visitor;
  338. return $this;
  339. }
  340. public function getDeliveryInfos(): ?string
  341. {
  342. return $this->deliveryInfos;
  343. }
  344. public function setDeliveryInfos(?string $deliveryInfos): self
  345. {
  346. $this->deliveryInfos = $deliveryInfos;
  347. return $this;
  348. }
  349. public function getOrderStatus(): ?OrderStatus
  350. {
  351. return $this->orderStatus;
  352. }
  353. public function setOrderStatusProtected(?OrderStatus $orderStatus): self
  354. {
  355. $this->orderStatus = $orderStatus;
  356. return $this;
  357. }
  358. /**
  359. * @return Collection|OrderReductionCart[]
  360. */
  361. public function getOrderReductionCarts(): Collection
  362. {
  363. return $this->orderReductionCarts;
  364. }
  365. public function addOrderReductionCart(OrderReductionCart $orderReductionCart): self
  366. {
  367. if (!$this->orderReductionCarts->contains($orderReductionCart)) {
  368. $this->orderReductionCarts[] = $orderReductionCart;
  369. $orderReductionCart->setOrderShop($this);
  370. }
  371. return $this;
  372. }
  373. public function removeOrderReductionCart(OrderReductionCart $orderReductionCart): self
  374. {
  375. if ($this->orderReductionCarts->contains($orderReductionCart)) {
  376. $this->orderReductionCarts->removeElement($orderReductionCart);
  377. // set the owning side to null (unless already changed)
  378. if ($orderReductionCart->getOrderShop() === $this) {
  379. $orderReductionCart->setOrderShop(null);
  380. }
  381. }
  382. return $this;
  383. }
  384. /**
  385. * @return Collection|OrderReductionCart[]
  386. */
  387. public function getOrderReductionCredits(): Collection
  388. {
  389. return $this->orderReductionCredits;
  390. }
  391. public function addOrderReductionCredit(OrderReductionCredit $orderReductionCredit): self
  392. {
  393. if (!$this->orderReductionCredits->contains($orderReductionCredit)) {
  394. $this->orderReductionCredits[] = $orderReductionCredit;
  395. $orderReductionCredit->setOrderShop($this);
  396. }
  397. return $this;
  398. }
  399. public function removeOrderReductionCredit(OrderReductionCredit $orderReductionCredit): self
  400. {
  401. if ($this->orderReductionCredits->contains($orderReductionCredit)) {
  402. $this->orderReductionCredits->removeElement($orderReductionCredit);
  403. // set the owning side to null (unless already changed)
  404. if ($orderReductionCredit->getOrderShop() === $this) {
  405. $orderReductionCredit->setOrderShop(null);
  406. }
  407. }
  408. return $this;
  409. }
  410. /**
  411. * @return Collection|Document[]
  412. */
  413. public function getDocuments(): Collection
  414. {
  415. return $this->documents;
  416. }
  417. public function addDocument(Document $document): self
  418. {
  419. if (!$this->documents->contains($document)) {
  420. $this->documents[] = $document;
  421. }
  422. return $this;
  423. }
  424. public function removeDocument(Document $document): self
  425. {
  426. if ($this->documents->contains($document)) {
  427. $this->documents->removeElement($document);
  428. }
  429. return $this;
  430. }
  431. public function getDocumentInvoice(): Document
  432. {
  433. foreach($this->getDocuments() as $document) {
  434. if($document->getType() == Document::TYPE_INVOICE) {
  435. return $document ;
  436. }
  437. }
  438. return false ;
  439. }
  440. /**
  441. * @return Collection|Ticket[]
  442. */
  443. public function getTickets(): Collection
  444. {
  445. return $this->tickets;
  446. }
  447. public function addTicket(Ticket $ticket): self
  448. {
  449. if (!$this->tickets->contains($ticket)) {
  450. $this->tickets[] = $ticket;
  451. $ticket->setOrderShop($this);
  452. }
  453. return $this;
  454. }
  455. public function removeTicket(Ticket $ticket): self
  456. {
  457. if ($this->tickets->contains($ticket)) {
  458. $this->tickets->removeElement($ticket);
  459. // set the owning side to null (unless already changed)
  460. if ($ticket->getOrderShop() === $this) {
  461. $ticket->setOrderShop(null);
  462. }
  463. }
  464. return $this;
  465. }
  466. public function isValid() {
  467. if($this->getOrderStatus() && in_array($this->getOrderStatus()->getAlias(), OrderStatus::$statusAliasAsValid) > 0) {
  468. return true ;
  469. }
  470. return false ;
  471. }
  472. public function isCart() {
  473. if($this->getOrderStatus() && in_array($this->getOrderStatus()->getAlias(), OrderStatus::$statusAliasAsCart) > 0) {
  474. return true ;
  475. }
  476. return false ;
  477. }
  478. public function getSection(): ?Section
  479. {
  480. return $this->section;
  481. }
  482. public function setSection(?Section $section): self
  483. {
  484. $this->section = $section;
  485. return $this;
  486. }
  487. }