Update source into github
This commit is contained in:
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\frontend;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Services\Upload;
|
||||
use App\Models\InvoiceItem;
|
||||
use App\Models\Ticket;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class TicketController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$title = "Danh sách yêu cầu hỗ trợ";
|
||||
$breadcrumbs = $this->crums->add(__('Dashboard'), route('home'))->add(__('Yêu cầu hỗ trợ'));
|
||||
return view("frontend.ticket.ticket", compact('title', 'breadcrumbs'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$title = "Gửi yêu cầu hỗ trợ";
|
||||
$ticket = true;
|
||||
$breadcrumbs = $this->crums->add(__('Dashboard'), route('home'))->add(__('DS Yêu cầu hỗ trợ'), route('ticket'))->add(__('Gửi yêu cầu hỗ trợ'));
|
||||
$itemProduct = \App\Models\InvoiceItem::whereHas('invoice', function ($query) {
|
||||
$query->where('customer_id', customer()->id);
|
||||
})
|
||||
->where('invoice_type', 1)
|
||||
->get();
|
||||
return view("frontend.ticket.add", compact('title', 'itemProduct', 'ticket', 'breadcrumbs'));
|
||||
}
|
||||
|
||||
public function store(Request $request, Upload $upload)
|
||||
{
|
||||
$validator = Validator::make(
|
||||
$request->all(),
|
||||
[
|
||||
'full_name' => 'required',
|
||||
'email' => 'required',
|
||||
'subject' => 'required',
|
||||
'room' => 'required',
|
||||
'description' => 'required',
|
||||
],
|
||||
[
|
||||
'full_name' => [
|
||||
'required' => 'Yêu cầu không hợp lệ'
|
||||
],
|
||||
'email' => [
|
||||
'required' => 'Yêu cầu không hợp lệ'
|
||||
],
|
||||
'subject' => [
|
||||
'required' => 'Tiêu đề không được để trống'
|
||||
],
|
||||
'room' => [
|
||||
'required' => 'Vui lòng chọn phòng ban cần hỗ trợ'
|
||||
],
|
||||
'description' => [
|
||||
'required' => 'Vui lòng nhập nội dung cần hỗ trợ'
|
||||
]
|
||||
]
|
||||
);
|
||||
if ($validator->fails()) {
|
||||
return back()->withInput()->withErrors($validator);
|
||||
}
|
||||
if ($request->fileTicket) {
|
||||
$data = $upload->ImageUpload($request->fileTicket);
|
||||
|
||||
if ($data['error']) {
|
||||
return back()->withInput()->withErrors($data['message']);
|
||||
}
|
||||
}
|
||||
$type = !empty($request->product) ? explode("|", $request->product) : [];
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$dataJson = [
|
||||
'product' => count($type) ? $type[1] : "",
|
||||
'product_type' => count($type) ? $type[0] : "",
|
||||
'file' => isset($data) ? $data['data'] : ""
|
||||
];
|
||||
$ticket = Ticket::create([
|
||||
'subject' => $request->subject,
|
||||
'ticket_num' => random_int(1000000, 99999999),
|
||||
'description' => $request->description,
|
||||
'customer_id' => $request->user('users')->id,
|
||||
'data' => json_encode($dataJson),
|
||||
'room' => $request->room,
|
||||
'status' => 1
|
||||
]);
|
||||
DB::commit();
|
||||
// Dispatch job to send Telegram notification
|
||||
$customer = \App\Models\Customer::find($ticket->customer_id);
|
||||
\App\Jobs\Ticket\TicketJobs::dispatch($ticket, $customer);
|
||||
} catch (\Exception $exception) {
|
||||
DB::rollBack();
|
||||
return back()->withInput()->withErrors($exception->getMessage());
|
||||
}
|
||||
return redirect()->route('ticket')->with('success', 'Gửi yêu cầu hỗ trợ thành công!');
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
$validator = Validator::make(
|
||||
$request->all(),
|
||||
[
|
||||
'ticket_num' => 'required'
|
||||
],
|
||||
[
|
||||
'ticket_num' => [
|
||||
'required' => 'Yêu cầu không hợp lệ'
|
||||
]
|
||||
]
|
||||
);
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator);
|
||||
}
|
||||
$ticket = Ticket::with([
|
||||
'Reply' => function ($query) {
|
||||
$query->latest('id');
|
||||
},
|
||||
'Reply.User',
|
||||
'Customer'
|
||||
])->where('ticket_num', $request->ticket_num)->latest('id')->get();
|
||||
|
||||
$title = "Ticket #" . $request->ticket_num;
|
||||
|
||||
return view("frontend.ticket.view", compact('title', 'ticket'));
|
||||
}
|
||||
|
||||
public function ReplyStore(Request $request, Upload $upload)
|
||||
{
|
||||
$validator = Validator::make(
|
||||
$request->all(),
|
||||
[
|
||||
'ticket_num' => 'required',
|
||||
'description' => 'required',
|
||||
],
|
||||
[
|
||||
'ticket_num' => [
|
||||
'required' => 'Yêu cầu không hợp lệ'
|
||||
],
|
||||
'description' => [
|
||||
'required' => 'Vui lòng nhập nội dung cần hỗ trợ'
|
||||
]
|
||||
]
|
||||
);
|
||||
if ($validator->fails()) {
|
||||
return back()->withInput()->withErrors($validator);
|
||||
}
|
||||
$ticket = Ticket::where('ticket_num', $request->ticket_num)->first();
|
||||
|
||||
if (!$ticket) {
|
||||
return back()->withInput()->withErrors('Yêu cầu không hợp lệ');
|
||||
}
|
||||
|
||||
if ($request->fileTicket) {
|
||||
$data = $upload->ImageUpload($request->fileTicket);
|
||||
|
||||
if ($data['error']) {
|
||||
return back()->withInput()->withErrors($data['message']);
|
||||
}
|
||||
}
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$dataJson = json_decode($ticket->data, true);
|
||||
$dataJson['file'] = isset($data) ? $data['data'] : "";
|
||||
Ticket::create([
|
||||
'subject' => $ticket->subject,
|
||||
'ticket_num' => $ticket->ticket_num,
|
||||
'description' => $request->description,
|
||||
'customer_id' => $ticket->customer_id,
|
||||
'data' => json_encode($dataJson),
|
||||
'room' => $ticket->room,
|
||||
'status' => 1
|
||||
]);
|
||||
DB::commit();
|
||||
} catch (\Exception $exception) {
|
||||
DB::rollBack();
|
||||
return back()->withInput()->withErrors($exception->getMessage());
|
||||
}
|
||||
return back()->with('success', 'Trả lời yêu cầu hỗ trợ thành công!');
|
||||
}
|
||||
|
||||
public function ClosedTicket(Request $request)
|
||||
{
|
||||
$validator = Validator::make(
|
||||
$request->all(),
|
||||
[
|
||||
'ticket_num' => 'required'
|
||||
],
|
||||
[
|
||||
'ticket_num' => [
|
||||
'required' => 'Yêu cầu không hợp lệ'
|
||||
]
|
||||
]
|
||||
);
|
||||
if ($validator->fails()) {
|
||||
return back()->withInput()->withErrors($validator);
|
||||
}
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
Ticket::where('ticket_num', $request->ticket_num)->update(['status' => 0]);
|
||||
DB::commit();
|
||||
} catch (\Exception $exception) {
|
||||
DB::rollBack();
|
||||
return back()->withInput()->withErrors($exception->getMessage());
|
||||
}
|
||||
return redirect()->route('ticket')->with('success', 'Yêu cầu xử lý thành công!');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user