mirror of
https://github.com/v2board/v2board.git
synced 2025-01-10 16:19:10 +08:00
update: ticket
This commit is contained in:
parent
f40480c918
commit
b5a614d901
@ -36,20 +36,20 @@ class TicketController extends Controller
|
|||||||
}
|
}
|
||||||
$current = $request->input('current') ? $request->input('current') : 1;
|
$current = $request->input('current') ? $request->input('current') : 1;
|
||||||
$pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10;
|
$pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10;
|
||||||
$model = Ticket::orderBy('created_at', 'DESC');
|
$model = Ticket::orderBy('updated_at', 'DESC');
|
||||||
if ($request->input('status') !== NULL) {
|
if ($request->input('status') !== NULL) {
|
||||||
$model->where('status', $request->input('status'));
|
$model->where('status', $request->input('status'));
|
||||||
}
|
}
|
||||||
|
if ($request->input('reply_status') !== NULL) {
|
||||||
|
$model->whereIn('reply_status', $request->input('reply_status'));
|
||||||
|
}
|
||||||
|
if ($request->input('email') !== NULL) {
|
||||||
|
$user = User::where('email', $request->input('email'))->first();
|
||||||
|
if ($user) $model->where('user_id', $user->id);
|
||||||
|
}
|
||||||
$total = $model->count();
|
$total = $model->count();
|
||||||
$res = $model->forPage($current, $pageSize)
|
$res = $model->forPage($current, $pageSize)
|
||||||
->get();
|
->get();
|
||||||
for ($i = 0; $i < count($res); $i++) {
|
|
||||||
if ($res[$i]['last_reply_user_id'] == $request->session()->get('id')) {
|
|
||||||
$res[$i]['reply_status'] = 0;
|
|
||||||
} else {
|
|
||||||
$res[$i]['reply_status'] = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return response([
|
return response([
|
||||||
'data' => $res,
|
'data' => $res,
|
||||||
'total' => $total
|
'total' => $total
|
||||||
|
@ -39,13 +39,6 @@ class TicketController extends Controller
|
|||||||
$total = $model->count();
|
$total = $model->count();
|
||||||
$res = $model->forPage($current, $pageSize)
|
$res = $model->forPage($current, $pageSize)
|
||||||
->get();
|
->get();
|
||||||
for ($i = 0; $i < count($res); $i++) {
|
|
||||||
if ($res[$i]['last_reply_user_id'] == $request->session()->get('id')) {
|
|
||||||
$res[$i]['reply_status'] = 0;
|
|
||||||
} else {
|
|
||||||
$res[$i]['reply_status'] = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return response([
|
return response([
|
||||||
'data' => $res,
|
'data' => $res,
|
||||||
'total' => $total
|
'total' => $total
|
||||||
|
@ -8,6 +8,7 @@ use App\Http\Requests\User\TicketWithdraw;
|
|||||||
use App\Jobs\SendTelegramJob;
|
use App\Jobs\SendTelegramJob;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Services\TelegramService;
|
use App\Services\TelegramService;
|
||||||
|
use App\Services\TicketService;
|
||||||
use App\Utils\Dict;
|
use App\Utils\Dict;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Models\Ticket;
|
use App\Models\Ticket;
|
||||||
@ -40,13 +41,6 @@ class TicketController extends Controller
|
|||||||
$ticket = Ticket::where('user_id', $request->session()->get('id'))
|
$ticket = Ticket::where('user_id', $request->session()->get('id'))
|
||||||
->orderBy('created_at', 'DESC')
|
->orderBy('created_at', 'DESC')
|
||||||
->get();
|
->get();
|
||||||
for ($i = 0; $i < count($ticket); $i++) {
|
|
||||||
if ($ticket[$i]['last_reply_user_id'] == $request->session()->get('id')) {
|
|
||||||
$ticket[$i]['reply_status'] = 0;
|
|
||||||
} else {
|
|
||||||
$ticket[$i]['reply_status'] = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return response([
|
return response([
|
||||||
'data' => $ticket
|
'data' => $ticket
|
||||||
]);
|
]);
|
||||||
@ -62,8 +56,7 @@ class TicketController extends Controller
|
|||||||
'subject',
|
'subject',
|
||||||
'level'
|
'level'
|
||||||
]), [
|
]), [
|
||||||
'user_id' => $request->session()->get('id'),
|
'user_id' => $request->session()->get('id')
|
||||||
'last_reply_user_id' => $request->session()->get('id')
|
|
||||||
]));
|
]));
|
||||||
if (!$ticket) {
|
if (!$ticket) {
|
||||||
DB::rollback();
|
DB::rollback();
|
||||||
@ -79,7 +72,7 @@ class TicketController extends Controller
|
|||||||
abort(500, __('Failed to open ticket'));
|
abort(500, __('Failed to open ticket'));
|
||||||
}
|
}
|
||||||
DB::commit();
|
DB::commit();
|
||||||
$this->sendNotify($ticket, $ticketMessage);
|
$this->sendNotify($ticket, $request->input('message'));
|
||||||
return response([
|
return response([
|
||||||
'data' => true
|
'data' => true
|
||||||
]);
|
]);
|
||||||
@ -105,19 +98,15 @@ class TicketController extends Controller
|
|||||||
if ($request->session()->get('id') == $this->getLastMessage($ticket->id)->user_id) {
|
if ($request->session()->get('id') == $this->getLastMessage($ticket->id)->user_id) {
|
||||||
abort(500, __('Please wait for the technical enginneer to reply'));
|
abort(500, __('Please wait for the technical enginneer to reply'));
|
||||||
}
|
}
|
||||||
DB::beginTransaction();
|
$ticketService = new TicketService();
|
||||||
$ticketMessage = TicketMessage::create([
|
if (!$ticketService->reply(
|
||||||
'user_id' => $request->session()->get('id'),
|
$ticket,
|
||||||
'ticket_id' => $ticket->id,
|
$request->input('message'),
|
||||||
'message' => $request->input('message')
|
$request->session()->get('id')
|
||||||
]);
|
)) {
|
||||||
$ticket->last_reply_user_id = $request->session()->get('id');
|
|
||||||
if (!$ticketMessage || !$ticket->save()) {
|
|
||||||
DB::rollback();
|
|
||||||
abort(500, __('Ticket reply failed'));
|
abort(500, __('Ticket reply failed'));
|
||||||
}
|
}
|
||||||
DB::commit();
|
$this->sendNotify($ticket, $request->input('message'));
|
||||||
$this->sendNotify($ticket, $ticketMessage);
|
|
||||||
return response([
|
return response([
|
||||||
'data' => true
|
'data' => true
|
||||||
]);
|
]);
|
||||||
@ -175,8 +164,7 @@ class TicketController extends Controller
|
|||||||
$ticket = Ticket::create([
|
$ticket = Ticket::create([
|
||||||
'subject' => $subject,
|
'subject' => $subject,
|
||||||
'level' => 2,
|
'level' => 2,
|
||||||
'user_id' => $request->session()->get('id'),
|
'user_id' => $request->session()->get('id')
|
||||||
'last_reply_user_id' => $request->session()->get('id')
|
|
||||||
]);
|
]);
|
||||||
if (!$ticket) {
|
if (!$ticket) {
|
||||||
DB::rollback();
|
DB::rollback();
|
||||||
@ -196,15 +184,15 @@ class TicketController extends Controller
|
|||||||
abort(500, __('Failed to open ticket'));
|
abort(500, __('Failed to open ticket'));
|
||||||
}
|
}
|
||||||
DB::commit();
|
DB::commit();
|
||||||
$this->sendNotify($ticket, $ticketMessage);
|
$this->sendNotify($ticket, $message);
|
||||||
return response([
|
return response([
|
||||||
'data' => true
|
'data' => true
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function sendNotify(Ticket $ticket, TicketMessage $ticketMessage)
|
private function sendNotify(Ticket $ticket, string $message)
|
||||||
{
|
{
|
||||||
$telegramService = new TelegramService();
|
$telegramService = new TelegramService();
|
||||||
$telegramService->sendMessageWithAdmin("📮工单提醒 #{$ticket->id}\n———————————————\n主题:\n`{$ticket->subject}`\n内容:\n`{$ticketMessage->message}`", true);
|
$telegramService->sendMessageWithAdmin("📮工单提醒 #{$ticket->id}\n———————————————\n主题:\n`{$ticket->subject}`\n内容:\n`{$message}`", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,27 @@ use Illuminate\Support\Facades\Cache;
|
|||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class TicketService {
|
class TicketService {
|
||||||
|
public function reply($ticket, $message, $userId)
|
||||||
|
{
|
||||||
|
DB::beginTransaction();
|
||||||
|
$ticketMessage = TicketMessage::create([
|
||||||
|
'user_id' => $userId,
|
||||||
|
'ticket_id' => $ticket->id,
|
||||||
|
'message' => $message
|
||||||
|
]);
|
||||||
|
if ($userId !== $ticket->user_id) {
|
||||||
|
$ticket->reply_status = 0;
|
||||||
|
} else {
|
||||||
|
$ticket->reply_status = 1;
|
||||||
|
}
|
||||||
|
if (!$ticketMessage || !$ticket->save()) {
|
||||||
|
DB::rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
DB::commit();
|
||||||
|
return $ticketMessage;
|
||||||
|
}
|
||||||
|
|
||||||
public function replyByAdmin($ticketId, $message, $userId):void
|
public function replyByAdmin($ticketId, $message, $userId):void
|
||||||
{
|
{
|
||||||
$ticket = Ticket::where('id', $ticketId)
|
$ticket = Ticket::where('id', $ticketId)
|
||||||
@ -24,7 +45,11 @@ class TicketService {
|
|||||||
'ticket_id' => $ticket->id,
|
'ticket_id' => $ticket->id,
|
||||||
'message' => $message
|
'message' => $message
|
||||||
]);
|
]);
|
||||||
$ticket->last_reply_user_id = $userId;
|
if ($userId !== $ticket->user_id) {
|
||||||
|
$ticket->reply_status = 0;
|
||||||
|
} else {
|
||||||
|
$ticket->reply_status = 1;
|
||||||
|
}
|
||||||
if (!$ticketMessage || !$ticket->save()) {
|
if (!$ticketMessage || !$ticket->save()) {
|
||||||
DB::rollback();
|
DB::rollback();
|
||||||
abort(500, '工单回复失败');
|
abort(500, '工单回复失败');
|
||||||
|
@ -317,10 +317,10 @@ DROP TABLE IF EXISTS `v2_ticket`;
|
|||||||
CREATE TABLE `v2_ticket` (
|
CREATE TABLE `v2_ticket` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`user_id` int(11) NOT NULL,
|
`user_id` int(11) NOT NULL,
|
||||||
`last_reply_user_id` int(11) NOT NULL,
|
|
||||||
`subject` varchar(255) NOT NULL,
|
`subject` varchar(255) NOT NULL,
|
||||||
`level` tinyint(1) NOT NULL,
|
`level` tinyint(1) NOT NULL,
|
||||||
`status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0:已开启 1:已关闭',
|
`status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0:已开启 1:已关闭',
|
||||||
|
`reply_status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '0:待回复 1:已回复',
|
||||||
`created_at` int(11) NOT NULL,
|
`created_at` int(11) NOT NULL,
|
||||||
`updated_at` int(11) NOT NULL,
|
`updated_at` int(11) NOT NULL,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
@ -377,4 +377,4 @@ CREATE TABLE `v2_user` (
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|
||||||
-- 2022-04-14 18:42:31
|
-- 2022-04-27 16:56:19
|
||||||
|
@ -560,3 +560,7 @@ DROP `server_type`;
|
|||||||
|
|
||||||
ALTER TABLE `v2_notice`
|
ALTER TABLE `v2_notice`
|
||||||
ADD `tags` varchar(255) COLLATE 'utf8_general_ci' NULL AFTER `img_url`;
|
ADD `tags` varchar(255) COLLATE 'utf8_general_ci' NULL AFTER `img_url`;
|
||||||
|
|
||||||
|
ALTER TABLE `v2_ticket`
|
||||||
|
DROP `last_reply_user_id`,
|
||||||
|
ADD `reply_status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '0:待回复 1:已回复' AFTER `status`;
|
||||||
|
2
public/assets/admin/umi.js
vendored
2
public/assets/admin/umi.js
vendored
File diff suppressed because one or more lines are too long
8
public/theme/v2board/assets/i18n/en-US.js
vendored
8
public/theme/v2board/assets/i18n/en-US.js
vendored
@ -259,5 +259,11 @@ window.settings.i18n['en-US'] = {
|
|||||||
'你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?': '你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?',
|
'你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?': '你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?',
|
||||||
'确定取消': '确定取消',
|
'确定取消': '确定取消',
|
||||||
'返回我的订单': '返回我的订单',
|
'返回我的订单': '返回我的订单',
|
||||||
'如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?': '如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?'
|
'如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?': '如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?',
|
||||||
|
'选择最适合你的计划': '选择最适合你的计划',
|
||||||
|
'全部': '全部',
|
||||||
|
'按周期': '按周期',
|
||||||
|
'一次性': '一次性',
|
||||||
|
'遇到问题': '遇到问题',
|
||||||
|
'遇到问题可以通过工单与我们沟通': '遇到问题可以通过工单与我们沟通'
|
||||||
};
|
};
|
8
public/theme/v2board/assets/i18n/ja-JP.js
vendored
8
public/theme/v2board/assets/i18n/ja-JP.js
vendored
@ -259,5 +259,11 @@ window.settings.i18n['ja-JP'] = {
|
|||||||
'你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?': '你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?',
|
'你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?': '你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?',
|
||||||
'确定取消': '确定取消',
|
'确定取消': '确定取消',
|
||||||
'返回我的订单': '返回我的订单',
|
'返回我的订单': '返回我的订单',
|
||||||
'如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?': '如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?'
|
'如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?': '如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?',
|
||||||
|
'选择最适合你的计划': '选择最适合你的计划',
|
||||||
|
'全部': '全部',
|
||||||
|
'按周期': '按周期',
|
||||||
|
'一次性': '一次性',
|
||||||
|
'遇到问题': '遇到问题',
|
||||||
|
'遇到问题可以通过工单与我们沟通': '遇到问题可以通过工单与我们沟通'
|
||||||
};
|
};
|
8
public/theme/v2board/assets/i18n/ko-KR.js
vendored
8
public/theme/v2board/assets/i18n/ko-KR.js
vendored
@ -259,5 +259,11 @@ window.settings.i18n['ko-KR'] = {
|
|||||||
'你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?': '你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?',
|
'你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?': '你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?',
|
||||||
'确定取消': '确定取消',
|
'确定取消': '确定取消',
|
||||||
'返回我的订单': '返回我的订单',
|
'返回我的订单': '返回我的订单',
|
||||||
'如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?': '如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?'
|
'如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?': '如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?',
|
||||||
|
'选择最适合你的计划': '选择最适合你的计划',
|
||||||
|
'全部': '全部',
|
||||||
|
'按周期': '按周期',
|
||||||
|
'一次性': '一次性',
|
||||||
|
'遇到问题': '遇到问题',
|
||||||
|
'遇到问题可以通过工单与我们沟通': '遇到问题可以通过工单与我们沟通'
|
||||||
};
|
};
|
8
public/theme/v2board/assets/i18n/vi-VN.js
vendored
8
public/theme/v2board/assets/i18n/vi-VN.js
vendored
@ -259,5 +259,11 @@ window.settings.i18n['vi-VN'] = {
|
|||||||
'你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?': '你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?',
|
'你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?': '你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?',
|
||||||
'确定取消': '确定取消',
|
'确定取消': '确定取消',
|
||||||
'返回我的订单': '返回我的订单',
|
'返回我的订单': '返回我的订单',
|
||||||
'如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?': '如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?'
|
'如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?': '如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?',
|
||||||
|
'选择最适合你的计划': '选择最适合你的计划',
|
||||||
|
'全部': '全部',
|
||||||
|
'按周期': '按周期',
|
||||||
|
'一次性': '一次性',
|
||||||
|
'遇到问题': '遇到问题',
|
||||||
|
'遇到问题可以通过工单与我们沟通': '遇到问题可以通过工单与我们沟通'
|
||||||
};
|
};
|
8
public/theme/v2board/assets/i18n/zh-CN.js
vendored
8
public/theme/v2board/assets/i18n/zh-CN.js
vendored
@ -259,5 +259,11 @@ window.settings.i18n['zh-CN'] = {
|
|||||||
'你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?': '你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?',
|
'你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?': '你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?',
|
||||||
'确定取消': '确定取消',
|
'确定取消': '确定取消',
|
||||||
'返回我的订单': '返回我的订单',
|
'返回我的订单': '返回我的订单',
|
||||||
'如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?': '如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?'
|
'如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?': '如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?',
|
||||||
|
'选择最适合你的计划': '选择最适合你的计划',
|
||||||
|
'全部': '全部',
|
||||||
|
'按周期': '按周期',
|
||||||
|
'一次性': '一次性',
|
||||||
|
'遇到问题': '遇到问题',
|
||||||
|
'遇到问题可以通过工单与我们沟通': '遇到问题可以通过工单与我们沟通'
|
||||||
};
|
};
|
8
public/theme/v2board/assets/i18n/zh-TW.js
vendored
8
public/theme/v2board/assets/i18n/zh-TW.js
vendored
@ -259,5 +259,11 @@ window.settings.i18n['zh-TW'] = {
|
|||||||
'你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?': '你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?',
|
'你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?': '你还有未完成的订单,购买前需要先进行取消,确定取消先前的订单吗?',
|
||||||
'确定取消': '确定取消',
|
'确定取消': '确定取消',
|
||||||
'返回我的订单': '返回我的订单',
|
'返回我的订单': '返回我的订单',
|
||||||
'如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?': '如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?'
|
'如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?': '如果你已经付款,取消订单可能会导致支付失败,确定取消订单吗?',
|
||||||
|
'选择最适合你的计划': '选择最适合你的计划',
|
||||||
|
'全部': '全部',
|
||||||
|
'按周期': '按周期',
|
||||||
|
'一次性': '一次性',
|
||||||
|
'遇到问题': '遇到问题',
|
||||||
|
'遇到问题可以通过工单与我们沟通': '遇到问题可以通过工单与我们沟通'
|
||||||
};
|
};
|
2
public/theme/v2board/assets/umi.js
vendored
2
public/theme/v2board/assets/umi.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user