Fix TicketReplied Notification using wrong ticket info

This commit is contained in:
兔姬桑
2021-07-14 22:43:02 +08:00
parent 3ab38d18f0
commit 9bb3e65db0
5 changed files with 24 additions and 25 deletions

View File

@@ -64,13 +64,14 @@ class TicketController extends Controller
{
$content = substr(str_replace(['atob', 'eval'], '', clean($request->input('content'))), 0, 300);
if ($ticket->reply()->create(['admin_id' => Auth::id(), 'content' => $content])) {
$reply = $ticket->reply()->create(['admin_id' => Auth::id(), 'content' => $content]);
if ($reply) {
// 将工单置为已回复
$ticket->update(['status' => 1]);
// 通知用户
if (sysConfig('ticket_replied_notification')) {
$ticket->user->notify(new TicketReplied($ticket, route('replyTicket', $ticket), true));
$ticket->user->notify(new TicketReplied($reply, route('replyTicket', $ticket), true));
}
return Response::json(['status' => 'success', 'message' => '回复成功']);

View File

@@ -312,14 +312,14 @@ class UserController extends Controller
if ($ticket->status === 2) {
return Response::json(['status' => 'fail', 'message' => trans('user.ticket.failed_closed')]);
}
if ($ticket->reply()->create(['user_id' => auth()->id(), 'content' => $content])) {
$reply = $ticket->reply()->create(['user_id' => auth()->id(), 'content' => $content]);
if ($reply) {
// 重新打开工单
$ticket->status = 0;
$ticket->save();
// 通知相关管理员
Notification::send(User::find(1), new TicketReplied($ticket, route('admin.ticket.edit', $ticket)));
Notification::send(User::find(1), new TicketReplied($reply, route('admin.ticket.edit', $ticket)));
return Response::json(['status' => 'success', 'message' => trans('user.ticket.reply').trans('common.success')]);
}

View File

@@ -2,7 +2,7 @@
namespace App\Notifications;
use App\Models\Ticket;
use App\Models\TicketReply;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
@@ -13,13 +13,13 @@ class TicketReplied extends Notification implements ShouldQueue
{
use Queueable;
private $ticket;
private $reply;
private $url;
private $is_user;
public function __construct(Ticket $ticket, $url, $is_user = false)
public function __construct($reply, $url, $is_user = false)
{
$this->ticket = $ticket;
$this->reply = $reply;
$this->url = $url;
$this->is_user = $is_user;
}
@@ -32,17 +32,17 @@ class TicketReplied extends Notification implements ShouldQueue
public function toMail($notifiable)
{
return (new MailMessage)
->subject(trans('notification.reply_ticket', ['title' => $this->ticket->title]))
->subject(trans('notification.reply_ticket', ['title' => $this->reply->ticket->title]))
->line(trans('notification.ticket_content'))
->line(strip_tags($this->ticket->content))
->line(strip_tags($this->reply->content))
->action(trans('notification.view_ticket'), $this->url);
}
public function toCustom($notifiable)
{
return [
'title' => trans('notification.reply_ticket', ['title' => $this->ticket->title]),
'content' => trans('notification.ticket_content').strip_tags($this->ticket->content),
'title' => trans('notification.reply_ticket', ['title' => $this->reply->ticket->title]),
'content' => trans('notification.ticket_content').strip_tags($this->reply->content),
];
}
@@ -50,12 +50,12 @@ class TicketReplied extends Notification implements ShouldQueue
{
return TelegramMessage::create()
->token(sysConfig('telegram_token'))
->content($this->markdownMessage($this->ticket))
->content($this->markdownMessage($this->reply))
->button(trans('notification.view_ticket'), $this->url);
}
private function markdownMessage($ticket)
private function markdownMessage(TicketReply $reply)
{
return "📮工单回复提醒 #{$ticket->id}\n———————————————\n主题:\n`{$ticket->title}`\n内容:\n`{$ticket->content}`";
return "📮工单回复提醒 #{$reply->ticket->id}\n———————————————\n主题:\n`{$reply->ticket->title}`\n内容:\n`{$reply->content}`";
}
}

View File

@@ -14,7 +14,7 @@
content="An account management Panel based on Laravel7 framework. Include multiple payment, account management, system caching, admin notification, products models, and more.">
<meta name="keywords" content="ProxyPanel Laravel Shadowsocks ShadowsocksR V2Ray Trojan VNET VPN">
<meta name="author" content="ZBrettonYe">
<meta name="copyright" content="2017-2020©ProxyPanel">
<meta name="copyright" content="2017-2021©ProxyPanel">
<title>@yield('title')</title>
<link href="{{asset('favicon.ico')}}" rel="shortcut icon apple-touch-icon">
<!-- 样式表/Stylesheets -->

View File

@@ -200,19 +200,17 @@
</div>
</div>
</div>
<div class="col-xl-4 mb-30">
<div class="card card-shadow text-center h-full">
<div class="card-block">
@if(sysConfig('is_push_bear') && sysConfig('push_bear_qrcode'))
@if(sysConfig('is_push_bear') && sysConfig('push_bear_qrcode'))
<div class="col-xl-4 mb-30">
<div class="card card-shadow text-center h-full">
<div class="card-block">
<h4 class="card-title"><i class="wb-bell mr-10 yellow-600"></i>{{trans('user.home.wechat_push')}}
</h4>
<div id="qrcode" class="mb-10"></div>
@else
<h4 class="card-title"><i class="wb-bell mr-10 yellow-600"></i>{{trans('user.home.chat_group')}}</h4>
@endif
</div>
</div>
</div>
</div>
@endif
</div>
<div class="row" data-plugin="matchHeight" data-by-row="true">
<div class="col-xxl-6 mb-30">