2022-01-27 01:46:26 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Plugins\Telegram\Commands;
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Plugins\Telegram\Telegram;
|
|
|
|
use App\Services\TicketService;
|
|
|
|
|
|
|
|
class ReplyTicket extends Telegram {
|
|
|
|
public $regex = '/[#](.*)/';
|
2022-01-27 15:18:41 +08:00
|
|
|
public $description = '快速工单回复';
|
2022-01-27 01:46:26 +08:00
|
|
|
|
|
|
|
public function handle($message, $match = []) {
|
|
|
|
if (!$message->is_private) return;
|
|
|
|
$this->replayTicket($message, $match[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function replayTicket($msg, $ticketId)
|
|
|
|
{
|
|
|
|
$user = User::where('telegram_id', $msg->chat_id)->first();
|
|
|
|
if (!$user) {
|
|
|
|
abort(500, '用户不存在');
|
|
|
|
}
|
|
|
|
if (!$msg->text) return;
|
2022-01-27 15:18:41 +08:00
|
|
|
if (!($user->is_admin || $user->is_staff)) return;
|
2022-01-27 15:20:03 +08:00
|
|
|
$ticketService = new TicketService();
|
2022-01-27 15:18:41 +08:00
|
|
|
$ticketService->replyByAdmin(
|
|
|
|
$ticketId,
|
|
|
|
$msg->text,
|
|
|
|
$user->id
|
|
|
|
);
|
2022-01-27 01:46:26 +08:00
|
|
|
$telegramService = $this->telegramService;
|
|
|
|
$telegramService->sendMessage($msg->chat_id, "#`{$ticketId}` 的工单已回复成功", 'markdown');
|
|
|
|
$telegramService->sendMessageWithAdmin("#`{$ticketId}` 的工单已由 {$user->email} 进行回复", true);
|
|
|
|
}
|
|
|
|
}
|