mirror of
https://github.com/cedar2025/Xboard.git
synced 2025-01-22 10:38:14 -05:00
Merge branch 'cedar2025:dev' into dev
This commit is contained in:
commit
1d9cb2295c
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Jobs;
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
@ -17,7 +18,7 @@ class BatchTrafficFetchJob implements ShouldQueue
|
|||||||
protected $protocol;
|
protected $protocol;
|
||||||
protected $timestamp;
|
protected $timestamp;
|
||||||
public $tries = 1;
|
public $tries = 1;
|
||||||
public $timeout = 10;
|
public $timeout = 20;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
@ -36,34 +37,16 @@ class BatchTrafficFetchJob implements ShouldQueue
|
|||||||
|
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
// 获取子节点
|
|
||||||
$targetServer = $this->childServer ?? $this->server;
|
$targetServer = $this->childServer ?? $this->server;
|
||||||
foreach ($this->data as $uid => $v) {
|
foreach ($this->data as $uid => $v) {
|
||||||
$u = $v[0];
|
User::where('id', $uid)
|
||||||
$d = $v[1];
|
->incrementEach(
|
||||||
$result = \DB::transaction(function () use ($uid, $u, $d, $targetServer) {
|
[
|
||||||
$user = \DB::table('v2_user')->lockForUpdate()->where('id', $uid)->first();
|
'u' => $v[0] * $targetServer['rate'],
|
||||||
if (!$user) {
|
'd' => $v[1] * $targetServer['rate'],
|
||||||
return true;
|
],
|
||||||
}
|
['t' => time()]
|
||||||
$newTime = time();
|
);
|
||||||
$newU = $user->u + ($u * $targetServer['rate']);
|
|
||||||
$newD = $user->d + ($d * $targetServer['rate']);
|
|
||||||
$rows = \DB::table('v2_user')
|
|
||||||
->where('id', $uid)
|
|
||||||
->update([
|
|
||||||
't' => $newTime,
|
|
||||||
'u' => $newU,
|
|
||||||
'd' => $newD,
|
|
||||||
]);
|
|
||||||
if ($rows === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}, 3);
|
|
||||||
if (!$result) {
|
|
||||||
TrafficFetchJob::dispatch($u, $d, $uid, $targetServer, $this->protocol);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ class ServerService
|
|||||||
// 获取可用的用户列表
|
// 获取可用的用户列表
|
||||||
public static function getAvailableUsers($groupId): Collection
|
public static function getAvailableUsers($groupId): Collection
|
||||||
{
|
{
|
||||||
return \DB::table('v2_user')
|
return User::toBase()
|
||||||
->whereIn('group_id', $groupId)
|
->whereIn('group_id', $groupId)
|
||||||
->whereRaw('u + d < transfer_enable')
|
->whereRaw('u + d < transfer_enable')
|
||||||
->where(function ($query) {
|
->where(function ($query) {
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.1",
|
"php": "^8.1",
|
||||||
|
"cedar2025/http-foundation": "6.4.x-dev",
|
||||||
"cweagans/composer-patches": "^1.7",
|
"cweagans/composer-patches": "^1.7",
|
||||||
"doctrine/dbal": "^3.7",
|
"doctrine/dbal": "^3.7",
|
||||||
"firebase/php-jwt": "^6.3",
|
"firebase/php-jwt": "^6.3",
|
||||||
@ -20,7 +21,7 @@
|
|||||||
"guzzlehttp/guzzle": "^7.4.3",
|
"guzzlehttp/guzzle": "^7.4.3",
|
||||||
"hhxsv5/laravel-s": "~3.7.0",
|
"hhxsv5/laravel-s": "~3.7.0",
|
||||||
"joanhey/adapterman": "^0.6.1",
|
"joanhey/adapterman": "^0.6.1",
|
||||||
"laravel/framework": "^10.0",
|
"laravel/framework": "10.48.22",
|
||||||
"laravel/horizon": "^5.9.6",
|
"laravel/horizon": "^5.9.6",
|
||||||
"laravel/tinker": "^2.5",
|
"laravel/tinker": "^2.5",
|
||||||
"linfo/linfo": "^4.0",
|
"linfo/linfo": "^4.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user