fix: 规范数据库事物的使用,解决在swoole环境下可能会出现事物一直不被提交的问题

This commit is contained in:
xboard committed 2023-12-06 19:00:26 +08:00
1 parent 6b209d8c58
commit a3356f695c
13 files changed
+293 -251

No files matched your search

@@ -118,14 +118,19 @@ class PaymentController extends Controller
'ids.required' => '参数有误',
'ids.array' => '参数有误'
]);
DB::beginTransaction();
foreach ($request->input('ids') as $k => $v) {
if (!Payment::find($v)->update(['sort' => $k + 1])) {
DB::rollBack();
throw new ApiException(500, '保存失败');
try{
DB::beginTransaction();
foreach ($request->input('ids') as $k => $v) {
if (!Payment::find($v)->update(['sort' => $k + 1])) {
throw new ApiException(500, '保存失败');
}
}
DB::commit();
}catch(\Exception $e){
DB::rollBack();
throw $e;
}
DB::commit();
return response([
'data' => true
]);