mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-24 03:57:27 +08:00
Initial commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Order;
|
||||
use App\Services\OrderService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class OrderHandleJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
protected $order;
|
||||
|
||||
public $tries = 3;
|
||||
public $timeout = 5;
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($tradeNo)
|
||||
{
|
||||
$this->onQueue('order_handle');
|
||||
$this->order = Order::where('trade_no', $tradeNo)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (!$this->order) return;
|
||||
$orderService = new OrderService($this->order);
|
||||
switch ($this->order->status) {
|
||||
// cancel
|
||||
case 0:
|
||||
if ($this->order->created_at <= (time() - 3600 * 2)) {
|
||||
$orderService->cancel();
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
$orderService->open();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Models\MailLog;
|
||||
|
||||
class SendEmailJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
protected $params;
|
||||
|
||||
public $tries = 3;
|
||||
public $timeout = 10;
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params, $queue = 'send_email')
|
||||
{
|
||||
$this->onQueue($queue);
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (admin_setting('email_host')) {
|
||||
Config::set('mail.host', admin_setting('email_host', env('mail.host')));
|
||||
Config::set('mail.port', admin_setting('email_port', env('mail.port')));
|
||||
Config::set('mail.encryption', admin_setting('email_encryption', env('mail.encryption')));
|
||||
Config::set('mail.username', admin_setting('email_username', env('mail.username')));
|
||||
Config::set('mail.password', admin_setting('email_password', env('mail.password')));
|
||||
Config::set('mail.from.address', admin_setting('email_from_address', env('mail.from.address')));
|
||||
Config::set('mail.from.name', admin_setting('app_name', 'XBoard'));
|
||||
}
|
||||
$params = $this->params;
|
||||
$email = $params['email'];
|
||||
$subject = $params['subject'];
|
||||
$params['template_name'] = 'mail.' . admin_setting('email_template', 'default') . '.' . $params['template_name'];
|
||||
try {
|
||||
Mail::send(
|
||||
$params['template_name'],
|
||||
$params['template_value'],
|
||||
function ($message) use ($email, $subject) {
|
||||
$message->to($email)->subject($subject);
|
||||
}
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
|
||||
$log = [
|
||||
'email' => $params['email'],
|
||||
'subject' => $params['subject'],
|
||||
'template_name' => $params['template_name'],
|
||||
'error' => isset($error) ? $error : NULL
|
||||
];
|
||||
|
||||
MailLog::create($log);
|
||||
$log['config'] = config('mail');
|
||||
return $log;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Services\TelegramService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class SendTelegramJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
protected $telegramId;
|
||||
protected $text;
|
||||
|
||||
public $tries = 3;
|
||||
public $timeout = 10;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(int $telegramId, string $text)
|
||||
{
|
||||
$this->onQueue('send_telegram');
|
||||
$this->telegramId = $telegramId;
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$telegramService = new TelegramService();
|
||||
$telegramService->sendMessage($this->telegramId, $this->text, 'markdown');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\MailService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class TrafficFetchJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
protected $u;
|
||||
protected $d;
|
||||
protected $userId;
|
||||
protected $server;
|
||||
protected $protocol;
|
||||
|
||||
public $tries = 3;
|
||||
public $timeout = 10;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($u, $d, $userId, array $server, $protocol)
|
||||
{
|
||||
$this->onQueue('traffic_fetch');
|
||||
$this->u = $u;
|
||||
$this->d = $d;
|
||||
$this->userId = $userId;
|
||||
$this->server = $server;
|
||||
$this->protocol = $protocol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
\DB::transaction(function () {
|
||||
$user = \DB::table('v2_user')->lockForUpdate()->where('id', $this->userId)->first();
|
||||
|
||||
if (!$user) {
|
||||
return;
|
||||
}
|
||||
|
||||
$newTime = time();
|
||||
$newU = $user->u + ($this->u * $this->server['rate']);
|
||||
$newD = $user->d + ($this->d * $this->server['rate']);
|
||||
|
||||
$updatedRows = \DB::table('v2_user')
|
||||
->where('id', $this->userId)
|
||||
->update([
|
||||
't' => $newTime,
|
||||
'u' => $newU,
|
||||
'd' => $newD,
|
||||
]);
|
||||
|
||||
if (!$updatedRows) {
|
||||
info("流量更新失败\n未记录用户ID:{$this->userId}\n未记录上行:{$this->u}\n未记录下行:{$this->d}");
|
||||
$this->fail();
|
||||
} else {
|
||||
|
||||
}
|
||||
}, 3);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user