v2board/app/Http/Controllers/Admin/TicketController.php
2019-12-13 16:00:04 +08:00

38 lines
1.1 KiB
PHP

<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Ticket;
use App\Models\TicketMessage;
use Illuminate\Support\Facades\Redis;
class TicketController extends Controller
{
public function index (Request $request) {
if ($request->input('id')) {
$ticket = Ticket::where('id', $request->input('id'))
->first();
if (!$ticket) {
abort(500, '工单不存在');
}
$ticket['message'] = TicketMessage::where('ticket_id', $ticket->id)->get();
for ($i = 0; $i < count($ticket['message']); $i++) {
if ($ticket['message'][$i]['user_id'] == $request->session()->get('id')) {
$ticket['message'][$i]['is_me'] = true;
} else {
$ticket['message'][$i]['is_me'] = false;
}
}
return response([
'data' => $ticket
]);
}
return response([
'data' => Ticket::orderBy('created_at', 'DESC')
->get()
]);
}
}