mirror of
https://github.com/cedar2025/Xboard.git
synced 2025-01-22 10:38:14 -05:00
fix: 修复创建工单中的事务安全
This commit is contained in:
parent
e16618142a
commit
f812e5f239
@ -44,7 +44,7 @@ class TicketController extends Controller
|
||||
try{
|
||||
DB::beginTransaction();
|
||||
if ((int)Ticket::where('status', 0)->where('user_id', $request->user['id'])->lockForUpdate()->count()) {
|
||||
return $this->fail([400, __('There are other unresolved tickets')]);
|
||||
throw new \Exception(__('There are other unresolved tickets'));
|
||||
}
|
||||
$ticket = Ticket::create(array_merge($request->only([
|
||||
'subject',
|
||||
@ -53,7 +53,7 @@ class TicketController extends Controller
|
||||
'user_id' => $request->user['id']
|
||||
]));
|
||||
if (!$ticket) {
|
||||
return $this->fail([400, __('Failed to open ticket')]);
|
||||
throw new \Exception(__('There are other unresolved tickets'));
|
||||
}
|
||||
$ticketMessage = TicketMessage::create([
|
||||
'user_id' => $request->user['id'],
|
||||
@ -61,15 +61,17 @@ class TicketController extends Controller
|
||||
'message' => $request->input('message')
|
||||
]);
|
||||
if (!$ticketMessage) {
|
||||
return $this->fail([400, __('Failed to open ticket')]);
|
||||
throw new \Exception(__('Failed to open ticket'));
|
||||
}
|
||||
DB::commit();
|
||||
$this->sendNotify($ticket, $request->input('message'), $request->user['id']);
|
||||
return $this->success(true);
|
||||
}catch(\Exception $e){
|
||||
DB::rollBack();
|
||||
throw $e;
|
||||
\Log::error($e);
|
||||
return $this->fail([400, $e->getMessage()]);
|
||||
}
|
||||
$this->sendNotify($ticket, $request->input('message'), $request->user['id']);
|
||||
return $this->success(true);
|
||||
|
||||
}
|
||||
|
||||
public function reply(Request $request)
|
||||
|
Loading…
Reference in New Issue
Block a user