diff --git a/app/Http/Controllers/Admin/TicketController.php b/app/Http/Controllers/Admin/TicketController.php index 0a144b96..842b0f33 100644 --- a/app/Http/Controllers/Admin/TicketController.php +++ b/app/Http/Controllers/Admin/TicketController.php @@ -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' => '回复成功']); diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 3ee12710..814cf606 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -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')]); } diff --git a/app/Notifications/TicketReplied.php b/app/Notifications/TicketReplied.php index 70dc4dda..1a939b4f 100644 --- a/app/Notifications/TicketReplied.php +++ b/app/Notifications/TicketReplied.php @@ -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}`"; } } diff --git a/resources/views/_layout.blade.php b/resources/views/_layout.blade.php index cc8f860a..894732b5 100644 --- a/resources/views/_layout.blade.php +++ b/resources/views/_layout.blade.php @@ -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."> - +