update: traffic fetch queue

This commit is contained in:
tokumeikoi
2021-09-01 00:55:07 +09:00
parent fbced4d09b
commit 1d87a1b99a
9 changed files with 134 additions and 240 deletions

View File

@ -2,6 +2,8 @@
namespace App\Services;
use App\Jobs\ServerLogJob;
use App\Jobs\TrafficFetchJob;
use App\Models\InviteCode;
use App\Models\Order;
use App\Models\Server;
@ -80,33 +82,9 @@ class UserService
return true;
}
public function trafficFetch(int $u, int $d, int $userId, object $server, string $protocol):bool
public function trafficFetch(int $u, int $d, int $userId, object $server, string $protocol)
{
$user = User::lockForUpdate()
->find($userId);
if (!$user) {
return true;
}
$user->t = time();
$user->u = $user->u + $u;
$user->d = $user->d + $d;
if (!$user->save()) {
return false;
}
$mailService = new MailService();
$serverService = new ServerService();
try {
$mailService->remindTraffic($user);
$serverService->log(
$userId,
$server->id,
$u,
$d,
$server->rate,
$protocol
);
} catch (\Exception $e) {
}
return true;
TrafficFetchJob::dispatch($u, $d, $userId, $server, $protocol);
ServerLogJob::dispatch($u, $d, $userId, $server, $protocol);
}
}