Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

90 lines
3.3KB

  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->setStatus(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. if(isset($params['answerByAdmin']) && $params['answerByAdmin']) {
  59. $ticketMessage->setAnswerByAdmin($params['answerByAdmin']) ;
  60. }
  61. $this->em->persist($ticketMessage);
  62. if(isset($params['closeTicket']) && $params['closeTicket']) {
  63. $ticket->setTicketStatus(Ticket::TICKET_STATUS_CLOSED) ;
  64. }
  65. $ticket->setUpdatedAt(new \DateTime()) ;
  66. $this->em->persist($ticket);
  67. $this->em->flush() ;
  68. return $ticketMessage ;
  69. }
  70. }