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);
$serverService = new ServerService();
$userService = new UserService();
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'])) {
return response([
'ret' => 0,
'msg' => 'user fetch fail'
]);
continue;
}
$serverService->log(
@ -96,6 +95,14 @@ class DeepbworkController extends Controller
'vmess'
);
}
} catch (\Exception $e) {
DB::rollBack();
return response([
'ret' => 0,
'msg' => 'user fetch fail'
]);
}
DB::commit();
return response([
'ret' => 1,

View File

@ -73,15 +73,12 @@ class ShadowsocksTidalabController extends Controller
$serverService = new ServerService();
$userService = new UserService();
DB::beginTransaction();
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'])) {
DB::rollBack();
return response([
'ret' => 0,
'msg' => 'user fetch fail'
]);
continue;
}
$serverService->log(
@ -93,6 +90,13 @@ class ShadowsocksTidalabController extends Controller
'shadowsocks'
);
}
} catch (\Exception $e) {
DB::rollBack();
return response([
'ret' => 0,
'msg' => 'user fetch fail'
]);
}
DB::commit();
return response([
@ -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));
}
}

View File

@ -75,15 +75,12 @@ class TrojanTidalabController extends Controller
$serverService = new ServerService();
$userService = new UserService();
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'])) {
DB::rollBack();
return response([
'ret' => 0,
'msg' => 'user fetch fail'
]);
continue;
}
$serverService->log(
@ -95,6 +92,13 @@ class TrojanTidalabController extends Controller
'trojan'
);
}
} catch (\Exception $e) {
DB::rollBack();
return response([
'ret' => 0,
'msg' => 'user fetch fail'
]);
}
DB::commit();
return response([