mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-24 20:17:32 +08:00
feat: new xboard
This commit is contained in:
@@ -12,47 +12,38 @@ use Illuminate\Queue\SerializesModels;
|
||||
class TrafficFetchJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
protected $u;
|
||||
protected $d;
|
||||
protected $userId;
|
||||
protected $data;
|
||||
protected $server;
|
||||
protected $protocol;
|
||||
|
||||
public $tries = 3;
|
||||
public $timeout = 10;
|
||||
protected $timestamp;
|
||||
public $tries = 1;
|
||||
public $timeout = 20;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($u, $d, $userId, array $server, $protocol)
|
||||
public function __construct(array $server, array $data, $protocol, int $timestamp)
|
||||
{
|
||||
$this->onQueue('traffic_fetch');
|
||||
$this->u = $u;
|
||||
$this->d = $d;
|
||||
$this->userId = $userId;
|
||||
$this->server = $server;
|
||||
$this->data = $data;
|
||||
$this->protocol = $protocol;
|
||||
$this->timestamp = $timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): void
|
||||
{
|
||||
\DB::transaction(function () {
|
||||
$user = User::lockForUpdate()->find($this->userId);
|
||||
if (!$user)
|
||||
return;
|
||||
$user->t = time();
|
||||
$user->u = $user->u + ($this->u * $this->server['rate']);
|
||||
$user->d = $user->d + ($this->d * $this->server['rate']);
|
||||
if (!$user->save()) {
|
||||
info("流量更新失败\n未记录用户ID:{$this->userId}\n未记录上行:{$user->u}\n未记录下行:{$user->d}");
|
||||
}
|
||||
});
|
||||
foreach ($this->data as $uid => $v) {
|
||||
User::where('id', $uid)
|
||||
->incrementEach(
|
||||
[
|
||||
'u' => $v[0] * $this->server['rate'],
|
||||
'd' => $v[1] * $this->server['rate'],
|
||||
],
|
||||
['t' => time()]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user