mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 01:11:46 +08:00 
			
		
		
		
	feature: staff permission
This commit is contained in:
		| @@ -184,7 +184,7 @@ class TelegramController extends Controller | ||||
|             abort(500, '用户不存在'); | ||||
|         } | ||||
|         $ticketService = new TicketService(); | ||||
|         if ($user->is_admin) { | ||||
|         if ($user->is_admin || $user->is_staff) { | ||||
|             $ticketService->replyByAdmin( | ||||
|                 $ticketId, | ||||
|                 $msg->text, | ||||
| @@ -194,4 +194,6 @@ class TelegramController extends Controller | ||||
|         $telegramService = new TelegramService(); | ||||
|         $telegramService->sendMessage($msg->chat_id, "#`{$ticketId}` 的工单已回复成功", 'markdown'); | ||||
|     } | ||||
|  | ||||
|  | ||||
| } | ||||
|   | ||||
							
								
								
									
										92
									
								
								app/Http/Controllers/Staff/TicketController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								app/Http/Controllers/Staff/TicketController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,92 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Http\Controllers\Staff; | ||||
|  | ||||
| use App\Services\TicketService; | ||||
| use Illuminate\Http\Request; | ||||
| use App\Http\Controllers\Controller; | ||||
| use App\Models\Ticket; | ||||
| use App\Models\TicketMessage; | ||||
|  | ||||
| class TicketController extends Controller | ||||
| { | ||||
|     public function fetch(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'] !== $ticket->user_id) { | ||||
|                     $ticket['message'][$i]['is_me'] = true; | ||||
|                 } else { | ||||
|                     $ticket['message'][$i]['is_me'] = false; | ||||
|                 } | ||||
|             } | ||||
|             return response([ | ||||
|                 'data' => $ticket | ||||
|             ]); | ||||
|         } | ||||
|         $current = $request->input('current') ? $request->input('current') : 1; | ||||
|         $pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10; | ||||
|         $model = Ticket::orderBy('created_at', 'DESC'); | ||||
|         if ($request->input('status') !== NULL) { | ||||
|             $model->where('status', $request->input('status')); | ||||
|         } | ||||
|         $total = $model->count(); | ||||
|         $res = $model->forPage($current, $pageSize) | ||||
|             ->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([ | ||||
|             'data' => $res, | ||||
|             'total' => $total | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     public function reply(Request $request) | ||||
|     { | ||||
|         if (empty($request->input('id'))) { | ||||
|             abort(500, '参数错误'); | ||||
|         } | ||||
|         if (empty($request->input('message'))) { | ||||
|             abort(500, '消息不能为空'); | ||||
|         } | ||||
|         $ticketService = new TicketService(); | ||||
|         $ticketService->replyByAdmin( | ||||
|             $request->input('id'), | ||||
|             $request->input('message'), | ||||
|             $request->session()->get('id') | ||||
|         ); | ||||
|         return response([ | ||||
|             'data' => true | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     public function close(Request $request) | ||||
|     { | ||||
|         if (empty($request->input('id'))) { | ||||
|             abort(500, '参数错误'); | ||||
|         } | ||||
|         $ticket = Ticket::where('id', $request->input('id')) | ||||
|             ->first(); | ||||
|         if (!$ticket) { | ||||
|             abort(500, '工单不存在'); | ||||
|         } | ||||
|         $ticket->status = 1; | ||||
|         if (!$ticket->save()) { | ||||
|             abort(500, '关闭失败'); | ||||
|         } | ||||
|         return response([ | ||||
|             'data' => true | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user