update: traffic submit

This commit is contained in:
Tokumeikoi 2020-11-07 16:38:57 +08:00
parent 675353bbe1
commit 7042dce0a1
3 changed files with 68 additions and 71 deletions

View File

@ -77,14 +77,13 @@ class DeepbworkController extends Controller
Cache::put(CacheKey::get('SERVER_V2RAY_ONLINE_USER', $server->id), count($data), 3600); Cache::put(CacheKey::get('SERVER_V2RAY_ONLINE_USER', $server->id), count($data), 3600);
$serverService = new ServerService(); $serverService = new ServerService();
$userService = new UserService(); $userService = new UserService();
DB::beginTransaction();
try {
foreach ($data as $item) { foreach ($data as $item) {
$u = $item['u'] * $server->rate; $u = $item['u'] * $server->rate;
$d = $item['d'] * $server->rate; $d = $item['d'] * $server->rate;
if (!$userService->trafficFetch($u, $d, $item['user_id'])) { if (!$userService->trafficFetch($u, $d, $item['user_id'])) {
return response([ continue;
'ret' => 0,
'msg' => 'user fetch fail'
]);
} }
$serverService->log( $serverService->log(
@ -96,6 +95,14 @@ class DeepbworkController extends Controller
'vmess' 'vmess'
); );
} }
} catch (\Exception $e) {
DB::rollBack();
return response([
'ret' => 0,
'msg' => 'user fetch fail'
]);
}
DB::commit();
return response([ return response([
'ret' => 1, 'ret' => 1,

View File

@ -73,15 +73,12 @@ class ShadowsocksTidalabController extends Controller
$serverService = new ServerService(); $serverService = new ServerService();
$userService = new UserService(); $userService = new UserService();
DB::beginTransaction(); DB::beginTransaction();
try {
foreach ($data as $item) { foreach ($data as $item) {
$u = $item['u'] * $server->rate; $u = $item['u'] * $server->rate;
$d = $item['d'] * $server->rate; $d = $item['d'] * $server->rate;
if (!$userService->trafficFetch((float)$u, (float)$d, (int)$item['user_id'])) { if (!$userService->trafficFetch((float)$u, (float)$d, (int)$item['user_id'])) {
DB::rollBack(); continue;
return response([
'ret' => 0,
'msg' => 'user fetch fail'
]);
} }
$serverService->log( $serverService->log(
@ -93,6 +90,13 @@ class ShadowsocksTidalabController extends Controller
'shadowsocks' 'shadowsocks'
); );
} }
} catch (\Exception $e) {
DB::rollBack();
return response([
'ret' => 0,
'msg' => 'user fetch fail'
]);
}
DB::commit(); DB::commit();
return response([ return response([
@ -100,22 +104,4 @@ class ShadowsocksTidalabController extends Controller
'msg' => 'ok' '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));
}
} }

View File

@ -75,15 +75,12 @@ class TrojanTidalabController extends Controller
$serverService = new ServerService(); $serverService = new ServerService();
$userService = new UserService(); $userService = new UserService();
DB::beginTransaction(); DB::beginTransaction();
try {
foreach ($data as $item) { foreach ($data as $item) {
$u = $item['u'] * $server->rate; $u = $item['u'] * $server->rate;
$d = $item['d'] * $server->rate; $d = $item['d'] * $server->rate;
if (!$userService->trafficFetch($u, $d, $item['user_id'])) { if (!$userService->trafficFetch($u, $d, $item['user_id'])) {
DB::rollBack(); continue;
return response([
'ret' => 0,
'msg' => 'user fetch fail'
]);
} }
$serverService->log( $serverService->log(
@ -95,6 +92,13 @@ class TrojanTidalabController extends Controller
'trojan' 'trojan'
); );
} }
} catch (\Exception $e) {
DB::rollBack();
return response([
'ret' => 0,
'msg' => 'user fetch fail'
]);
}
DB::commit(); DB::commit();
return response([ return response([