diff --git a/app/Http/Controllers/Admin/StatController.php b/app/Http/Controllers/Admin/StatController.php index 7af5f065..9af79f9a 100644 --- a/app/Http/Controllers/Admin/StatController.php +++ b/app/Http/Controllers/Admin/StatController.php @@ -2,8 +2,6 @@ namespace App\Http\Controllers\Admin; -use App\Http\Requests\Admin\ServerSave; -use App\Http\Requests\Admin\ServerUpdate; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use App\Models\ServerGroup; diff --git a/app/Http/Controllers/Admin/TicketController.php b/app/Http/Controllers/Admin/TicketController.php new file mode 100644 index 00000000..e2a6313c --- /dev/null +++ b/app/Http/Controllers/Admin/TicketController.php @@ -0,0 +1,16 @@ +session()->get('id')); return response([ 'data' => $plan ]); diff --git a/app/Http/Controllers/TicketController.php b/app/Http/Controllers/TicketController.php new file mode 100644 index 00000000..e33ae8a4 --- /dev/null +++ b/app/Http/Controllers/TicketController.php @@ -0,0 +1,49 @@ + Ticket::where('user_id', $request->session()->get('id')) + ->orderBy('created_at', 'DESC') + ->get() + ]); + } + + public function save (TicketSave $request) { + DB::beginTransaction(); + $ticket = Ticket::create(array_merge($request->only([ + 'subject', + 'level' + ]), [ + 'user_id' => $request->session()->get('id') + ])); + if (!$ticket) { + DB::rollback(); + abort(500, '工单创建失败'); + } + $ticketMessage = TicketMessage::create([ + 'user_id' => $request->session()->get('id'), + 'ticket_id' => $ticket->id, + 'message' => $request->input('message') + ]); + if (!$ticketMessage) { + DB::rollback(); + abort(500, '工单创建失败'); + } + DB::commit(); + return response([ + 'data' => true + ]); + } +} diff --git a/app/Http/Requests/TicketSave.php b/app/Http/Requests/TicketSave.php new file mode 100644 index 00000000..6cc98556 --- /dev/null +++ b/app/Http/Requests/TicketSave.php @@ -0,0 +1,32 @@ + 'required', + 'level' => 'required|in:0,1,2', + 'message' => 'required' + ]; + } + + public function messages() + { + return [ + 'subject.required' => '工单主题不能为空', + 'level.required' => '工单级别不能为空', + 'level.in' => '工单级别格式不正确', + 'message.required' => '消息不能为空' + ]; + } +} diff --git a/app/Models/Ticket.php b/app/Models/Ticket.php new file mode 100644 index 00000000..7f1ead31 --- /dev/null +++ b/app/Models/Ticket.php @@ -0,0 +1,12 @@ +