diff --git a/hesabixCore/src/Controller/SupportController.php b/hesabixCore/src/Controller/SupportController.php new file mode 100644 index 0000000..d56487b --- /dev/null +++ b/hesabixCore/src/Controller/SupportController.php @@ -0,0 +1,218 @@ +getRepository(Support::class)->findBy(['main' => 0], ['id' => 'DESC']); + $res = []; + foreach ($items as $item) { + $res[] = Explore::ExploreSupportTicket($item, $this->getUser()); + } + return $this->json($extractor->operationSuccess($res)); + } + #[Route('/api/admin/support/view/{id}', name: 'app_admin_support_view')] + public function app_admin_support_view(Extractor $extractor, Jdate $jdate, EntityManagerInterface $entityManager, string $id = ''): JsonResponse + { + $item = $entityManager->getRepository(Support::class)->find($id); + if (!$item) + throw $this->createNotFoundException(); + $replays = $entityManager->getRepository(Support::class)->findBy(['main' => $item->getId()]); + $res = []; + foreach ($replays as $replay) { + if ($replay->getSubmitter() == $this->getUser()) + $replay->setState(1); + else + $replay->setState(0); + $res[] = Explore::ExploreSupportTicket($replay, $this->getUser()); + } + return $this->json( + $extractor->operationSuccess([ + 'item' => Explore::ExploreSupportTicket($item, $this->getUser()), + 'replays' => $res + ]) + ); + } + #[Route('/api/admin/support/mod/{id}', name: 'app_admin_support_mod')] + public function app_admin_support_mod(registryMGR $registryMGR, SMS $SMS, Request $request, EntityManagerInterface $entityManager, Notification $notifi, string $id = ''): JsonResponse + { + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + + $item = $entityManager->getRepository(Support::class)->find($id); + if (!$item) + $this->createNotFoundException(); + if (array_key_exists('body', $params)) { + $support = new Support(); + $support->setDateSubmit(time()); + $support->setTitle('0'); + $support->setBody($params['body']); + $support->setState('0'); + $support->setMain($item->getId()); + $support->setSubmitter($this->getUser()); + $entityManager->persist($support); + $entityManager->flush(); + $item->setState('پاسخ داده شده'); + $entityManager->persist($support); + $entityManager->flush(); + //send sms to customer + if ($item->getSubmitter()->getMobile()) { + $SMS->send( + [$item->getId()], + $registryMGR->get('sms', 'ticketReplay'), + $item->getSubmitter()->getMobile() + ); + } + //send notification to user + $settings = $entityManager->getRepository(Settings::class)->findAll()[0]; + $url = '/profile/support-view/' . $item->getId(); + $notifi->insert("به درخواست پشتیبانی پاسخ داده شد", $url, null, $item->getSubmitter()); + return $this->json([ + 'error' => 0, + 'message' => 'successful' + ]); + } + return $this->json([ + 'error' => 999, + 'message' => 'تمام موارد لازم را وارد کنید.' + ]); + } + #[Route('/api/support/list', name: 'app_support_list')] + public function app_support_list(Jdate $jdate, EntityManagerInterface $entityManager): JsonResponse + { + $items = $entityManager->getRepository(Support::class)->findBy( + [ + 'submitter' => $this->getUser(), + 'main' => 0 + ], + [ + 'id' => 'DESC' + ] + ); + foreach ($items as $item) { + $item->setDateSubmit($jdate->jdate('Y/n/d', $item->getDateSubmit())); + } + return $this->json($items); + } + + #[Route('/api/support/mod/{id}', name: 'app_support_mod')] + public function app_support_mod(registryMGR $registryMGR, SMS $SMS, Request $request, EntityManagerInterface $entityManager, string $id = ''): JsonResponse + { + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + if ($id == '') { + if (array_key_exists('title', $params) && array_key_exists('body', $params)) { + $item = new Support(); + $item->setBody($params['body']); + $item->setTitle($params['title']); + $item->setDateSubmit(time()); + $item->setSubmitter($this->getUser()); + $item->setMain(0); + $item->setCode($this->RandomString(8)); + $item->setState('در حال پیگیری'); + $entityManager->persist($item); + $entityManager->flush(); + //send sms to manager + $SMS->send( + [$item->getId()], + $registryMGR->get('sms', 'ticketRec'), + $registryMGR->get('ticket', 'managerMobile') + ); + + return $this->json([ + 'error' => 0, + 'message' => 'ok', + 'url' => $item->getId() + ]); + } + } else { + if (array_key_exists('body', $params)) { + $item = new Support(); + $upper = $entityManager->getRepository(Support::class)->find($id); + if ($upper) + $item->setMain($upper->getid()); + + $item->setBody($params['body']); + $item->setTitle($upper->getTitle()); + $item->setDateSubmit(time()); + $item->setSubmitter($this->getUser()); + $item->setState('در حال پیگیری'); + $entityManager->persist($item); + $entityManager->flush(); + $upper->setState('در حال پیگیری'); + $entityManager->persist($upper); + $entityManager->flush(); + //send sms to manager + $SMS->send( + [$item->getId()], + $registryMGR->get('sms', 'ticketRec'), + $registryMGR->get('ticket', 'managerMobile') + ); + return $this->json([ + 'error' => 0, + 'message' => 'ok', + 'url' => $item->getId() + ]); + } + } + + return $this->json([ + 'error' => 999, + 'message' => 'تمام موارد لازم را وارد کنید.' + ]); + } + + #[Route('/api/support/view/{id}', name: 'app_support_view')] + public function app_support_view(Jdate $jdate, EntityManagerInterface $entityManager, string $id = ''): JsonResponse + { + $item = $entityManager->getRepository(Support::class)->find($id); + if (!$item) + throw $this->createNotFoundException(); + if ($item->getSubmitter() != $this->getUser()) + throw $this->createAccessDeniedException(); + $replays = $entityManager->getRepository(Support::class)->findBy(['main' => $item->getId()]); + $replaysArray = []; + foreach ($replays as $replay) { + $replaysArray[] = Explore::ExploreSupportTicket($replay, $this->getUser()); + } + return $this->json([ + 'item' => Explore::ExploreSupportTicket($item, $this->getUser()), + 'replays' => $replaysArray + ]); + } +} diff --git a/hesabixCore/src/Entity/Support.php b/hesabixCore/src/Entity/Support.php new file mode 100644 index 0000000..85ee98b --- /dev/null +++ b/hesabixCore/src/Entity/Support.php @@ -0,0 +1,129 @@ +id; + } + + public function getMain(): ?string + { + return $this->main; + } + + public function setMain(?string $main): self + { + $this->main = $main; + + return $this; + } + + public function getSubmitter(): ?User + { + return $this->submitter; + } + + public function setSubmitter(?User $submitter): self + { + $this->submitter = $submitter; + + return $this; + } + + public function getDateSubmit(): ?string + { + return $this->dateSubmit; + } + + public function setDateSubmit(string $dateSubmit): self + { + $this->dateSubmit = $dateSubmit; + + return $this; + } + + public function getTitle(): ?string + { + return $this->title; + } + + public function setTitle(string $title): self + { + $this->title = $title; + + return $this; + } + + public function getBody(): ?string + { + return $this->body; + } + + public function setBody(string $body): self + { + $this->body = $body; + + return $this; + } + + public function getState(): ?string + { + return $this->state; + } + + public function setState(string $state): self + { + $this->state = $state; + + return $this; + } + + public function getCode(): ?string + { + return $this->code; + } + + public function setCode(?string $code): static + { + $this->code = $code; + + return $this; + } +} diff --git a/hesabixCore/src/Entity/User.php b/hesabixCore/src/Entity/User.php index aa2bfe5..73739be 100644 --- a/hesabixCore/src/Entity/User.php +++ b/hesabixCore/src/Entity/User.php @@ -41,9 +41,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\OneToMany(mappedBy: 'owner', targetEntity: Business::class, orphanRemoval: true)] private Collection $businesses; - #[ORM\OneToMany(mappedBy: 'submitter', targetEntity: StackContent::class, orphanRemoval: true)] - private Collection $stackContents; - #[ORM\OneToMany(mappedBy: 'user', targetEntity: Log::class)] private Collection $logs; @@ -114,7 +111,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface { $this->userTokens = new ArrayCollection(); $this->businesses = new ArrayCollection(); - $this->stackContents = new ArrayCollection(); $this->logs = new ArrayCollection(); $this->permissions = new ArrayCollection(); $this->hesabdariDocs = new ArrayCollection(); @@ -288,36 +284,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this; } - /** - * @return Collection - */ - public function getStackContents(): Collection - { - return $this->stackContents; - } - - public function addStackContent(StackContent $stackContent): self - { - if (!$this->stackContents->contains($stackContent)) { - $this->stackContents->add($stackContent); - $stackContent->setSubmitter($this); - } - - return $this; - } - - public function removeStackContent(StackContent $stackContent): self - { - if ($this->stackContents->removeElement($stackContent)) { - // set the owning side to null (unless already changed) - if ($stackContent->getSubmitter() === $this) { - $stackContent->setSubmitter(null); - } - } - - return $this; - } - /** * @return Collection */ diff --git a/hesabixCore/src/Repository/SupportRepository.php b/hesabixCore/src/Repository/SupportRepository.php new file mode 100644 index 0000000..8c3175f --- /dev/null +++ b/hesabixCore/src/Repository/SupportRepository.php @@ -0,0 +1,66 @@ + + * + * @method Support|null find($id, $lockMode = null, $lockVersion = null) + * @method Support|null findOneBy(array $criteria, array $orderBy = null) + * @method Support[] findAll() + * @method Support[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class SupportRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Support::class); + } + + public function save(Support $entity, bool $flush = false): void + { + $this->getEntityManager()->persist($entity); + + if ($flush) { + $this->getEntityManager()->flush(); + } + } + + public function remove(Support $entity, bool $flush = false): void + { + $this->getEntityManager()->remove($entity); + + if ($flush) { + $this->getEntityManager()->flush(); + } + } + +// /** +// * @return Support[] Returns an array of Support objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('s') +// ->andWhere('s.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('s.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?Support +// { +// return $this->createQueryBuilder('s') +// ->andWhere('s.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +} diff --git a/hesabixCore/src/Service/SMS.php b/hesabixCore/src/Service/SMS.php index 9e99b0f..ad9b930 100644 --- a/hesabixCore/src/Service/SMS.php +++ b/hesabixCore/src/Service/SMS.php @@ -18,7 +18,7 @@ class SMS /** * @param EntityManagerInterface $entityManager */ - public function __construct(EntityManagerInterface $entityManager,registryMGR $registryMGR) + public function __construct(EntityManagerInterface $entityManager, registryMGR $registryMGR) { $this->entityManager = $entityManager; $this->registryMGR = $registryMGR; @@ -26,54 +26,67 @@ class SMS } - public function send(array $params,$bodyID,$to): void + public function send(array $params, $bodyID, $to): void { - if($this->registryMGR->get('sms','plan') == 'melipayamak'){ - try{ - $username = $this->registryMGR->get('sms','username'); - $password = $this->registryMGR->get('sms','password'); - $api = new MelipayamakApi($username,$password); - $sms = $api->sms('soap'); - $response = $sms->sendByBaseNumber($params,$to,$bodyID); - $json = json_decode($response); - - }catch(\Exception $e){ - echo $e->getMessage(); - die(); - } + if ($this->registryMGR->get('sms', 'plan') == 'melipayamak') { + try { + $username = $this->registryMGR->get('sms', 'username'); + $password = $this->registryMGR->get('sms', 'password'); + $api = new MelipayamakApi($username, $password); + $sms = $api->sms('soap'); + $response = $sms->sendByBaseNumber($params, $to, $bodyID); + $json = json_decode($response); - } - elseif($this->registryMGR->get('sms','plan') == 'idepayam'){ + } catch (\Exception $e) { + echo $e->getMessage(); + die(); + } + + } elseif ($this->registryMGR->get('sms', 'plan') == 'idepayam') { ini_set("soap.wsdl_cache_enabled", "0"); - + //create next $pt = []; - foreach($params as $param){ - $pt['{' . strval(array_search($param,$params)) . '}'] = $param; + foreach ($params as $param) { + $pt['{' . strval(array_search($param, $params)) . '}'] = $param; } $soap = new \SoapClient("http://185.112.33.61/wbs/send.php?wsdl"); - $soap->token = $this->registryMGR->get('sms','token'); - $soap->fromNum = $this->registryMGR->get('sms','fromNum'); + $soap->token = $this->registryMGR->get('sms', 'token'); + $soap->fromNum = $this->registryMGR->get('sms', 'fromNum'); $soap->toNum = array($to); $soap->patternID = $bodyID; - $soap->Content = json_encode($pt,JSON_UNESCAPED_UNICODE); + $soap->Content = json_encode($pt, JSON_UNESCAPED_UNICODE); $soap->Type = 0; $array = $soap->SendSMSByPattern($soap->fromNum, $soap->toNum, $soap->Content, $soap->patternID, $soap->Type, $soap->token); - + + } elseif ($this->registryMGR->get('sms', 'plan') == 'ippanel') { + $toArray = [$to]; + $username = $this->registryMGR->get('sms', 'username'); + $password = $this->registryMGR->get('sms', 'password'); + $from = $this->registryMGR->get('sms', 'fromNum'); + $input_data = []; + foreach ($params as $param) { + $input_data['%' . strval(array_search($param, $params)) . '%'] = $param; + } + $url = "https://ippanel.com/patterns/pattern?username=" . $username . "&password=" . urlencode($password) . "&from=$from&to=" . json_encode($toArray) . "&input_data=" . urlencode(json_encode($input_data)) . "&pattern_code=$bodyID"; + $handler = curl_init($url); + curl_setopt($handler, CURLOPT_CUSTOMREQUEST, "POST"); + curl_setopt($handler, CURLOPT_POSTFIELDS, $input_data); + curl_setopt($handler, CURLOPT_RETURNTRANSFER, true); + $response = curl_exec($handler); } - } - public function sendByBalance(array $params,$bodyID,$to,Business $business,User $user,$balance = 500): int + public function sendByBalance(array $params, $bodyID, $to, Business $business, User $user, $balance = 500): int { - if($business->getSmsCharge() < ($balance * $this->smsPrice)) - return 2; - $this->send($params,$bodyID,$to); - $business->setSmsCharge($business->getSmsCharge() - ($balance * $this->smsPrice)); - $this->entityManager->persist($business); - $this->entityManager->flush(); - //save logs + if ($business->getSmsCharge() < ($balance * $this->smsPrice)) + return 2; + $this->send($params, $bodyID, $to); + $business->setSmsCharge($business->getSmsCharge() - ($balance * $this->smsPrice)); + $this->entityManager->persist($business); + $this->entityManager->flush(); + //save logs $log = new \App\Entity\Log(); $log->setBid($business); $log->setDateSubmit(time()); @@ -82,7 +95,7 @@ class SMS $log->setDes('ارسال پیامک به طول ' . $balance . ' پیامک به شماره ' . $to . ' با شماره الگو ' . $bodyID . ' هزینه: ' . ($this->smsPrice * $balance) . ' ریال '); $this->entityManager->persist($log); $this->entityManager->flush(); - return 1; + return 1; } } \ No newline at end of file