diff --git a/app/Http/Controllers/Server/DeepbworkController.php b/app/Http/Controllers/Server/DeepbworkController.php index 471a78a4..cdfb1e97 100644 --- a/app/Http/Controllers/Server/DeepbworkController.php +++ b/app/Http/Controllers/Server/DeepbworkController.php @@ -77,25 +77,32 @@ class DeepbworkController extends Controller Cache::put(CacheKey::get('SERVER_V2RAY_ONLINE_USER', $server->id), count($data), 3600); $serverService = new ServerService(); $userService = new UserService(); - foreach ($data as $item) { - $u = $item['u'] * $server->rate; - $d = $item['d'] * $server->rate; - if (!$userService->trafficFetch($u, $d, $item['user_id'])) { - return response([ - 'ret' => 0, - 'msg' => 'user fetch fail' - ]); - } + DB::beginTransaction(); + try { + foreach ($data as $item) { + $u = $item['u'] * $server->rate; + $d = $item['d'] * $server->rate; + if (!$userService->trafficFetch($u, $d, $item['user_id'])) { + continue; + } - $serverService->log( - $item['user_id'], - $request->input('node_id'), - $item['u'], - $item['d'], - $server->rate, - 'vmess' - ); + $serverService->log( + $item['user_id'], + $request->input('node_id'), + $item['u'], + $item['d'], + $server->rate, + 'vmess' + ); + } + } catch (\Exception $e) { + DB::rollBack(); + return response([ + 'ret' => 0, + 'msg' => 'user fetch fail' + ]); } + DB::commit(); return response([ 'ret' => 1, diff --git a/app/Http/Controllers/Server/ShadowsocksTidalabController.php b/app/Http/Controllers/Server/ShadowsocksTidalabController.php index b7f69583..c99fa2fe 100644 --- a/app/Http/Controllers/Server/ShadowsocksTidalabController.php +++ b/app/Http/Controllers/Server/ShadowsocksTidalabController.php @@ -73,25 +73,29 @@ class ShadowsocksTidalabController extends Controller $serverService = new ServerService(); $userService = new UserService(); DB::beginTransaction(); - foreach ($data as $item) { - $u = $item['u'] * $server->rate; - $d = $item['d'] * $server->rate; - if (!$userService->trafficFetch((float)$u, (float)$d, (int)$item['user_id'])) { - DB::rollBack(); - return response([ - 'ret' => 0, - 'msg' => 'user fetch fail' - ]); - } + try { + foreach ($data as $item) { + $u = $item['u'] * $server->rate; + $d = $item['d'] * $server->rate; + if (!$userService->trafficFetch((float)$u, (float)$d, (int)$item['user_id'])) { + continue; + } - $serverService->log( - $item['user_id'], - $request->input('node_id'), - $item['u'], - $item['d'], - $server->rate, - 'shadowsocks' - ); + $serverService->log( + $item['user_id'], + $request->input('node_id'), + $item['u'], + $item['d'], + $server->rate, + 'shadowsocks' + ); + } + } catch (\Exception $e) { + DB::rollBack(); + return response([ + 'ret' => 0, + 'msg' => 'user fetch fail' + ]); } DB::commit(); @@ -100,22 +104,4 @@ class ShadowsocksTidalabController extends Controller 'msg' => 'ok' ]); } - - // 后端获取配置 - public function config(Request $request) - { - $nodeId = $request->input('node_id'); - $localPort = $request->input('local_port'); - if (empty($nodeId) || empty($localPort)) { - abort(500, '参数错误'); - } - $serverService = new ServerService(); - try { - $json = $serverService->getTrojanConfig($nodeId, $localPort); - } catch (\Exception $e) { - abort(500, $e->getMessage()); - } - - die(json_encode($json, JSON_UNESCAPED_UNICODE)); - } } diff --git a/app/Http/Controllers/Server/TrojanTidalabController.php b/app/Http/Controllers/Server/TrojanTidalabController.php index 1351ec7c..81cfd0a8 100644 --- a/app/Http/Controllers/Server/TrojanTidalabController.php +++ b/app/Http/Controllers/Server/TrojanTidalabController.php @@ -75,25 +75,29 @@ class TrojanTidalabController extends Controller $serverService = new ServerService(); $userService = new UserService(); DB::beginTransaction(); - foreach ($data as $item) { - $u = $item['u'] * $server->rate; - $d = $item['d'] * $server->rate; - if (!$userService->trafficFetch($u, $d, $item['user_id'])) { - DB::rollBack(); - return response([ - 'ret' => 0, - 'msg' => 'user fetch fail' - ]); - } + try { + foreach ($data as $item) { + $u = $item['u'] * $server->rate; + $d = $item['d'] * $server->rate; + if (!$userService->trafficFetch($u, $d, $item['user_id'])) { + continue; + } - $serverService->log( - $item['user_id'], - $request->input('node_id'), - $item['u'], - $item['d'], - $server->rate, - 'trojan' - ); + $serverService->log( + $item['user_id'], + $request->input('node_id'), + $item['u'], + $item['d'], + $server->rate, + 'trojan' + ); + } + } catch (\Exception $e) { + DB::rollBack(); + return response([ + 'ret' => 0, + 'msg' => 'user fetch fail' + ]); } DB::commit();