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

This commit is contained in:
xboard
2023-12-06 19:00:26 +08:00
parent 64cc2d79da
commit 1fcb6fa911
13 changed files with 293 additions and 251 deletions

View File

@@ -28,19 +28,21 @@ class ManageController extends Controller
'hysteria',
'vless'
) ?? [];
DB::beginTransaction();
foreach ($params as $k => $v) {
$model = 'App\\Models\\Server' . ucfirst($k);
foreach($v as $id => $sort) {
if (!$model::find($id)->update(['sort' => $sort])) {
DB::rollBack();
throw new ApiException(500, '保存失败');
try{
DB::beginTransaction();
foreach ($params as $k => $v) {
$model = 'App\\Models\\Server' . ucfirst($k);
foreach($v as $id => $sort) {
if (!$model::find($id)->update(['sort' => $sort])) {
throw new ApiException(500, '保存失败');
}
}
}
DB::commit();
}catch (\Exception $e){
DB::rollBack();
throw $e;
}
DB::commit();
return response([
'data' => true
]);
return $this->success(true);
}
}