From ccbf892e79c682a2cfad0df02388d3dec3b87179 Mon Sep 17 00:00:00 2001 From: n1rwana Date: Thu, 3 Aug 2023 18:56:19 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BE=D0=BF=D1=80=D0=BE=D1=81=20=D0=BE?= =?UTF-8?q?=D1=82=20=D0=9F=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Web/Models/Entities/SupportAgent.php | 7 +++- Web/Models/Entities/Ticket.php | 11 ++++++ Web/Models/Entities/User.php | 2 +- Web/Presenters/SupportPresenter.php | 35 +++++++++++++++++- .../templates/Support/AnswerTicket.xml | 11 +++++- Web/Presenters/templates/Support/View.xml | 11 ++++-- Web/Presenters/templates/User/View.xml | 37 +++++++++++++++++++ Web/routes.yml | 2 + .../00038-support-tickets-from-agents.sql | 2 + locales/en.strings | 2 + locales/ru.strings | 1 + 11 files changed, 112 insertions(+), 9 deletions(-) create mode 100644 install/sqls/00038-support-tickets-from-agents.sql diff --git a/Web/Models/Entities/SupportAgent.php b/Web/Models/Entities/SupportAgent.php index 2f7fc21b..00f06457 100644 --- a/Web/Models/Entities/SupportAgent.php +++ b/Web/Models/Entities/SupportAgent.php @@ -32,8 +32,13 @@ class SupportAgent extends RowModel return $this->getRecord()->numerate; } + function getUser(): User + { + return (new Users)->get((int) $this->getAgentId()); + } + function getRealName(): string { - return (new Users)->get($this->getAgentId())->getCanonicalName(); + return $this->getUser()->getCanonicalName(); } } \ No newline at end of file diff --git a/Web/Models/Entities/Ticket.php b/Web/Models/Entities/Ticket.php index 31690ce3..f197cf6e 100644 --- a/Web/Models/Entities/Ticket.php +++ b/Web/Models/Entities/Ticket.php @@ -1,5 +1,6 @@ get((int) $this->getRecord()->support_sender); + } + + function isFromSupport(): bool + { + return $this->getSupportSender() !== NULL; + } + use Traits\TRichText; } diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index 348631e4..0653cd2b 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -1031,7 +1031,7 @@ class User extends RowModel function adminNotify(string $message): bool { - $admId = OPENVK_ROOT_CONF["openvk"]["preferences"]["support"]["adminAccount"]; + $admId = (int) OPENVK_ROOT_CONF["openvk"]["preferences"]["support"]["adminAccount"]; if(!$admId) return false; else if(is_null($admin = (new Users)->get($admId))) diff --git a/Web/Presenters/SupportPresenter.php b/Web/Presenters/SupportPresenter.php index c4d729ea..251076a2 100644 --- a/Web/Presenters/SupportPresenter.php +++ b/Web/Presenters/SupportPresenter.php @@ -152,7 +152,7 @@ final class SupportPresenter extends OpenVKPresenter if(!empty($id)) { $ticket = $this->tickets->get($id); - if(!$ticket || $ticket->isDeleted() != 0 || $ticket->getUserId() !== $this->user->id && !$this->hasPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0)) { + if(!$ticket || $ticket->isDeleted() != 0 || (($ticket->getUserId() !== $this->user->id || $ticket->isFromSupport()) && !$this->hasPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0))) { $this->notFound(); } else { if($ticket->getUserId() !== $this->user->id && $this->hasPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0)) @@ -396,4 +396,37 @@ final class SupportPresenter extends OpenVKPresenter $this->flashFail("succ", "Успех", "Профиль создан. Теперь пользователи видят Ваши псевдоним и аватарку вместо стандартных аватарки и номера."); } } + + function renderSendUserTicket(): void + { + $this->assertPermission("openvk\Web\Models\Entities\TicketReply", "write", 0); + $this->assertNoCSRF(); + + if (!$this->postParam("uid") || !$this->postParam("text")) + $this->returnJson(["success" => false, "error" => "Один или несколько обязательных параметров не были переданы"]); + + $user = (new Users)->get((int) $this->postParam("uid")); + if (!$user) $this->returnJson(["success" => false, "error" => "Пользователь не найден"]); + + $ticket = new Ticket; + $ticket->setType(1); + $ticket->setUser_Id($user->getId()); + $ticket->setName("[Вопрос от Поддержки]" . ($this->postParam("title") ? " " . $this->postParam("title") : "")); + $ticket->setText($this->postParam("text")); + $ticket->setCreated(time()); + $ticket->setSupport_Sender($this->user->id); + $ticket->save(); + + $comment = new TicketComment; + $comment->setUser_Id($this->user->id); + $comment->setUser_Type(1); + $comment->setText($this->postParam("text")); + $comment->setCreated(time()); + $comment->setTicket_Id($ticket->getId()); + $comment->save(); + + $user->adminNotify(($user->isFemale() ? "Дорогая " : "Дорогой ") . $user->getFirstName() . "!\n\nВы получили новый вопрос (https://$_SERVER[SERVER_NAME]/support/view/{$ticket->getId()}) от Команды Поддержки " . OPENVK_ROOT_CONF["openvk"]["appearance"]["name"]); + + $this->returnJson(["success" => true, "payload" => $ticket->getId()]); + } } diff --git a/Web/Presenters/templates/Support/AnswerTicket.xml b/Web/Presenters/templates/Support/AnswerTicket.xml index 7f577f9d..841fe69b 100644 --- a/Web/Presenters/templates/Support/AnswerTicket.xml +++ b/Web/Presenters/templates/Support/AnswerTicket.xml @@ -8,9 +8,16 @@ {block content}
{$ticket->getName()}
- {_author}: {$ticket->getUser()->getFullName()} | {$ticket->getUser()->getRegistrationIP()} | {_status}: {$ticket->getStatus()}. + {$ticket->isFromSupport() ? tr("user") : tr("author")}: {$ticket->getUser()->getFullName()} + {if $ticket->isFromSupport()} + | {_author}: + + {$ticket->getSupportSender()->getUser()->getCanonicalName()} + + {/if} + | {$ticket->getUser()->getRegistrationIP()} | {_status}: {$ticket->getStatus()}.
-
+
{$ticket->getText()|noescape}

