Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

86 linhas
3.1KB

  1. <?php
  2. namespace Lc\ShopBundle\Services ;
  3. use App\Entity\TicketMessage;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Lc\ShopBundle\Context\MerchantUtilsInterface;
  6. use Lc\ShopBundle\Context\OrderShopInterface;
  7. use Lc\ShopBundle\Context\TicketInterface;
  8. use Lc\ShopBundle\Context\TicketMessageInterface;
  9. use Lc\ShopBundle\Model\Ticket;
  10. class TicketUtils
  11. {
  12. protected $em ;
  13. protected $merchantUtils ;
  14. public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils)
  15. {
  16. $this->em = $em ;
  17. $this->merchantUtils = $merchantUtils ;
  18. }
  19. public function createTicket($params): TicketInterface
  20. {
  21. $classTicket = $this->em->getClassMetadata(TicketInterface::class)->getName() ;
  22. $ticket = new $classTicket ;
  23. $ticket->setMerchant($this->merchantUtils->getMerchantCurrent()) ;
  24. $ticket->setStatus(1) ;
  25. if(isset($params['user'])) {
  26. $ticket->setUser($params['user']) ;
  27. }
  28. else {
  29. $ticket->setVisitorFirstname($params['visitorFirstname']) ;
  30. $ticket->setVisitorLastname($params['visitorLastname']) ;
  31. $ticket->setVisitorEmail($params['visitorEmail']) ;
  32. $ticket->setVisitorToken(uniqid()) ;
  33. }
  34. $ticket->setTicketStatus(Ticket::TICKET_STATUS_OPEN) ;
  35. $ticket->setType($params['type']) ;
  36. if(isset($params['orderShop']) && $params['orderShop'] && $params['orderShop'] instanceof OrderShopInterface) {
  37. $ticket->setOrderShop($params['orderShop']) ;
  38. }
  39. $ticket->setSubject($params['subject']) ;
  40. $this->em->persist($ticket);
  41. $classTicketMessage = $this->em->getClassMetadata(TicketMessageInterface::class)->getName() ;
  42. $ticketMessage = new $classTicketMessage ;
  43. $ticketMessage->setStatus(1) ;
  44. $ticketMessage->setTicket($ticket) ;
  45. $ticketMessage->setMessage($params['message']) ;
  46. $this->em->persist($ticketMessage);
  47. $this->em->flush() ;
  48. return $ticket ;
  49. }
  50. public function createTicketMessage($params)
  51. {
  52. $classTicketMessage = $this->em->getClassMetadata(TicketMessageInterface::class)->getName() ;
  53. $ticketMessage = new $classTicketMessage ;
  54. $ticket = $params['ticket'] ;
  55. $ticketMessage->setStatus(1) ;
  56. $ticketMessage->setTicket($ticket) ;
  57. $ticketMessage->setMessage($params['message']) ;
  58. $this->em->persist($ticketMessage);
  59. if(isset($params['closeTicket']) && $params['closeTicket']) {
  60. $ticket->setTicketStatus(Ticket::TICKET_STATUS_CLOSED) ;
  61. }
  62. $ticket->setUpdatedAt(new \DateTime()) ;
  63. $this->em->persist($ticket);
  64. $this->em->flush() ;
  65. return $ticketMessage ;
  66. }
  67. }