mirror of
https://github.com/v2board/v2board.git
synced 2025-01-10 16:19:10 +08:00
update: server submit
This commit is contained in:
parent
59a8429456
commit
9917e21a61
@ -64,7 +64,7 @@ class DeepbworkController extends Controller
|
||||
// 后端提交数据
|
||||
public function submit(Request $request)
|
||||
{
|
||||
// Log::info('serverSubmitData:' . $request->input('node_id') . ':' . file_get_contents('php://input'));
|
||||
Log::info('serverSubmitData:' . $request->input('node_id') . ':' . file_get_contents('php://input'));
|
||||
$server = Server::find($request->input('node_id'));
|
||||
if (!$server) {
|
||||
return response([
|
||||
@ -75,25 +75,15 @@ class DeepbworkController extends Controller
|
||||
$data = file_get_contents('php://input');
|
||||
$data = json_decode($data, true);
|
||||
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'])) {
|
||||
if (!$userService->trafficFetch($u, $d, $item['user_id'], $server, 'vmess')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$serverService->log(
|
||||
$item['user_id'],
|
||||
$request->input('node_id'),
|
||||
$item['u'],
|
||||
$item['d'],
|
||||
$server->rate,
|
||||
'vmess'
|
||||
);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
|
@ -68,23 +68,13 @@ class PoseidonController extends Controller
|
||||
$data = file_get_contents('php://input');
|
||||
$data = json_decode($data, true);
|
||||
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'])) {
|
||||
if (!$userService->trafficFetch($u, $d, $item['user_id'], $server, 'vmess')) {
|
||||
return $this->error("user fetch fail", 500);
|
||||
}
|
||||
|
||||
$serverService->log(
|
||||
$item['user_id'],
|
||||
$request->input('node_id'),
|
||||
$item['u'],
|
||||
$item['d'],
|
||||
$server->rate,
|
||||
'vmess'
|
||||
);
|
||||
}
|
||||
|
||||
return $this->success('');
|
||||
|
@ -70,25 +70,15 @@ class ShadowsocksTidalabController extends Controller
|
||||
$data = file_get_contents('php://input');
|
||||
$data = json_decode($data, true);
|
||||
Cache::put(CacheKey::get('SERVER_SHADOWSOCKS_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((float)$u, (float)$d, (int)$item['user_id'])) {
|
||||
if (!$userService->trafficFetch((float)$u, (float)$d, (int)$item['user_id'], $server, 'shadowsocks')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$serverService->log(
|
||||
$item['user_id'],
|
||||
$request->input('node_id'),
|
||||
$item['u'],
|
||||
$item['d'],
|
||||
$server->rate,
|
||||
'shadowsocks'
|
||||
);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
|
@ -72,25 +72,15 @@ class TrojanTidalabController extends Controller
|
||||
$data = file_get_contents('php://input');
|
||||
$data = json_decode($data, true);
|
||||
Cache::put(CacheKey::get('SERVER_TROJAN_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'])) {
|
||||
if (!$userService->trafficFetch($u, $d, $item['user_id'], $server, 'trojan')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$serverService->log(
|
||||
$item['user_id'],
|
||||
$request->input('node_id'),
|
||||
$item['u'],
|
||||
$item['d'],
|
||||
$server->rate,
|
||||
'trojan'
|
||||
);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
|
@ -43,7 +43,6 @@ class Kernel extends HttpKernel
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\App\Http\Middleware\ForceJson::class,
|
||||
\App\Http\Middleware\CORS::class,
|
||||
'throttle:120,1',
|
||||
'bindings',
|
||||
],
|
||||
];
|
||||
|
@ -270,6 +270,7 @@ class ServerService
|
||||
->where('user_id', $userId)
|
||||
->where('rate', $rate)
|
||||
->where('method', $method)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
if ($serverLog) {
|
||||
$serverLog->u = $serverLog->u + $u;
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Order;
|
||||
use App\Models\Server;
|
||||
use App\Models\User;
|
||||
|
||||
class UserService
|
||||
@ -76,9 +77,10 @@ class UserService
|
||||
return true;
|
||||
}
|
||||
|
||||
public function trafficFetch(int $u, int $d, int $userId):bool
|
||||
public function trafficFetch(int $u, int $d, int $userId, Server $server, string $protocol):bool
|
||||
{
|
||||
$user = User::find($userId);
|
||||
$user = User::lockForUpdate()
|
||||
->find($userId);
|
||||
if (!$user) {
|
||||
return true;
|
||||
}
|
||||
@ -88,9 +90,18 @@ class UserService
|
||||
if (!$user->save()) {
|
||||
return false;
|
||||
}
|
||||
$mailService = new MailService();
|
||||
$serverService = new ServerService();
|
||||
try {
|
||||
$mailService = new MailService();
|
||||
$mailService->remindTraffic($user);
|
||||
$serverService->log(
|
||||
$userId,
|
||||
$server->id,
|
||||
$u,
|
||||
$d,
|
||||
$server->rate,
|
||||
$protocol
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user