diff --git a/Web/Presenters/templates/Support/View.xml b/Web/Presenters/templates/Support/View.xml index b239c351..308fdc60 100644 --- a/Web/Presenters/templates/Support/View.xml +++ b/Web/Presenters/templates/Support/View.xml @@ -34,13 +34,16 @@ {$ticket->getName()}
{_status}: {$ticket->getStatus()}
-
+
{$ticket->getText()|noescape} -

+

- {$ticket->getTime()} |  - {_delete} + {$ticket->getTime()} + +  |  + {_delete} +
{if $ticket->getType() !== 2}
diff --git a/Web/Presenters/templates/User/View.xml b/Web/Presenters/templates/User/View.xml index 1fa71026..a4f691fa 100644 --- a/Web/Presenters/templates/User/View.xml +++ b/Web/Presenters/templates/User/View.xml @@ -128,6 +128,9 @@ {_ban_in_support_user_action} {/if} + + Вопрос от Поддержки + {/if} {_send_gift} @@ -688,6 +691,40 @@ ]); } {/if} + + function newSupportTicketToUser() { + uTicketMsgTxt = "Вы собираетесь связаться с пользователем " + {$user->getCanonicalName()} + " от имени Поддержки. Он получит об этом оповещение от имени служебного аккаунта."; + uTicketMsgTxt += "

Название: "; + uTicketMsgTxt += "

Текст: "; + + MessageBox("Отправить вопрос", uTicketMsgTxt, ["Отправить", "Отмена"], [ + (function () { + title = $("#uTicketTitle").val(); + text = $("#uTicketText").val() + + $.ajax({ + type: "POST", + url: "/al_helpdesk/sendTicket", + data: { + uid: {$user->getId()}, + title: title, + text: text, + hash: {=$csrfToken} + }, + success: (response) => { + if (response.success) { + MessageBox("Успех", "Пользователь получил вопрос и оповещения

Перейти к вопросу", ["OK"], [Function.noop]); + } else { + MessageBox("Ошибка", "При отправке запроса произошла ошибка: " + (response?.error ?? "Неизвестная ошибка"), ["OK"], [Function.noop]); + } + } + }) + }), + Function.noop + ]) + + $(".ovk-diag-cont").width("650px"); + }