改进 代码
This commit is contained in:
parent
d840631b18
commit
2821c1a275
@ -4,6 +4,7 @@
|
||||
|
||||
use App\Models\Admin;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Command\Command as CommandAlias;
|
||||
|
||||
class All extends Command
|
||||
{
|
||||
@ -26,7 +27,7 @@ class All extends Command
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): int
|
||||
{
|
||||
|
||||
$admins = Admin::all();
|
||||
@ -38,6 +39,6 @@ public function handle()
|
||||
];
|
||||
})->toArray());
|
||||
|
||||
return Command::SUCCESS;
|
||||
return CommandAlias::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public function handle(): int
|
||||
}
|
||||
|
||||
// 创建管理员
|
||||
$admin = Admin::create([
|
||||
$admin = (new Admin)->create([
|
||||
'email' => $email,
|
||||
'password' => bcrypt($password)
|
||||
]);
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
use App\Models\Admin;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Command\Command as CommandAlias;
|
||||
|
||||
class Delete extends Command
|
||||
{
|
||||
@ -26,7 +27,7 @@ class Delete extends Command
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): int
|
||||
{
|
||||
// 获取管理员ID
|
||||
$id = $this->ask('请输入管理员ID');
|
||||
@ -36,6 +37,6 @@ public function handle()
|
||||
|
||||
// 输出信息
|
||||
$this->info('管理员删除成功。');
|
||||
return Command::SUCCESS;
|
||||
return CommandAlias::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
use App\Models\Admin;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Command\Command as CommandAlias;
|
||||
|
||||
class Reset extends Command
|
||||
{
|
||||
@ -26,19 +27,19 @@ class Reset extends Command
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): int
|
||||
{
|
||||
|
||||
// 获取管理员ID
|
||||
$id = $this->ask('请输入管理员ID');
|
||||
|
||||
// 获取管理员
|
||||
$admin = Admin::find($id);
|
||||
$admin = (new Admin)->find($id);
|
||||
|
||||
// 验证管理员
|
||||
if (is_null($admin)) {
|
||||
$this->error('管理员不存在。');
|
||||
return Command::FAILURE;
|
||||
return CommandAlias::FAILURE;
|
||||
}
|
||||
|
||||
// 密码
|
||||
@ -50,6 +51,6 @@ public function handle()
|
||||
// 输出信息
|
||||
$this->info('管理员密码重置成功。');
|
||||
|
||||
return Command::SUCCESS;
|
||||
return CommandAlias::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public function __construct()
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): int
|
||||
{
|
||||
//
|
||||
|
||||
@ -44,7 +44,7 @@ public function handle()
|
||||
|
||||
$reason = $this->argument('reason');
|
||||
|
||||
$user = User::find($user_id);
|
||||
$user = (new User)->find($user_id);
|
||||
|
||||
$this->info('封禁: ' . $user->name);
|
||||
|
||||
|
@ -36,13 +36,13 @@ public function __construct()
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): int
|
||||
{
|
||||
$this->warn('开始计算集成模块收益。');
|
||||
$this->warn('当前时间: ' . now());
|
||||
|
||||
|
||||
Module::chunk(100, function ($modules) {
|
||||
(new Module)->chunk(100, function ($modules) {
|
||||
foreach ($modules as $module) {
|
||||
$this->warn('模块: ' . $module->name);
|
||||
$years = $module->calculate();
|
||||
@ -57,7 +57,7 @@ public function handle()
|
||||
foreach ($months as $month => $m) {
|
||||
$total += round($m['balance'], 2);
|
||||
$total_should += round($m['should_balance'], 2);
|
||||
$this->info("{$module->name} {$year}年 {$month}月 实收: {$total}元 应得: {$total_should} 元");
|
||||
$this->info("$module->name {$year}年 {$month}月 实收: {$total}元 应得: $total_should 元");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ private function format(string $event, array $message = [])
|
||||
return;
|
||||
}
|
||||
|
||||
$message = "[{$message['node']['type']}] {$message['node']['id']}:{$event}: " . $status;
|
||||
$message = "[{$message['node']['type']}] {$message['node']['id']}:$event: " . $status;
|
||||
|
||||
$this->info($message);
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public function handle(): int
|
||||
$cache_path = base_path('config');
|
||||
|
||||
// exec
|
||||
$cmd = "rm -rf {$cache_path}";
|
||||
$cmd = "rm -rf $cache_path";
|
||||
exec($cmd);
|
||||
|
||||
|
||||
@ -118,7 +118,7 @@ public function handle(): int
|
||||
$env = file_get_contents(base_path('.env'));
|
||||
|
||||
// REPLACE NODE_IP 这一行
|
||||
$env = preg_replace('/^NODE_IP=.*$/m', "NODE_IP={$node_ip}", $env);
|
||||
$env = preg_replace('/^NODE_IP=.*$/m', "NODE_IP=$node_ip", $env);
|
||||
|
||||
file_put_contents(base_path('.env'), $env);
|
||||
|
||||
|
@ -84,7 +84,7 @@ public function handle(): int
|
||||
|
||||
public function upload($node_type)
|
||||
{
|
||||
$this->warn("正在上传 {$node_type} 文件。");
|
||||
$this->warn("正在上传 $node_type 文件。");
|
||||
$this->info('正在打包 config 目录。');
|
||||
|
||||
if ($node_type === 'master') {
|
||||
|
@ -47,22 +47,22 @@ public function handle(): int
|
||||
|
||||
$version = config('settings.roadrunner.version');
|
||||
|
||||
$download_link = "https://github.sakurapuare.com/roadrunner-server/roadrunner/releases/download/v{$version}/roadrunner-{$version}-{$os}-{$arch}.tar.gz";
|
||||
$download_link = "https://github.sakurapuare.com/roadrunner-server/roadrunner/releases/download/v$version/roadrunner-$version-$os-$arch.tar.gz";
|
||||
|
||||
$save_name = 'rr_download.tar.gz';
|
||||
|
||||
// 下载(wget)
|
||||
exec("wget {$download_link} -O {$save_name}");
|
||||
exec("tar -zxvf {$save_name}");
|
||||
exec("wget $download_link -O $save_name");
|
||||
exec("tar -zxvf $save_name");
|
||||
|
||||
// 删除下载的压缩包
|
||||
exec("rm {$save_name}");
|
||||
exec("rm $save_name");
|
||||
|
||||
// 提取解压目录下的 rr 文件
|
||||
exec("mv roadrunner-{$version}-{$os}-$arch/rr rr");
|
||||
exec("mv roadrunner-$version-$os-$arch/rr rr");
|
||||
|
||||
// 删除解压目录
|
||||
exec("rm -rf roadrunner-{$version}-{$os}-$arch");
|
||||
exec("rm -rf roadrunner-$version-$os-$arch");
|
||||
|
||||
// 设置 rr 可执行权限
|
||||
exec("chmod +x rr");
|
||||
@ -236,7 +236,7 @@ private function dispatchEvent($event, $message = []): void
|
||||
];
|
||||
|
||||
if (isset($events[$event])) {
|
||||
$this->warn("正在处理 {$event} 事件。");
|
||||
$this->warn("正在处理 $event 事件。");
|
||||
$events[$event]($message);
|
||||
}
|
||||
}
|
||||
|
@ -41,44 +41,44 @@ public function __construct()
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): int
|
||||
{
|
||||
//
|
||||
|
||||
$this->info('正在获取用户数量...');
|
||||
$users = User::count();
|
||||
$transactions = new Transaction();
|
||||
$users = (new User)->count();
|
||||
// $transactions = new Transaction();
|
||||
|
||||
// 获取今年的交易记录 (MongoDB)
|
||||
$startOfYear = now()->startOfYear();
|
||||
$endOfYear = now()->endOfYear();
|
||||
|
||||
$this->info('正在获取交易记录...');
|
||||
$transactions = Transaction::where('type', 'payout')->whereBetween('created_at', [$startOfYear, $endOfYear])->count();
|
||||
$transactions = (new Transaction)->where('type', 'payout')->whereBetween('created_at', [$startOfYear, $endOfYear])->count();
|
||||
|
||||
$this->info('正在获取主机数量...');
|
||||
$hosts = Host::count();
|
||||
$hosts = (new Host)->count();
|
||||
|
||||
$this->info('正在获取部署中的主机数量...');
|
||||
$pending_hosts = Host::where('status', 'pending')->count();
|
||||
$pending_hosts = (new Host)->where('status', 'pending')->count();
|
||||
|
||||
$this->info('正在获取已停止的主机数量...');
|
||||
$stopped_hosts = Host::where('status', 'stopped')->count();
|
||||
$stopped_hosts = (new Host)->where('status', 'stopped')->count();
|
||||
|
||||
$this->info('正在获取部署失败的主机数量...');
|
||||
$error_hosts = Host::where('status', 'error')->count();
|
||||
$error_hosts = (new Host)->where('status', 'error')->count();
|
||||
|
||||
$this->info('正在获取激活的主机数量...');
|
||||
$active_hosts = Host::where('status', 'running')->count();
|
||||
$active_hosts = (new Host)->where('status', 'running')->count();
|
||||
|
||||
$this->info('正在获取暂停的主机数量...');
|
||||
$suspended_hosts = Host::whereNotNull('suspended_at')->count();
|
||||
$suspended_hosts = (new Host)->whereNotNull('suspended_at')->count();
|
||||
|
||||
$this->info('正在获取工单数量...');
|
||||
$workOrders = WorkOrder::count();
|
||||
$workOrders = (new WorkOrder)->count();
|
||||
|
||||
$this->info('正在获取工单回复数量...');
|
||||
$replies = Reply::count();
|
||||
$replies = (new Reply)->count();
|
||||
|
||||
$this->info('统计服务器...');
|
||||
$servers = Cache::get('servers', []);
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
use App\Models\Balance;
|
||||
use App\Models\Host;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
@ -39,15 +38,15 @@ public function __construct()
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): int
|
||||
{
|
||||
//
|
||||
$email_or_id = $this->argument('email_or_id');
|
||||
|
||||
$user = User::where('email', $email_or_id)->orWhere('id', $email_or_id)->orWhere('name', $email_or_id)->first();
|
||||
$user = (new User)->where('email', $email_or_id)->orWhere('id', $email_or_id)->orWhere('name', $email_or_id)->first();
|
||||
|
||||
|
||||
$transaction = new Transaction();
|
||||
// $transaction = new Transaction();
|
||||
|
||||
$this->warn('用户基本信息');
|
||||
|
||||
@ -58,7 +57,7 @@ public function handle()
|
||||
|
||||
$this->warn('前 10 条充值记录');
|
||||
|
||||
$balances = Balance::where('user_id', $user->id)->whereNotNull('paid_at')->latest()->limit(10)->get();
|
||||
$balances = (new Balance)->where('user_id', $user->id)->whereNotNull('paid_at')->latest()->limit(10)->get();
|
||||
|
||||
// 倒序输出
|
||||
foreach (array_reverse($balances->toArray()) as $balance) {
|
||||
@ -67,7 +66,7 @@ public function handle()
|
||||
|
||||
$this->warn('前 10 个主机');
|
||||
|
||||
$hosts = Host::where('user_id', $user->id)->with('module')->latest()->limit(10)->get();
|
||||
$hosts = (new Host)->where('user_id', $user->id)->with('module')->latest()->limit(10)->get();
|
||||
|
||||
// 倒序
|
||||
foreach (array_reverse($hosts->toArray()) as $host) {
|
||||
|
@ -33,7 +33,7 @@ public function handle(): int
|
||||
|
||||
if (empty($host)) {
|
||||
if ($this->confirm('如果不指定主机名,将会扣除所有主机的费用,是否继续?', true)) {
|
||||
Host::chunk(100, function ($hosts) {
|
||||
(new Host)->chunk(100, function ($hosts) {
|
||||
foreach ($hosts as $host) {
|
||||
$this->info('正在扣除主机 ' . $host->name . ' 的费用: ' . $host->getPrice() . ' 元');
|
||||
$host->cost();
|
||||
@ -41,7 +41,7 @@ public function handle(): int
|
||||
});
|
||||
}
|
||||
} else {
|
||||
$host_model = Host::where('id', $host)->firstOrFail();
|
||||
$host_model = (new Host)->where('id', $host)->firstOrFail();
|
||||
|
||||
|
||||
if ($this->confirm('是否扣除主机 ' . $host_model->name . ' 的费用?', true)) {
|
||||
|
@ -1,123 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use PhpMqtt\Client\Facades\MQTT as MqttClient;
|
||||
|
||||
class Mqtt extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'mqtt:run';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
declare(ticks=1);
|
||||
pcntl_signal(SIGINT, function () {
|
||||
$this->info('Stopping...');
|
||||
// 关闭子进程
|
||||
posix_kill($pid, SIGKILL);
|
||||
exit;
|
||||
});
|
||||
|
||||
// MQTT::publish('some/topic', 'Hello World!');
|
||||
|
||||
$tasks = [
|
||||
'publish' => function () {
|
||||
$this->info('Publishing...');
|
||||
|
||||
MqttClient::publish('some/topic', 'Hello World!');
|
||||
|
||||
sleep(1);
|
||||
|
||||
|
||||
return true;
|
||||
},
|
||||
'subscribe' => function () {
|
||||
$this->info('Subscribing...');
|
||||
|
||||
$mqtt = MqttClient::connection();
|
||||
$mqtt->subscribe('some/topic', function (string $topic, string $message) {
|
||||
echo sprintf('Received QoS level 1 message on topic [%s]: %s', $topic, $message) . PHP_EOL;
|
||||
}, 1);
|
||||
$mqtt->loop();
|
||||
|
||||
return true;
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
foreach ($tasks as $key => $task) {
|
||||
$this->info('Starting task: ' . $key);
|
||||
$pid = pcntl_fork();
|
||||
if ($pid == -1) {
|
||||
die('could not fork');
|
||||
} else if ($pid) {
|
||||
// we are the parent
|
||||
// pcntl_wait($status); //Protect against Zombie children
|
||||
|
||||
|
||||
// while (pcntl_waitpid(0, $status) != -1) {
|
||||
// $status = pcntl_wexitstatus($status);
|
||||
// echo "Child $status completed\n";
|
||||
// }
|
||||
} else {
|
||||
// we are the child
|
||||
while (true) {
|
||||
if ($task() === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Command::SUCCESS;
|
||||
|
||||
// // 开启新的进程,处理 MQTT 消息
|
||||
// $running = 0; // 记录正在运行的子进程数
|
||||
// for ($i = 0; $i < $task_num; $i++) {
|
||||
// $pid = pcntl_fork();
|
||||
// if ($pid == -1) {
|
||||
// die('could not fork');
|
||||
// } else if ($pid) {
|
||||
// $running++; // 进程数+1
|
||||
// if ($running >= $max_process) { // 子进程开启数量达到上限
|
||||
// pcntl_wait($status); // 等待有子进程退出
|
||||
// $running--; // 有子进程退出,进程数-1
|
||||
// }
|
||||
// } else {
|
||||
// // 子进程
|
||||
// echo "子进程开始" . PHP_EOL;
|
||||
// while (true) {
|
||||
// MqttClient::publish('some/topic', 'Hello World!');
|
||||
// // sleep(0.5);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// while ($running) {
|
||||
// pcntl_wait($status);
|
||||
// $running--;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -37,7 +37,7 @@ public function __construct()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): void
|
||||
{
|
||||
//
|
||||
|
||||
@ -46,7 +46,7 @@ public function handle()
|
||||
$amount = $this->argument('amount');
|
||||
|
||||
|
||||
$user = User::find($user_id);
|
||||
$user = (new User)->find($user_id);
|
||||
|
||||
$this->warn('扣除金额: ' . $amount . ' 元');
|
||||
|
||||
|
@ -37,7 +37,7 @@ public function __construct()
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): int
|
||||
{
|
||||
|
||||
$this->warn('===== 运行环境 =====');
|
||||
|
@ -36,13 +36,13 @@ public function __construct()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): void
|
||||
{
|
||||
//
|
||||
|
||||
$user_id = $this->argument('user_id');
|
||||
|
||||
Host::where('user_id', $user_id)->update([
|
||||
(new Host)->where('user_id', $user_id)->update([
|
||||
'status' => 'suspended',
|
||||
'suspended_at' => now()
|
||||
]);
|
||||
|
@ -36,13 +36,13 @@ public function __construct()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): void
|
||||
{
|
||||
//
|
||||
|
||||
$user_id = $this->argument('user_id');
|
||||
|
||||
$user = User::find($user_id);
|
||||
$user = (new User)->find($user_id);
|
||||
|
||||
$this->info('解除封禁: ' . $user->name);
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Exceptions\ChargeException;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
@ -38,7 +37,7 @@ public function __construct()
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): int
|
||||
{
|
||||
//
|
||||
|
||||
@ -47,7 +46,7 @@ public function handle()
|
||||
|
||||
|
||||
// find user
|
||||
$user = User::findOrFail($user_id);
|
||||
$user = (new User)->findOrFail($user_id);
|
||||
|
||||
$this->info($user->name . ', 当前余额: ' . $user->balance . ' 元');
|
||||
|
||||
@ -61,16 +60,12 @@ public function handle()
|
||||
|
||||
$description = '控制台充值 ' . $amount . ' 元';
|
||||
|
||||
try {
|
||||
$transaction->addAmount($user->id, 'console', $amount, $description, true);
|
||||
|
||||
$this->info('充值成功。');
|
||||
|
||||
$user->refresh();
|
||||
$this->info($user->name . ', 当前余额: ' . $user->balance);
|
||||
} catch (ChargeException $e) {
|
||||
$this->error('充值失败: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
|
@ -21,9 +21,4 @@ public function broadcastOn(): Channel
|
||||
{
|
||||
return new Channel('servers');
|
||||
}
|
||||
|
||||
public function broadcastAs()
|
||||
{
|
||||
return 'servers';
|
||||
}
|
||||
}
|
||||
|
34
app/Events/Tasks.php
Normal file
34
app/Events/Tasks.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class Tasks
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return Channel|PrivateChannel
|
||||
*/
|
||||
public function broadcastOn(): Channel|PrivateChannel
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
@ -47,20 +46,19 @@ class Handler extends ExceptionHandler
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->reportable(function (Throwable $e) {
|
||||
// custom json 404 response
|
||||
if ($e instanceof NotFoundHttpException) {
|
||||
return response()->json([
|
||||
'message' => 'Not Found',
|
||||
'errors' => [
|
||||
'code' => 404,
|
||||
'message' => 'Not Found'
|
||||
]
|
||||
], 404);
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
// $this->reportable(function (Throwable $e) {
|
||||
// // custom json 404 response
|
||||
// if ($e instanceof NotFoundHttpException) {
|
||||
// return response()->json([
|
||||
// 'message' => 'Not Found',
|
||||
// 'errors' => [
|
||||
// 'code' => 404,
|
||||
// 'message' => 'Not Found'
|
||||
// ]
|
||||
// ], 404);
|
||||
// }
|
||||
// return response();
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,14 +122,14 @@ public function accepted($message = 'Accepted'): JsonResponse
|
||||
|
||||
public function updated($message = 'Updated'): JsonResponse
|
||||
{
|
||||
return $this->success($message, 200);
|
||||
return $this->success($message);
|
||||
}
|
||||
|
||||
// server error
|
||||
|
||||
public function deleted($message = 'Deleted'): JsonResponse
|
||||
{
|
||||
return $this->success($message, 200);
|
||||
return $this->success($message);
|
||||
}
|
||||
|
||||
// service unavailable
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace App\Helpers;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Cache\LockTimeoutException;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
trait Lock
|
||||
@ -11,15 +10,13 @@ trait Lock
|
||||
public function await($name, Closure $callback)
|
||||
{
|
||||
// if env is local
|
||||
if (env('APP_ENV') == 'local') {
|
||||
if (config('app.env') == 'local') {
|
||||
return $callback();
|
||||
}
|
||||
$lock = Cache::lock("lock_" . $name, 5);
|
||||
try {
|
||||
$lock->block(5);
|
||||
return $callback();
|
||||
} catch (LockTimeoutException $e) {
|
||||
return false;
|
||||
} finally {
|
||||
optional($lock)->release();
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ class AdminController extends Controller
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$admins = Admin::paginate(50);
|
||||
$admins = (new Admin)->paginate(50);
|
||||
|
||||
return view('admin.admins.index', compact('admins'));
|
||||
}
|
||||
@ -40,7 +40,7 @@ public function store(Request $request): RedirectResponse
|
||||
// 随机密码
|
||||
$password = Str::random();
|
||||
|
||||
$admin = Admin::create([
|
||||
$admin = (new Admin)->create([
|
||||
'email' => $request->input('email'),
|
||||
'password' => bcrypt($password),
|
||||
]);
|
||||
@ -121,7 +121,7 @@ public function destroy(Admin $admin): RedirectResponse
|
||||
}
|
||||
|
||||
// 不能删除最后一个管理员
|
||||
if (Admin::count() == 1) {
|
||||
if ((new Admin)->count() == 1) {
|
||||
return redirect()->back()->with('error', '不能删除最后一个管理员。');
|
||||
}
|
||||
|
||||
|
@ -15,11 +15,9 @@ class ApplicationController extends Controller
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function index()
|
||||
public function index(): View
|
||||
{
|
||||
//
|
||||
|
||||
$applications = Application::paginate(100);
|
||||
$applications = (new Application)->paginate(100);
|
||||
|
||||
return view('admin.applications.index', compact('applications'));
|
||||
}
|
||||
@ -31,7 +29,7 @@ public function index()
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function store(Request $request)
|
||||
public function store(Request $request): View
|
||||
{
|
||||
//
|
||||
|
||||
@ -41,7 +39,7 @@ public function store(Request $request)
|
||||
'api_token' => 'required|unique:applications,api_token',
|
||||
]);
|
||||
|
||||
$application = Application::create($request->all());
|
||||
$application = (new Application)->create($request->all());
|
||||
|
||||
return view('admin.applications.edit', compact('application'));
|
||||
}
|
||||
@ -51,7 +49,7 @@ public function store(Request $request)
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function create()
|
||||
public function create(): View
|
||||
{
|
||||
//
|
||||
|
||||
@ -65,7 +63,7 @@ public function create()
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function show(Application $application)
|
||||
public function show(Application $application): RedirectResponse
|
||||
{
|
||||
//
|
||||
|
||||
@ -79,7 +77,7 @@ public function show(Application $application)
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function edit(Application $application)
|
||||
public function edit(Application $application): View
|
||||
{
|
||||
//
|
||||
|
||||
@ -94,7 +92,7 @@ public function edit(Application $application)
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, Application $application)
|
||||
public function update(Request $request, Application $application): RedirectResponse
|
||||
{
|
||||
//
|
||||
|
||||
@ -116,7 +114,7 @@ public function update(Request $request, Application $application)
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function destroy(Application $application)
|
||||
public function destroy(Application $application): RedirectResponse
|
||||
{
|
||||
//
|
||||
|
||||
|
@ -6,23 +6,25 @@
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\EmqxSupport;
|
||||
use Illuminate\Http\Client\ConnectionException;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class DeviceController extends Controller
|
||||
{
|
||||
//
|
||||
|
||||
public function index(Request $request)
|
||||
public function index(Request $request): RedirectResponse|View
|
||||
{
|
||||
$emqx = new EmqxSupport();
|
||||
|
||||
try {
|
||||
$clients = $emqx->clients([
|
||||
'clientid' => $request->client_id,
|
||||
'username' => $request->username,
|
||||
'page' => $request->page,
|
||||
'clientid' => $request->input('client_id'),
|
||||
'username' => $request->input('username'),
|
||||
'page' => $request->input('page'),
|
||||
]);
|
||||
} catch (EmqxSupportException|ConnectionException $e) {
|
||||
} catch (EmqxSupportException $e) {
|
||||
return back()->with('error', $e->getMessage());
|
||||
}
|
||||
|
||||
@ -41,7 +43,10 @@ public function index(Request $request)
|
||||
// }
|
||||
|
||||
|
||||
public function destroy($client_id)
|
||||
/**
|
||||
* @throws EmqxSupportException
|
||||
*/
|
||||
public function destroy($client_id): RedirectResponse
|
||||
{
|
||||
$emqx = new EmqxSupport();
|
||||
|
||||
|
@ -6,17 +6,18 @@
|
||||
use App\Models\Module;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
public function index()
|
||||
public function index(): View
|
||||
{
|
||||
$modules = Module::paginate(10);
|
||||
$modules = (new Module)->paginate(10);
|
||||
|
||||
return view('admin.index', compact('modules'));
|
||||
}
|
||||
|
||||
public function transactions(Request $request)
|
||||
public function transactions(Request $request): View
|
||||
{
|
||||
$transactions = new Transaction();
|
||||
|
||||
|
@ -54,11 +54,11 @@ public function store(Request $request): RedirectResponse
|
||||
|
||||
$module = new Module();
|
||||
|
||||
$module->id = $request->id;
|
||||
$module->name = $request->name;
|
||||
$module->id = $request->input('id');
|
||||
$module->name = $request->input('name');
|
||||
$module->api_token = $api_token;
|
||||
$module->url = $request->url;
|
||||
$module->status = $request->status;
|
||||
$module->url = $request->input('url');
|
||||
$module->status = $request->input('status');
|
||||
|
||||
$module->save();
|
||||
|
||||
@ -87,7 +87,7 @@ public function show(Module $module): View
|
||||
{
|
||||
$years = $module->calculate();
|
||||
|
||||
$hosts = Host::where('module_id', $module->id)->with('user')->latest()->paginate(50);
|
||||
$hosts = (new Host)->where('module_id', $module->id)->with('user')->latest()->paginate(50);
|
||||
|
||||
return view('admin.modules.show', compact('module', 'years', 'hosts'));
|
||||
}
|
||||
@ -154,20 +154,20 @@ public function destroy(Module $module): RedirectResponse
|
||||
return redirect()->route('admin.modules.index')->with('success', '模块已删除。');
|
||||
}
|
||||
|
||||
public function allows(Module $module)
|
||||
public function allows(Module $module): View
|
||||
{
|
||||
$allows = ModuleAllow::where('module_id', $module->id)->with('allowed_module')->paginate(50);
|
||||
$allows = (new ModuleAllow)->where('module_id', $module->id)->with('allowed_module')->paginate(50);
|
||||
|
||||
return view('admin.modules.allows', compact('module', 'allows'));
|
||||
}
|
||||
|
||||
public function allows_store(Request $request, Module $module)
|
||||
public function allows_store(Request $request, Module $module): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'allowed_module_id' => 'required|string|max:255|exists:modules,id',
|
||||
]);
|
||||
|
||||
ModuleAllow::where('module_id', $module->id)->where('allowed_module_id', $request->allow_module_id)->firstOrCreate([
|
||||
(new ModuleAllow)->where('module_id', $module->id)->where('allowed_module_id', $request->input('allow_module_id'))->firstOrCreate([
|
||||
'module_id' => $module->id,
|
||||
'allowed_module_id' => $request->get('allowed_module_id'),
|
||||
]);
|
||||
@ -178,7 +178,7 @@ public function allows_store(Request $request, Module $module)
|
||||
|
||||
// fast login
|
||||
|
||||
public function allows_destroy(Module $module, ModuleAllow $allow)
|
||||
public function allows_destroy(Module $module, ModuleAllow $allow): RedirectResponse
|
||||
{
|
||||
$allow->delete();
|
||||
|
||||
|
@ -17,9 +17,11 @@ class NotificationController extends Controller
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function create(Request $request)
|
||||
public function create(Request $request): View
|
||||
{
|
||||
$modules = Module::all();
|
||||
|
||||
@ -35,7 +37,7 @@ public function query(Request|array $request): User|CachedBuilder
|
||||
}
|
||||
|
||||
if (!empty($request['user_id'])) {
|
||||
$users = User::where('id', $request['user_id']);
|
||||
$users = (new User)->where('id', $request['user_id']);
|
||||
} else {
|
||||
$users = User::query();
|
||||
|
||||
@ -70,7 +72,7 @@ public function query(Request|array $request): User|CachedBuilder
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'title' => 'required',
|
||||
|
@ -19,7 +19,7 @@ class ReplyController extends Controller
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function store(Request $request, WorkOrder $work_order)
|
||||
public function store(Request $request, WorkOrder $work_order): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'content' => 'required|string',
|
||||
@ -29,7 +29,7 @@ public function store(Request $request, WorkOrder $work_order)
|
||||
return back()->with('error', '工单还未就绪。');
|
||||
}
|
||||
|
||||
Reply::create([
|
||||
(new Reply)->create([
|
||||
'content' => $request->input('content'),
|
||||
'work_order_id' => $work_order->id,
|
||||
'name' => auth('admin')->user()->name
|
||||
@ -46,7 +46,7 @@ public function store(Request $request, WorkOrder $work_order)
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function edit(WorkOrder $work_order, Reply $reply)
|
||||
public function edit(WorkOrder $work_order, Reply $reply): View
|
||||
{
|
||||
return view('admin.work-orders.reply_edit', compact('reply', 'work_order'));
|
||||
}
|
||||
@ -60,7 +60,7 @@ public function edit(WorkOrder $work_order, Reply $reply)
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, WorkOrder $work_order, Reply $reply)
|
||||
public function update(Request $request, WorkOrder $work_order, Reply $reply): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'content' => 'required|string',
|
||||
@ -81,7 +81,7 @@ public function update(Request $request, WorkOrder $work_order, Reply $reply)
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function destroy(WorkOrder $work_order, Reply $reply)
|
||||
public function destroy(WorkOrder $work_order, Reply $reply): RedirectResponse
|
||||
{
|
||||
$reply->safeDelete();
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Exceptions\ChargeException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Balance;
|
||||
use App\Models\Host;
|
||||
@ -68,13 +67,13 @@ public function show(User $user): RedirectResponse
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function edit(User $user)
|
||||
public function edit(User $user): View
|
||||
{
|
||||
//
|
||||
|
||||
$hosts = Host::where('user_id', $user->id)->latest()->paginate(50, ['*'], 'hosts_page');
|
||||
$workOrders = WorkOrder::where('user_id', $user->id)->latest()->paginate(50, ['*'], 'workOrders_page');
|
||||
$balances = Balance::where('user_id', $user->id)->latest()->paginate(50, ['*'], 'balances_page');
|
||||
$hosts = (new Host)->where('user_id', $user->id)->latest()->paginate(50, ['*'], 'hosts_page');
|
||||
$workOrders = (new WorkOrder)->where('user_id', $user->id)->latest()->paginate(50, ['*'], 'workOrders_page');
|
||||
$balances = (new Balance)->where('user_id', $user->id)->latest()->paginate(50, ['*'], 'balances_page');
|
||||
$groups = UserGroup::all();
|
||||
|
||||
return view('admin.users.edit', compact('user', 'hosts', 'workOrders', 'balances', 'groups'));
|
||||
@ -88,7 +87,7 @@ public function edit(User $user)
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, User $user)
|
||||
public function update(Request $request, User $user): RedirectResponse
|
||||
{
|
||||
//
|
||||
$request->validate([
|
||||
@ -97,11 +96,11 @@ public function update(Request $request, User $user)
|
||||
|
||||
$transaction = new Transaction();
|
||||
|
||||
if ($request->is_banned) {
|
||||
if ($request->input('is_banned')) {
|
||||
$user->banned_at = Carbon::now();
|
||||
|
||||
if ($request->filled('banned_reason')) {
|
||||
$user->banned_reason = $request->banned_reason;
|
||||
$user->banned_reason = $request->input('banned_reason');
|
||||
}
|
||||
} else {
|
||||
if ($user->banned_at) {
|
||||
@ -119,11 +118,7 @@ public function update(Request $request, User $user)
|
||||
} else if ($one_time_action == 'stop_all_hosts') {
|
||||
$user->hosts()->update(['status' => 'stopped', 'suspended_at' => null]);
|
||||
} else if ($one_time_action == 'add_balance') {
|
||||
try {
|
||||
$transaction->addAmount($user->id, 'console', $request->balance ?? 0, '管理员添加。', true);
|
||||
} catch (ChargeException $e) {
|
||||
return back()->with('error', $e->getMessage());
|
||||
}
|
||||
} else if ($one_time_action == 'reduce_balance') {
|
||||
$transaction->reduceAmount($user->id, $request->balance ?? 0, '管理员扣除。');
|
||||
}
|
||||
|
@ -16,9 +16,9 @@ class UserGroupController extends Controller
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function index()
|
||||
public function index(): View
|
||||
{
|
||||
$user_groups = UserGroup::paginate(10);
|
||||
$user_groups = (new UserGroup)->paginate(10);
|
||||
|
||||
return view('admin.user-groups.index', compact('user_groups'));
|
||||
}
|
||||
@ -30,11 +30,11 @@ public function index()
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate($this->rules());
|
||||
|
||||
$user_group = UserGroup::create($request->all());
|
||||
$user_group = (new UserGroup)->create($request->all());
|
||||
|
||||
return redirect()->route('admin.user-groups.edit', $user_group)->with('success', '用户组新建成功。');
|
||||
}
|
||||
@ -70,7 +70,7 @@ public function create(): View
|
||||
*/
|
||||
public function show(UserGroup $user_group): View
|
||||
{
|
||||
$users = User::where('user_group_id', $user_group->id)->paginate(100);
|
||||
$users = (new User)->where('user_group_id', $user_group->id)->paginate(100);
|
||||
|
||||
return view('admin.user-groups.show', compact('user_group', 'users'));
|
||||
}
|
||||
@ -114,7 +114,7 @@ public function update(Request $request, UserGroup $user_group): RedirectRespons
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function destroy(UserGroup $user_group)
|
||||
public function destroy(UserGroup $user_group): RedirectResponse
|
||||
{
|
||||
$user_group->delete();
|
||||
|
||||
|
@ -37,7 +37,7 @@ public function show(WorkOrder $workOrder): View
|
||||
{
|
||||
$workOrder->load(['user', 'module']);
|
||||
|
||||
$replies = Reply::where('work_order_id', $workOrder->id)->latest()->paginate(100);
|
||||
$replies = (new Reply)->where('work_order_id', $workOrder->id)->latest()->paginate(100);
|
||||
|
||||
return view('admin.work-orders.show', compact('workOrder', 'replies'));
|
||||
}
|
||||
|
@ -14,9 +14,9 @@ class BalanceController extends Controller
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function index()
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$balances = Balance::thisUser()->paginate(100);
|
||||
$balances = (new Balance)->thisUser()->paginate(100);
|
||||
|
||||
return $this->success($balances);
|
||||
}
|
||||
@ -28,14 +28,14 @@ public function index()
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$this->validate($request, [
|
||||
'amount' => 'required|integer|min:0.1|max:10000',
|
||||
'payment' => 'required|in:wechat,alipay',
|
||||
]);
|
||||
|
||||
$balance = Balance::create([
|
||||
$balance = (new Balance)->create([
|
||||
'user_id' => auth('sanctum')->id(),
|
||||
'amount' => $request->input('amount'),
|
||||
'payment' => $request->input('payment'),
|
||||
@ -54,7 +54,7 @@ public function store(Request $request)
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function show(Balance $balance)
|
||||
public function show(Balance $balance): JsonResponse
|
||||
{
|
||||
if ($balance->canPay()) {
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
use App\Http\Controllers\Controller;
|
||||
use Closure;
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use function config;
|
||||
@ -21,7 +22,7 @@ public function __construct()
|
||||
$this->http = Http::baseUrl($this->baseUrl . '/api')->throw();
|
||||
}
|
||||
|
||||
public function announcements()
|
||||
public function announcements(): JsonResponse
|
||||
{
|
||||
$resp = $this->cache(function () {
|
||||
return $this->get('discussions?filter[tag]=announcements&page[offset]=0&sort=-createdAt');
|
||||
@ -45,14 +46,14 @@ public function get($url)
|
||||
return $this->http->get($url)->json()['data'];
|
||||
}
|
||||
|
||||
public function resp($data)
|
||||
public function resp($data): JsonResponse
|
||||
{
|
||||
$data['base_url'] = $this->baseUrl;
|
||||
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
public function pinned()
|
||||
public function pinned(): JsonResponse
|
||||
{
|
||||
$resp = $this->cache(function () {
|
||||
return $this->get('discussions?filter[tag]=pinned&page[offset]=0&sort=-createdAt');
|
||||
|
@ -16,7 +16,7 @@ class HostController extends Controller
|
||||
{
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$hosts = Host::where('user_id', auth()->id())->with('module', function ($query) {
|
||||
$hosts = (new Host)->where('user_id', auth()->id())->with('module', function ($query) {
|
||||
$query->select(['id', 'name']);
|
||||
})->get();
|
||||
|
||||
@ -37,7 +37,7 @@ public function update(HostRequest $request, Host $host): JsonResponse
|
||||
}
|
||||
|
||||
$host->update([
|
||||
'status' => $request->status,
|
||||
'status' => $request->input('status'),
|
||||
]);
|
||||
|
||||
return $this->updated($host);
|
||||
|
@ -20,7 +20,7 @@ public function index(Request $request): JsonResponse
|
||||
|
||||
public function birthdays(): JsonResponse
|
||||
{
|
||||
$users = User::birthday()->simplePaginate(20);
|
||||
$users = (new User)->birthday()->simplePaginate(20);
|
||||
|
||||
return $this->success($users);
|
||||
}
|
||||
|
@ -14,11 +14,13 @@ class ReplyController extends Controller
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param WorkOrder $workOrder
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function index(WorkOrder $workOrder)
|
||||
public function index(WorkOrder $workOrder): JsonResponse
|
||||
{
|
||||
$replies = Reply::workOrderId($workOrder->id)->with('module')->withUser()->simplePaginate(20);
|
||||
$replies = (new Reply)->workOrderId($workOrder->id)->with('module')->withUser()->simplePaginate(20);
|
||||
|
||||
return $this->success($replies);
|
||||
}
|
||||
@ -31,7 +33,7 @@ public function index(WorkOrder $workOrder)
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function store(Request $request, WorkOrder $workOrder)
|
||||
public function store(Request $request, WorkOrder $workOrder): JsonResponse
|
||||
{
|
||||
$this->validate($request, [
|
||||
'content' => 'string|required|min:1|max:1000',
|
||||
@ -61,7 +63,7 @@ public function store(Request $request, WorkOrder $workOrder)
|
||||
$create['name'] = $request->input('name');
|
||||
}
|
||||
|
||||
$reply = Reply::create($create);
|
||||
$reply = (new Reply)->create($create);
|
||||
|
||||
return $this->success($reply);
|
||||
}
|
||||
|
@ -4,12 +4,13 @@
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\Cluster;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class ServerController extends Controller
|
||||
{
|
||||
public function module_reports(Request $request)
|
||||
public function module_reports(Request $request): JsonResponse
|
||||
{
|
||||
$servers = Cache::get('servers', []);
|
||||
|
||||
@ -23,7 +24,7 @@ public function module_reports(Request $request)
|
||||
return $this->success($servers);
|
||||
}
|
||||
|
||||
public function nodes()
|
||||
public function nodes(): JsonResponse
|
||||
{
|
||||
$nodes = Cluster::nodes(true);
|
||||
|
||||
|
@ -4,17 +4,18 @@
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Task;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TaskController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$tasks = Task::where('user_id', $request->user()->id)->with('host')->latest()->get();
|
||||
$tasks = (new Task)->where('user_id', $request->user()->id)->with('host')->latest()->get();
|
||||
return $this->success($tasks);
|
||||
}
|
||||
|
||||
public function show(Task $task)
|
||||
public function show(Task $task): JsonResponse
|
||||
{
|
||||
if ($task->user_id !== auth('sanctum')->id()) {
|
||||
return $this->error('无权查看');
|
||||
|
@ -3,11 +3,12 @@
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$user = $request->user()->load('user_group');
|
||||
|
||||
|
@ -20,7 +20,7 @@ public function index(WorkOrder $workOrder): JsonResponse
|
||||
/**
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function store(Request $request)
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$this->validate($request, [
|
||||
'title' => 'required|max:255',
|
||||
@ -39,7 +39,7 @@ public function store(Request $request)
|
||||
]);
|
||||
}
|
||||
|
||||
$workOrder = WorkOrder::create([
|
||||
$workOrder = (new WorkOrder)->create([
|
||||
'title' => $request->input('title'),
|
||||
'content' => $request->input('content'),
|
||||
'module_id' => $request->input('module_id'),
|
||||
@ -60,7 +60,7 @@ public function show(WorkOrder $workOrder): JsonResponse
|
||||
/**
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function update(Request $request, WorkOrder $workOrder)
|
||||
public function update(Request $request, WorkOrder $workOrder): JsonResponse
|
||||
{
|
||||
$this->validate($request, [
|
||||
'status' => 'nullable|sometimes|string|in:closed',
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Module;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class ModuleController extends Controller
|
||||
{
|
||||
@ -16,7 +17,7 @@ class ModuleController extends Controller
|
||||
// }
|
||||
|
||||
|
||||
public function show(Module $module)
|
||||
public function show(Module $module): JsonResponse
|
||||
{
|
||||
|
||||
|
||||
|
@ -6,12 +6,13 @@
|
||||
use App\Models\Module;
|
||||
use App\Models\ModuleAllow;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class MqttAuthController extends Controller
|
||||
{
|
||||
//
|
||||
|
||||
public function authentication(Request $request)
|
||||
public function authentication(Request $request): Response
|
||||
{
|
||||
//
|
||||
$client_id = $request->input('client_id');
|
||||
@ -26,7 +27,7 @@ public function authentication(Request $request)
|
||||
$device_id = $usernames[1] ?? null;
|
||||
|
||||
|
||||
$module = Module::where('id', $module_id)->first();
|
||||
$module = (new Module)->where('id', $module_id)->first();
|
||||
|
||||
if (!$module) {
|
||||
return $this->ignore();
|
||||
@ -63,14 +64,14 @@ public function authentication(Request $request)
|
||||
}
|
||||
}
|
||||
|
||||
private function ignore()
|
||||
private function ignore(): Response
|
||||
{
|
||||
return response([
|
||||
'result' => 'ignore',
|
||||
], 200);
|
||||
}
|
||||
|
||||
private function allow()
|
||||
private function allow(): Response
|
||||
{
|
||||
return response([
|
||||
'result' => 'allow',
|
||||
@ -78,14 +79,14 @@ private function allow()
|
||||
], 200);
|
||||
}
|
||||
|
||||
private function deny()
|
||||
private function deny(): Response
|
||||
{
|
||||
return response([
|
||||
'result' => 'deny',
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function authorization(Request $request)
|
||||
public function authorization(Request $request): Response
|
||||
{
|
||||
// 禁止订阅保留的
|
||||
if ($request->input('topic') == '$SYS/#') {
|
||||
@ -109,7 +110,7 @@ public function authorization(Request $request)
|
||||
$module_id = $usernames[0] ?? null;
|
||||
$device_id = $usernames[1] ?? null;
|
||||
|
||||
$module = Module::where('id', $module_id)->first();
|
||||
$module = (new Module)->where('id', $module_id)->first();
|
||||
|
||||
if (!$module) {
|
||||
// 不属于我们管理,跳过。
|
||||
@ -122,7 +123,7 @@ public function authorization(Request $request)
|
||||
if ($action == 'publish') {
|
||||
if ($topics[0] !== $module_id) {
|
||||
// 但是,在拒绝之前,应该检查一下,是否有允许的模块
|
||||
$allow = ModuleAllow::where('module_id', $topics[0])->where('allowed_module_id', $module_id)->exists();
|
||||
$allow = (new ModuleAllow)->where('module_id', $topics[0])->where('allowed_module_id', $module_id)->exists();
|
||||
|
||||
if (!$allow) {
|
||||
return $this->deny();
|
||||
|
@ -6,11 +6,12 @@
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Host;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class BroadcastController extends Controller
|
||||
{
|
||||
public function broadcast_to_user(Request $request, User $user)
|
||||
public function broadcast_to_user(Request $request, User $user): JsonResponse
|
||||
{
|
||||
$this->validate($request, $this->rules());
|
||||
|
||||
@ -22,14 +23,14 @@ public function broadcast_to_user(Request $request, User $user)
|
||||
return $this->created($request->input('message'));
|
||||
}
|
||||
|
||||
private function rules()
|
||||
private function rules(): array
|
||||
{
|
||||
return [
|
||||
'message' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
public function broadcast_to_host(Request $request, Host $host)
|
||||
public function broadcast_to_host(Request $request, Host $host): JsonResponse
|
||||
{
|
||||
$this->validate($request, $this->rules());
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Host;
|
||||
// use App\Models\User;
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@ -22,7 +23,7 @@ class HostController extends Controller
|
||||
*/
|
||||
public function index(Request $request): Paginator
|
||||
{
|
||||
return Host::where('module_id', $request->user('module')->id)->simplePaginate(100);
|
||||
return (new Host)->where('module_id', $request->user('module')->id)->simplePaginate(100);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,9 +43,9 @@ public function store(Request $request): Response|JsonResponse
|
||||
'user_id' => 'required|integer|exists:users,id',
|
||||
]);
|
||||
|
||||
$user = User::findOrFail($request->user_id);
|
||||
$user = (new User)->findOrFail($request->input('user_id'));
|
||||
|
||||
if ($request->price > 0) {
|
||||
if ($request->input('price') > 0) {
|
||||
if ($user->balance < 1) {
|
||||
return $this->error('此用户余额不足,无法开设计费项目。');
|
||||
}
|
||||
@ -55,14 +56,14 @@ public function store(Request $request): Response|JsonResponse
|
||||
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'status' => $request->status,
|
||||
'price' => $request->price,
|
||||
'managed_price' => $request->managed_price,
|
||||
'status' => $request->input('status'),
|
||||
'price' => $request->input('price'),
|
||||
'managed_price' => $request->input('managed_price'),
|
||||
'user_id' => $user->id,
|
||||
'module_id' => auth('module')->id()
|
||||
];
|
||||
|
||||
$host = Host::create($data);
|
||||
$host = (new Host)->create($data);
|
||||
|
||||
$host['host_id'] = $host->id;
|
||||
|
||||
@ -105,7 +106,7 @@ public function update(Request $request, Host $host): JsonResponse
|
||||
'cost_once' => 'sometimes|numeric|nullable',
|
||||
]);
|
||||
|
||||
// if has cost_once
|
||||
// if it has cost_once
|
||||
if ($request->has('cost_once')) {
|
||||
$host->cost($request->cost_once ?? 0, false);
|
||||
|
||||
@ -130,7 +131,7 @@ public function destroy($host): JsonResponse
|
||||
{
|
||||
// if host not instance of HostJob
|
||||
if (!$host instanceof Host) {
|
||||
$host = Host::findOrFail($host);
|
||||
$host = (new Host)->findOrFail($host);
|
||||
}
|
||||
|
||||
$host?->delete();
|
||||
|
@ -11,14 +11,14 @@
|
||||
|
||||
class ModuleController extends Controller
|
||||
{
|
||||
public function index()
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$module = auth('module')->user()->calculate();
|
||||
|
||||
return $this->success($module);
|
||||
}
|
||||
|
||||
public function call(Request $request, Module $module)
|
||||
public function call(Request $request, Module $module): Response|JsonResponse
|
||||
{
|
||||
$path = $this->fixPath($request, $module, 'api');
|
||||
|
||||
@ -35,7 +35,7 @@ public function call(Request $request, Module $module)
|
||||
|
||||
private function fixPath(Request $request, Module $module, $prefix): string
|
||||
{
|
||||
$path = substr($request->path(), strlen("/{$prefix}/modules/{$module->id}"));
|
||||
$path = substr($request->path(), strlen("/$prefix/modules/$module->id"));
|
||||
|
||||
return preg_replace('/[^a-zA-Z0-9\/]/', '', $path);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ class ReplyController extends Controller
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$replies = Reply::workOrderId($request->route('work_order'))->simplePaginate(10);
|
||||
$replies = (new Reply)->workOrderId($request->route('work_order'))->simplePaginate(10);
|
||||
|
||||
return $this->success($replies);
|
||||
}
|
||||
@ -36,7 +36,7 @@ public function store(Request $request, WorkOrder $work_order): JsonResponse
|
||||
'name' => 'required|string|max:255',
|
||||
]);
|
||||
|
||||
$reply = Reply::create([
|
||||
$reply = (new Reply)->create([
|
||||
'content' => $request->input('content'),
|
||||
'work_order_id' => $work_order->id,
|
||||
'module_id' => $work_order->module_id,
|
||||
|
@ -21,7 +21,7 @@ class TaskController extends Controller
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$modules = Task::where('module_id', $request->user('module')->id)->simplePaginate(100);
|
||||
$modules = (new Task)->where('module_id', $request->user('module')->id)->simplePaginate(100);
|
||||
|
||||
return $this->success($modules);
|
||||
}
|
||||
@ -43,7 +43,7 @@ public function store(Request $request): JsonResponse
|
||||
'status' => 'required|in:pending,processing,need_operation,done,success,failed,error,canceled',
|
||||
]);
|
||||
|
||||
$task = Task::create($request->all());
|
||||
$task = (new Task)->create($request->all());
|
||||
|
||||
return $this->success($task);
|
||||
}
|
||||
|
@ -7,11 +7,12 @@
|
||||
use App\Models\Host;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$this->validate($request, [
|
||||
'user_id' => 'sometimes|integer',
|
||||
@ -40,19 +41,19 @@ public function index(Request $request)
|
||||
return $this->success($users);
|
||||
}
|
||||
|
||||
public function show(User $user)
|
||||
public function show(User $user): JsonResponse
|
||||
{
|
||||
return $this->success($user);
|
||||
}
|
||||
|
||||
public function hosts(User $user)
|
||||
public function hosts(User $user): JsonResponse
|
||||
{
|
||||
$hosts = (new Host())->getUserHosts($user->id);
|
||||
|
||||
return $this->success($hosts);
|
||||
}
|
||||
|
||||
public function reduce(Request $request, User $user)
|
||||
public function reduce(Request $request, User $user): JsonResponse
|
||||
{
|
||||
$this->validate($request, [
|
||||
'amount' => 'required|numeric|min:0.01|max:10000',
|
||||
@ -63,7 +64,7 @@ public function reduce(Request $request, User $user)
|
||||
$transaction = new Transaction();
|
||||
|
||||
try {
|
||||
$transaction->reduceAmountModuleFail($user->id, $module->id, $request->amount, $request->description);
|
||||
$transaction->reduceAmountModuleFail($user->id, $module->id, $request->input('amount'), $request->input('description'));
|
||||
} catch (BalanceNotEnoughException) {
|
||||
return $this->error('余额不足');
|
||||
}
|
||||
|
@ -8,9 +8,12 @@
|
||||
use App\Models\User;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\View\View;
|
||||
use function back;
|
||||
use function config;
|
||||
use function redirect;
|
||||
@ -21,12 +24,12 @@ class AuthController extends Controller
|
||||
{
|
||||
// use ApiResponse;
|
||||
|
||||
public function index(Request $request)
|
||||
public function index(Request $request): View|RedirectResponse
|
||||
{
|
||||
// if logged in
|
||||
if ($request->callback) {
|
||||
if ($request->input('callback')) {
|
||||
|
||||
session(['callback' => $request->callback]);
|
||||
session(['callback' => $request->input('callback')]);
|
||||
|
||||
|
||||
if (Auth::check()) {
|
||||
@ -39,7 +42,7 @@ public function index(Request $request)
|
||||
return view('index');
|
||||
}
|
||||
|
||||
public function confirm_redirect(Request $request)
|
||||
public function confirm_redirect(Request $request): View
|
||||
{
|
||||
// create token
|
||||
|
||||
@ -49,7 +52,7 @@ public function confirm_redirect(Request $request)
|
||||
return view('confirm_redirect', compact('callback'));
|
||||
}
|
||||
|
||||
public function redirect(Request $request)
|
||||
public function redirect(Request $request): RedirectResponse
|
||||
{
|
||||
$request->session()->put('state', $state = Str::random(40));
|
||||
|
||||
@ -67,11 +70,11 @@ public function redirect(Request $request)
|
||||
return redirect()->to(config('oauth.oauth_auth_url') . '?' . $query);
|
||||
}
|
||||
|
||||
public function callback(Request $request)
|
||||
public function callback(Request $request): RedirectResponse
|
||||
{
|
||||
$state = $request->session()->pull('state');
|
||||
|
||||
if (!strlen($state) > 0 && $state === $request->state) {
|
||||
if (!strlen($state) > 0 && $state === $request->input('state')) {
|
||||
return redirect(route('login'));
|
||||
}
|
||||
|
||||
@ -84,28 +87,32 @@ public function callback(Request $request)
|
||||
'client_id' => config('oauth.client_id'),
|
||||
'client_secret' => config('oauth.client_secret'),
|
||||
'redirect_uri' => config('oauth.callback_uri'),
|
||||
'code' => $request->code,
|
||||
'code' => $request->input('code'),
|
||||
],
|
||||
])->getBody();
|
||||
} catch (ClientException) {
|
||||
} catch (ClientException|GuzzleException) {
|
||||
return redirect(route('login'));
|
||||
}
|
||||
|
||||
$authorize = json_decode($authorize);
|
||||
|
||||
try {
|
||||
$oauth_user = $http->get(config('oauth.oauth_user_url'), [
|
||||
'headers' => [
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $authorize->access_token,
|
||||
],
|
||||
])->getBody();
|
||||
} catch (GuzzleException) {
|
||||
return redirect(route('login'));
|
||||
}
|
||||
$oauth_user = json_decode($oauth_user);
|
||||
|
||||
if (is_null($oauth_user->verified_at)) {
|
||||
return redirect()->route('not_verified');
|
||||
}
|
||||
|
||||
$user_sql = User::where('email', $oauth_user->email);
|
||||
$user_sql = (new User)->where('email', $oauth_user->email);
|
||||
$user = $user_sql->first();
|
||||
|
||||
if (is_null($user)) {
|
||||
@ -125,7 +132,7 @@ public function callback(Request $request)
|
||||
$request->session()->put('auth.password_confirmed_at', time());
|
||||
} else {
|
||||
if ($user->name != $oauth_user->name) {
|
||||
User::where('email', $oauth_user->email)->update([
|
||||
(new User)->where('email', $oauth_user->email)->update([
|
||||
'name' => $oauth_user->name
|
||||
]);
|
||||
}
|
||||
@ -137,25 +144,25 @@ public function callback(Request $request)
|
||||
return redirect()->route('index', ['callback' => session('callback')]);
|
||||
}
|
||||
|
||||
public function newToken(Request $request)
|
||||
public function newToken(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'token_name' => 'required|string|max:255',
|
||||
]);
|
||||
|
||||
$token = $request->user()->createToken($request->token_name);
|
||||
$token = $request->user()->createToken($request->input('token_name'));
|
||||
|
||||
return back()->with('token', $token->plainTextToken);
|
||||
}
|
||||
|
||||
public function deleteAll(Request $request)
|
||||
public function deleteAll(Request $request): RedirectResponse
|
||||
{
|
||||
$request->user()->tokens()->delete();
|
||||
|
||||
return back()->with('success', '所有 Token 删除成功。');
|
||||
}
|
||||
|
||||
public function logout()
|
||||
public function logout(): RedirectResponse
|
||||
{
|
||||
Auth::guard('web')->logout();
|
||||
|
||||
|
@ -2,13 +2,13 @@
|
||||
|
||||
namespace App\Http\Controllers\Web;
|
||||
|
||||
use App\Exceptions\ChargeException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Balance;
|
||||
use App\Models\Module;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@ -22,19 +22,19 @@ public function index(Request $request): View
|
||||
{
|
||||
$balance = $request->user()->balance;
|
||||
|
||||
$balances = Balance::thisUser()->latest()->paginate(100);
|
||||
$balances = (new Balance)->thisUser()->latest()->paginate(100);
|
||||
|
||||
return view('balances.index', compact('balance', 'balances'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$this->validate($request, [
|
||||
'amount' => 'required|integer|min:0.1|max:10000',
|
||||
'payment' => 'required|in:wechat,alipay',
|
||||
]);
|
||||
|
||||
$balance = Balance::create([
|
||||
$balance = (new Balance)->create([
|
||||
'user_id' => auth('web')->id(),
|
||||
'amount' => $request->input('amount'),
|
||||
'payment' => $request->input('payment'),
|
||||
@ -46,7 +46,7 @@ public function store(Request $request)
|
||||
/**
|
||||
* 显示充值页面和状态(ajax)
|
||||
*/
|
||||
public function show(Request $request, Balance $balance)
|
||||
public function show(Request $request, Balance $balance): RedirectResponse|JsonResponse|View
|
||||
{
|
||||
|
||||
if ($balance->isPaid()) {
|
||||
@ -147,7 +147,7 @@ function xunhu_wechat(
|
||||
private
|
||||
function xunhu_hash(
|
||||
array $arr
|
||||
) {
|
||||
): string {
|
||||
ksort($arr);
|
||||
|
||||
$pre = [];
|
||||
@ -193,7 +193,7 @@ function notify(
|
||||
}
|
||||
|
||||
// 检测订单是否存在
|
||||
$balance = Balance::where('order_id', $out_trade_no)->with('user')->first();
|
||||
$balance = (new Balance)->where('order_id', $out_trade_no)->with('user')->first();
|
||||
if (!$balance) {
|
||||
abort(404, '找不到订单。');
|
||||
}
|
||||
@ -228,16 +228,11 @@ function notify(
|
||||
}
|
||||
|
||||
if ($is_paid) {
|
||||
try {
|
||||
(new Transaction)->addAmount($balance->user_id, 'alipay', $balance->amount);
|
||||
|
||||
$balance->update([
|
||||
'paid_at' => now()
|
||||
]);
|
||||
|
||||
} catch (ChargeException $e) {
|
||||
abort(500, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -263,7 +258,7 @@ function transactions(
|
||||
|
||||
$modules = Module::all();
|
||||
|
||||
$transactions = Transaction::where('user_id', auth()->id());
|
||||
$transactions = (new Transaction)->where('user_id', auth()->id());
|
||||
|
||||
if ($request->has('type')) {
|
||||
$transactions = $transactions->where('type', $request->type);
|
||||
|
@ -5,13 +5,15 @@
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class TransferController extends Controller
|
||||
{
|
||||
//
|
||||
|
||||
public function index(Request $request)
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$user = $request->user();
|
||||
$balance = $user->balance;
|
||||
@ -19,33 +21,31 @@ public function index(Request $request)
|
||||
return view('transfer.search', compact('balance'));
|
||||
}
|
||||
|
||||
public function transfer(Request $request)
|
||||
public function transfer(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'amount' => 'numeric|min:1|max:100',
|
||||
'description' => 'nullable|string|max:100',
|
||||
]);
|
||||
|
||||
$to = User::where('email', $request->to)->first();
|
||||
$to = (new User)->where('email', $request->input('to'))->first();
|
||||
if (!$to) {
|
||||
return back()->withErrors(['to' => '找不到用户。']);
|
||||
}
|
||||
|
||||
$user = $request->user();
|
||||
if ($request->to == $user->email) {
|
||||
if ($request->input('to') == $user->email) {
|
||||
return back()->withErrors(['to' => '不能转给自己。']);
|
||||
}
|
||||
|
||||
$transaction = new Transaction();
|
||||
|
||||
if ($user->balance < $request->amount) {
|
||||
if ($user->balance < $request->input('amount')) {
|
||||
return back()->withErrors(['amount' => '您的余额不足。']);
|
||||
} else {
|
||||
$transaction->transfer($user, $to, $request->amount, $request->description);
|
||||
$transaction->transfer($user, $to, $request->input('amount'), $request->input('description'));
|
||||
}
|
||||
|
||||
return back()->with('success', '转账成功,已达对方账户。');
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class TrustHosts extends Middleware
|
||||
*
|
||||
* @return array<int, string|null>
|
||||
*/
|
||||
public function hosts()
|
||||
public function hosts(): array
|
||||
{
|
||||
return [
|
||||
$this->allSubdomainsOfApplicationUrl(),
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Http\Requests\Remote\Server;
|
||||
|
||||
use App\Models\Server\Status;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StatusRequest extends FormRequest
|
||||
|
@ -23,7 +23,7 @@ public function authorize(): bool
|
||||
$work_order_id = $work_order;
|
||||
}
|
||||
|
||||
return WorkOrder::where('id', $work_order_id)->where('module_id', auth('module')->id())->exists();
|
||||
return (new WorkOrder)->where('id', $work_order_id)->where('module_id', auth('module')->id())->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,7 +17,7 @@ public function authorize(): bool
|
||||
$host = $this->route('host');
|
||||
|
||||
if (!($host instanceof Host)) {
|
||||
$host = Host::where('id', $host)->first();
|
||||
$host = (new Host)->where('id', $host)->first();
|
||||
}
|
||||
|
||||
if ($host->user_id ?? 0 == $this->user()->id) {
|
||||
@ -33,7 +33,7 @@ public function authorize(): bool
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
|
@ -24,6 +24,6 @@ public function __construct()
|
||||
public function handle(): void
|
||||
{
|
||||
// close work order after 1 day
|
||||
WorkOrder::where('updated_at', '<=', now()->subDay())->update(['status' => 'closed']);
|
||||
(new WorkOrder)->where('updated_at', '<=', now()->subDay())->update(['status' => 'closed']);
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,12 @@
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Exceptions\ChargeException;
|
||||
use App\Models\Balance;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Yansongda\LaravelPay\Facades\Pay;
|
||||
use Yansongda\Pay\Exception\ContainerException;
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Exception\ServiceNotFoundException;
|
||||
|
||||
class CheckAndChargeBalanceJob extends Job
|
||||
{
|
||||
@ -27,7 +28,7 @@ public function __construct()
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
Balance::where('paid_at', null)->chunk(100, function ($balances) {
|
||||
(new Balance)->where('paid_at', null)->chunk(100, function ($balances) {
|
||||
foreach ($balances as $balance) {
|
||||
if (!$this->checkAndCharge($balance, true)) {
|
||||
if (now()->diffInDays($balance->created_at) > 1) {
|
||||
@ -37,14 +38,18 @@ public function handle(): void
|
||||
}
|
||||
});
|
||||
|
||||
Balance::where('paid_at', null)->where('created_at', '<', now()->subDays(2))->delete();
|
||||
(new Balance)->where('paid_at', null)->where('created_at', '<', now()->subDays(2))->delete();
|
||||
}
|
||||
|
||||
public function checkAndCharge(Balance $balance, $check = false): bool
|
||||
{
|
||||
|
||||
if ($check) {
|
||||
try {
|
||||
$alipay = Pay::alipay()->find(['out_trade_no' => $balance->order_id]);
|
||||
} catch (ContainerException|InvalidParamsException|ServiceNotFoundException) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($alipay->trade_status !== 'TRADE_SUCCESS') {
|
||||
return false;
|
||||
@ -55,16 +60,11 @@ public function checkAndCharge(Balance $balance, $check = false): bool
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
(new Transaction)->addAmount($balance->user_id, 'alipay', $balance->amount);
|
||||
|
||||
$balance->update([
|
||||
'paid_at' => now()
|
||||
]);
|
||||
} catch (ChargeException $e) {
|
||||
Log::error($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -32,6 +32,6 @@ public function __construct()
|
||||
public function handle(): void
|
||||
{
|
||||
// 删除所有大于 1 天的任务
|
||||
Task::where('created_at', '<', now()->subDay())->delete();
|
||||
(new Task)->where('created_at', '<', now()->subDay())->delete();
|
||||
}
|
||||
}
|
||||
|
@ -32,14 +32,14 @@ public function __construct()
|
||||
public function handle(): void
|
||||
{
|
||||
// 查找暂停时间超过 3 天的 host
|
||||
Host::where('status', 'suspended')->where('suspended_at', '<', now()->subDays(3))->chunk(100, function ($hosts) {
|
||||
(new Host)->where('status', 'suspended')->where('suspended_at', '<', now()->subDays(3))->chunk(100, function ($hosts) {
|
||||
foreach ($hosts as $host) {
|
||||
dispatch(new Module\HostJob($host, 'delete'));
|
||||
}
|
||||
});
|
||||
|
||||
// 查找部署时间超过3天以上的 host
|
||||
Host::where('status', 'pending')->where('created_at', '<', now()->subDays(3))->chunk(100, function ($hosts) {
|
||||
(new Host)->where('status', 'pending')->where('created_at', '<', now()->subDays(3))->chunk(100, function ($hosts) {
|
||||
foreach ($hosts as $host) {
|
||||
dispatch(new Module\HostJob($host, 'delete'));
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ class HostCostJob implements ShouldQueue
|
||||
{
|
||||
use InteractsWithQueue, Queueable, SerializesModels, Lock;
|
||||
|
||||
public $minute, $cache, $user;
|
||||
public int $minute;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
|
@ -43,7 +43,7 @@ public function handle(): void
|
||||
// }
|
||||
|
||||
//
|
||||
Module::whereNotNull('url')->chunk(100, function ($modules) {
|
||||
(new Module)->whereNotNull('url')->chunk(100, function ($modules) {
|
||||
$servers = [];
|
||||
|
||||
foreach ($modules as $module) {
|
||||
|
@ -33,6 +33,7 @@ public function __construct($host, $type = 'post')
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
* @noinspection PhpUndefinedVariableInspection
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ public function __construct()
|
||||
public function handle(): void
|
||||
{
|
||||
//
|
||||
Host::whereIn('status', ['pending', 'error'])->with(['module', 'user'])->chunk(100, function ($hosts) {
|
||||
(new Host)->whereIn('status', ['pending', 'error'])->with(['module', 'user'])->chunk(100, function ($hosts) {
|
||||
foreach ($hosts as $host) {
|
||||
$host->status = 'running';
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Jobs\Module;
|
||||
|
||||
use App\Models\WorkOrder\Reply;
|
||||
use App\Jobs\Module\WorkOrder\Reply;
|
||||
use App\Models\WorkOrder\WorkOrder;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
@ -34,7 +34,7 @@ public function __construct()
|
||||
public function handle(): void
|
||||
{
|
||||
//
|
||||
WorkOrder::whereIn('status', ['pending', 'error'])->with(['module', 'user', 'host', 'replies'])->chunk(100, function ($workOrders) {
|
||||
(new WorkOrder)->whereIn('status', ['pending', 'error'])->with(['module', 'user', 'host', 'replies'])->chunk(100, function ($workOrders) {
|
||||
foreach ($workOrders as $workOrder) {
|
||||
|
||||
if ($workOrder->host) {
|
||||
@ -69,9 +69,9 @@ public function handle(): void
|
||||
}
|
||||
});
|
||||
|
||||
Reply::where('is_pending', 1)->chunk(100, function ($replies) {
|
||||
(new \App\Models\WorkOrder\Reply)->where('is_pending', 1)->chunk(100, function ($replies) {
|
||||
foreach ($replies as $reply) {
|
||||
dispatch(new \App\Jobs\Module\WorkOrder\Reply($reply));
|
||||
dispatch(new Reply($reply));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -37,7 +37,7 @@ public function handle(): void
|
||||
|
||||
foreach ($temp_groups as $user_id => $temp_group) {
|
||||
if (now()->gt($temp_group['expired_at'])) {
|
||||
$user = User::find($user_id);
|
||||
$user = (new User)->find($user_id);
|
||||
$user->user_group_id = $temp_group['user_group_id'];
|
||||
$user->save();
|
||||
unset($temp_groups[$user_id]);
|
||||
|
@ -24,7 +24,7 @@ public function __construct()
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
Module::chunk(100, function ($modules) {
|
||||
(new Module)->chunk(100, function ($modules) {
|
||||
foreach ($modules as $module) {
|
||||
(new ModuleEarnings($module))
|
||||
->toGroup($module->calculate());
|
||||
|
@ -32,16 +32,16 @@ public function __construct()
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$birthday_group = UserGroup::find(config('settings.user_groups.birthday_group_id'));
|
||||
$birthday_group = (new UserGroup)->find(config('settings.user_groups.birthday_group_id'));
|
||||
|
||||
if (!$birthday_group) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 先撤销原来的
|
||||
User::where('user_group_id', $birthday_group->id)->update(['user_group_id' => null]);
|
||||
(new User)->where('user_group_id', $birthday_group->id)->update(['user_group_id' => null]);
|
||||
|
||||
User::birthday()->whereNull('user_group_id')->chunk(100, function ($users) use ($birthday_group) {
|
||||
(new User)->birthday()->whereNull('user_group_id')->chunk(100, function ($users) use ($birthday_group) {
|
||||
foreach ($users as $user) {
|
||||
$user->user_group_id = $birthday_group->id;
|
||||
$user->save();
|
||||
|
@ -2,11 +2,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Eloquent;
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class Admin extends Authenticatable
|
||||
{
|
||||
|
@ -2,12 +2,9 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Eloquent;
|
||||
use GeneaLabs\LaravelModelCaching\CachedBuilder;
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo as BelongsToAlias;
|
||||
use Illuminate\Support\Carbon;
|
||||
use function auth;
|
||||
|
||||
class Balance extends Model
|
||||
|
@ -4,13 +4,10 @@
|
||||
|
||||
use App\Events\Users;
|
||||
use App\Jobs\Module\HostJob;
|
||||
use App\Models\WorkOrder\WorkOrder;
|
||||
use GeneaLabs\LaravelModelCaching\CachedBuilder;
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo as BelongsToAlias;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class Host extends Model
|
||||
@ -104,6 +101,7 @@ protected static function boot()
|
||||
});
|
||||
}
|
||||
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
public function getUserHosts($user_id = null): array|Collection
|
||||
{
|
||||
return $this->where('user_id', $user_id)->with('module', function ($query) {
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Eloquent;
|
||||
use GeneaLabs\LaravelModelCaching\CachedBuilder;
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
use GuzzleHttp\Exception\ConnectException;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
@ -92,7 +90,7 @@ private function getResponse(Response $response): array
|
||||
|
||||
public function request($method, $path, $requests): array
|
||||
{
|
||||
return $this->baseRequest($method, "functions/{$path}", $requests);
|
||||
return $this->baseRequest($method, "functions/$path", $requests);
|
||||
}
|
||||
|
||||
public function baseRequest($method, $path, $requests): array
|
||||
@ -125,18 +123,19 @@ public function moduleRequest($method, $path, $requests): array
|
||||
|
||||
$requests['module_id'] = $module_id;
|
||||
|
||||
$response = $http->{$method}("exports/{$path}", $requests);
|
||||
$response = $http->{$method}("exports/$path", $requests);
|
||||
|
||||
return $this->getResponse($response);
|
||||
}
|
||||
|
||||
public function check($module_id = null): bool
|
||||
public function check(): bool
|
||||
{
|
||||
if ($module_id) {
|
||||
$module = Module::find($module_id);
|
||||
} else {
|
||||
$module = $this;
|
||||
}
|
||||
// $module_id = null
|
||||
// if ($module_id) {
|
||||
// $module = Module::find($module_id);
|
||||
// } else {
|
||||
// $module = $this;
|
||||
// }
|
||||
|
||||
$success = 0;
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
|
@ -2,11 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Eloquent;
|
||||
use GeneaLabs\LaravelModelCaching\CachedBuilder;
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Laravel\Sanctum\PersonalAccessToken as SanctumPersonalAccessToken;
|
||||
|
||||
class PersonalAccessToken extends SanctumPersonalAccessToken
|
||||
@ -24,7 +20,7 @@ class PersonalAccessToken extends SanctumPersonalAccessToken
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function save(array $options = [])
|
||||
public function save(array $options = []): bool
|
||||
{
|
||||
$changes = $this->getDirty();
|
||||
// Check for 2 changed values because one is always the updated_at column
|
||||
|
@ -4,11 +4,8 @@
|
||||
|
||||
use App\Events\Users;
|
||||
use App\Exceptions\CommonException;
|
||||
use Eloquent;
|
||||
use GeneaLabs\LaravelModelCaching\CachedBuilder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use function auth;
|
||||
@ -68,7 +65,7 @@ protected static function boot()
|
||||
broadcast(new Users($model->user_id, 'tasks.created', $model));
|
||||
});
|
||||
|
||||
// updateing
|
||||
// updating
|
||||
static::updating(function ($model) {
|
||||
if ($model->progress == 100) {
|
||||
$model->status = 'done';
|
||||
|
@ -2,12 +2,11 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Exceptions\ChargeException;
|
||||
use App\Exceptions\User\BalanceNotEnoughException;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Contracts\Cache\LockTimeoutException;
|
||||
use Illuminate\Database\Eloquent\HigherOrderBuilderProxy;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\HigherOrderCollectionProxy;
|
||||
use Jenssegers\Mongodb\Eloquent\Model;
|
||||
|
||||
class Transaction extends Model
|
||||
@ -68,7 +67,7 @@ public function reduceAmount($user_id, $amount = 0, $description = '扣除费用
|
||||
|
||||
$lock->block(5);
|
||||
|
||||
$user = User::findOrFail($user_id);
|
||||
$user = (new User)->findOrFail($user_id);
|
||||
|
||||
$user->balance -= $amount;
|
||||
$user->save();
|
||||
@ -100,7 +99,7 @@ public function addPayoutBalance($user_id, $amount, $description, $module_id = n
|
||||
|
||||
private function addLog($user_id, $data)
|
||||
{
|
||||
$user = User::find($user_id);
|
||||
$user = (new User)->find($user_id);
|
||||
|
||||
$current = [
|
||||
'balance' => (float)$user->balance,
|
||||
@ -113,9 +112,13 @@ private function addLog($user_id, $data)
|
||||
// add expired at
|
||||
$data['expired_at'] = now()->addSeconds(7);
|
||||
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
return $this->create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BalanceNotEnoughException
|
||||
*/
|
||||
public function reduceAmountModuleFail($user_id, $module_id, $amount = 0, $description = '扣除费用请求。')
|
||||
{
|
||||
|
||||
@ -124,7 +127,7 @@ public function reduceAmountModuleFail($user_id, $module_id, $amount = 0, $descr
|
||||
|
||||
$lock->block(5);
|
||||
|
||||
$user = User::findOrFail($user_id);
|
||||
$user = (new User)->findOrFail($user_id);
|
||||
|
||||
$user->balance -= $amount;
|
||||
|
||||
@ -151,7 +154,7 @@ public function reduceHostAmount($user_id, $host_id, $module_id, $amount = 0, $d
|
||||
|
||||
$lock->block(5);
|
||||
|
||||
$user = User::findOrFail($user_id);
|
||||
$user = (new User)->findOrFail($user_id);
|
||||
|
||||
$user->balance -= $amount;
|
||||
$user->save();
|
||||
@ -180,16 +183,22 @@ public function addHostPayoutBalance($user_id, $host_id, $module_id, $amount, $d
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ChargeException
|
||||
* @param $user_id
|
||||
* @param string $payment
|
||||
* @param int $amount
|
||||
* @param null $description
|
||||
* @param bool $add_charge_log
|
||||
*
|
||||
* @return float|HigherOrderBuilderProxy|HigherOrderCollectionProxy|int|mixed|string
|
||||
*/
|
||||
public function addAmount($user_id, $payment = 'console', $amount = 0, $description = null, $add_charge_log = false)
|
||||
public function addAmount($user_id, string $payment = 'console', int $amount = 0, $description = null, bool $add_charge_log = false): mixed
|
||||
{
|
||||
$lock = Cache::lock("user_balance_lock_" . $user_id, 10);
|
||||
try {
|
||||
|
||||
$lock->block(5);
|
||||
|
||||
$user = User::findOrFail($user_id);
|
||||
$user = (new User)->findOrFail($user_id);
|
||||
|
||||
$left_balance = $user->balance + $amount;
|
||||
|
||||
@ -207,13 +216,10 @@ public function addAmount($user_id, $payment = 'console', $amount = 0, $descript
|
||||
'paid_at' => Carbon::now(),
|
||||
];
|
||||
|
||||
Balance::create($data);
|
||||
(new Balance)->create($data);
|
||||
}
|
||||
|
||||
$this->addIncomeBalance($user_id, $payment, $amount, $description);
|
||||
} catch (LockTimeoutException $e) {
|
||||
Log::error($e);
|
||||
throw new ChargeException('充值失败,请稍后再试。');
|
||||
} finally {
|
||||
optional($lock)->release();
|
||||
}
|
||||
@ -253,11 +259,11 @@ public function transfer(User $user, User $to, float $amount, string|null $descr
|
||||
$description = '完成。';
|
||||
}
|
||||
|
||||
$description_new = "转账给 {$to->name}({$to->email}) {$amount} 元,{$description}";
|
||||
$description_new = "转账给 $to->name($to->email) $amount 元,$description";
|
||||
|
||||
$this->addPayoutBalance($user->id, $amount, $description_new);
|
||||
|
||||
$description_new = "收到来自 {$user->name}($user->email) 转来的 {$amount} 元, $description";
|
||||
$description_new = "收到来自 $user->name($user->email) 转来的 $amount 元, $description";
|
||||
|
||||
$this->addIncomeBalance($to->id, 'transfer', $amount, $description_new);
|
||||
} finally {
|
||||
|
@ -3,19 +3,12 @@
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Database\Factories\UserFactory;
|
||||
use Eloquent;
|
||||
use GeneaLabs\LaravelModelCaching\CachedBuilder;
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\DatabaseNotification;
|
||||
use Illuminate\Notifications\DatabaseNotificationCollection;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
@ -83,6 +76,7 @@ public function user_group(): BelongsTo
|
||||
|
||||
public function scopeBirthday()
|
||||
{
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
return $this->select(['id', 'name', 'birthday_at', 'email_md5', 'created_at'])->whereMonth('birthday_at', now()->month)
|
||||
->whereDay('birthday_at', now()->day);
|
||||
}
|
||||
|
@ -6,12 +6,9 @@
|
||||
use App\Exceptions\CommonException;
|
||||
use App\Models\Module;
|
||||
use App\Models\User;
|
||||
use Eloquent;
|
||||
use GeneaLabs\LaravelModelCaching\CachedBuilder;
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class Reply extends Model
|
||||
{
|
||||
|
@ -8,15 +8,11 @@
|
||||
use App\Models\Module;
|
||||
use App\Models\User;
|
||||
use App\Notifications\WorkOrder as WorkOrderNotification;
|
||||
use Eloquent;
|
||||
use GeneaLabs\LaravelModelCaching\CachedBuilder;
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class WorkOrder extends Model
|
||||
@ -39,6 +35,13 @@ class WorkOrder extends Model
|
||||
'notify' => 'boolean'
|
||||
];
|
||||
|
||||
public function routeNotificationForMail(WorkOrderNotification $work_order): array
|
||||
{
|
||||
$user = $work_order->user;
|
||||
|
||||
return [$user->email => $user->name];
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
@ -28,11 +28,10 @@ public function __construct(string $title, string $content)
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable): array
|
||||
public function via(): array
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
@ -40,11 +39,10 @@ public function via($notifiable): array
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return MailMessage
|
||||
*/
|
||||
public function toMail($notifiable): MailMessage
|
||||
public function toMail(): MailMessage
|
||||
{
|
||||
return (new MailMessage)->subject($this->title)->markdown('mail.common', [
|
||||
'title' => $this->title,
|
||||
@ -55,11 +53,10 @@ public function toMail($notifiable): MailMessage
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable): array
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
|
@ -31,7 +31,7 @@ public function __construct(Module $module)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function toGroup($notifiable)
|
||||
public function toGroup(mixed $notifiable): void
|
||||
{
|
||||
$module = $this->module;
|
||||
|
||||
@ -39,7 +39,7 @@ public function toGroup($notifiable)
|
||||
$wecom_key = $module->wecom_key ?? config('settings.wecom.robot_hook.billing');
|
||||
|
||||
|
||||
$text = "# {$module->name} 收益";
|
||||
$text = "# $module->name 收益";
|
||||
foreach ($notifiable as $year => $months) {
|
||||
// 排序 months 从小到大
|
||||
ksort($months);
|
||||
@ -55,7 +55,7 @@ public function toGroup($notifiable)
|
||||
==========
|
||||
{$year}年 {$month}月
|
||||
实收: {$total}元
|
||||
应得: {$total_should} 元
|
||||
应得: $total_should 元
|
||||
|
||||
EOF;
|
||||
}
|
||||
|
@ -25,11 +25,10 @@ public function __construct()
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable): array
|
||||
public function via(): array
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
@ -37,11 +36,10 @@ public function via($notifiable): array
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return MailMessage
|
||||
*/
|
||||
public function toMail(mixed $notifiable): MailMessage
|
||||
public function toMail(): MailMessage
|
||||
{
|
||||
$url = URL::format(config('settings.dashboard.base_url'), config('settings.dashboard.birthday_path'));
|
||||
|
||||
@ -95,11 +93,10 @@ public function toMail(mixed $notifiable): MailMessage
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
|
@ -11,51 +11,52 @@ class WorkOrder extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public WorkOrderModel $work_order;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct(WorkOrderModel $work_order)
|
||||
{
|
||||
//
|
||||
$this->work_order = $work_order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function via(mixed $notifiable): array
|
||||
public function via(): array
|
||||
{
|
||||
return [WeComChannel::class];
|
||||
return [WeComChannel::class, 'mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return MailMessage
|
||||
*/
|
||||
public function toMail(mixed $notifiable): MailMessage
|
||||
public function toMail(): MailMessage
|
||||
{
|
||||
return (new MailMessage)
|
||||
->line('The introduction to the notification.')
|
||||
->action('Notification Action', url('/'))
|
||||
->line('Thank you for using our application!');
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(mixed $notifiable): array
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
namespace App\Policies\WorkOrder;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\WorkOrder\Reply;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
||||
@ -14,11 +12,10 @@ class ReplyPolicy
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @param User $user
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function viewAny(User $user): Response|bool
|
||||
public function viewAny(): Response|bool
|
||||
{
|
||||
//
|
||||
|
||||
@ -28,11 +25,10 @@ public function viewAny(User $user): Response|bool
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @param User $user
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function create(User $user): Response|bool
|
||||
public function create(): Response|bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -40,12 +36,10 @@ public function create(User $user): Response|bool
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @param User $user
|
||||
* @param Reply $reply
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function update(User $user, Reply $reply): Response|bool
|
||||
public function update(): Response|bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -53,12 +47,10 @@ public function update(User $user, Reply $reply): Response|bool
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @param User $user
|
||||
* @param Reply $reply
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function delete(User $user, Reply $reply): Response|bool
|
||||
public function delete(): Response|bool
|
||||
{
|
||||
//
|
||||
return false;
|
||||
|
@ -24,7 +24,7 @@ class RouteServiceProvider extends ServiceProvider
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
public function boot(): void
|
||||
{
|
||||
$this->configureRateLimiting();
|
||||
|
||||
|
@ -26,6 +26,7 @@ public static function isSlave(): bool
|
||||
|
||||
public static function publish($event, $data = []): void
|
||||
{
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
Redis::publish('cluster_ready', json_encode([
|
||||
'event' => $event,
|
||||
'node' => [
|
||||
@ -59,6 +60,7 @@ public static function registerThisNode($report = true): void
|
||||
|
||||
public static function hset($key, $value, $data = []): void
|
||||
{
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
Redis::hset(self::$prefix . $key, $value, json_encode($data));
|
||||
}
|
||||
|
||||
@ -95,11 +97,13 @@ public static function listen(string|array $events, callable $callback, bool $ig
|
||||
|
||||
public static function get($key, $default = null): string|array|null
|
||||
{
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
return Redis::get(self::$prefix . $key, $default);
|
||||
}
|
||||
|
||||
public static function forget($key): void
|
||||
{
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
Redis::forget(self::$prefix . $key);
|
||||
}
|
||||
|
||||
@ -111,11 +115,13 @@ public static function forever($key, $value): void
|
||||
|
||||
public static function set($key, $value, $ttl = null): void
|
||||
{
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
Redis::set(self::$prefix . $key, $value, $ttl);
|
||||
}
|
||||
|
||||
public static function hget($key, $hashKey, $default = []): string|array|null
|
||||
{
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
$value = Redis::hget(self::$prefix . $key, $hashKey);
|
||||
|
||||
return $value ?: $default;
|
||||
@ -138,6 +144,7 @@ public static function nodes($hide_ip = false): array
|
||||
|
||||
public static function hgetAll($hashKey, $default = []): array
|
||||
{
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
$value = Redis::hgetall(self::$prefix . $hashKey);
|
||||
|
||||
return $value ?: $default;
|
||||
|
@ -3,11 +3,15 @@
|
||||
namespace App\Support;
|
||||
|
||||
use App\Exceptions\EmqxSupportException;
|
||||
use Illuminate\Http\Client\ConnectionException;
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class EmqxSupport
|
||||
{
|
||||
/**
|
||||
* @throws EmqxSupportException
|
||||
*/
|
||||
public function kickClient($client_id = null, $username = null): void
|
||||
{
|
||||
// 如果都为空,直接返回
|
||||
@ -20,7 +24,11 @@ public function kickClient($client_id = null, $username = null): void
|
||||
}
|
||||
|
||||
if ($username) {
|
||||
try {
|
||||
$clients = $this->clients(['username' => $username]);
|
||||
} catch (EmqxSupportException $e) {
|
||||
throw new EmqxSupportException($e->getMessage());
|
||||
}
|
||||
|
||||
if ($clients) {
|
||||
// 循环翻页
|
||||
@ -51,7 +59,11 @@ public function clients($params = [])
|
||||
'isTrusted' => true,
|
||||
], $params);
|
||||
|
||||
try {
|
||||
$response = $this->api()->get('clients', $params);
|
||||
} catch (ConnectionException $e) {
|
||||
throw new EmqxSupportException('EMQX API 无法连接。');
|
||||
}
|
||||
|
||||
if ($response->successful()) {
|
||||
return $response->json();
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
@ -22,9 +20,9 @@ public function __construct()
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return Application|Factory|View
|
||||
* @return View
|
||||
*/
|
||||
public function render()
|
||||
public function render(): View
|
||||
{
|
||||
return view('components.alert');
|
||||
}
|
||||
|
@ -2,15 +2,13 @@
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class BasicCard extends Component
|
||||
{
|
||||
|
||||
public $title;
|
||||
public string $title;
|
||||
|
||||
/**
|
||||
* Create a new component instance.
|
||||
@ -26,9 +24,9 @@ public function __construct($title)
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return Application|Factory|View
|
||||
* @return View
|
||||
*/
|
||||
public function render()
|
||||
public function render() :View
|
||||
{
|
||||
return view('components.basic-card', [
|
||||
'title' => $this->title,
|
||||
|
@ -2,14 +2,12 @@
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class HostStatus extends Component
|
||||
{
|
||||
public $status = null;
|
||||
public string|null $status = null;
|
||||
|
||||
/**
|
||||
* Create a new component instance.
|
||||
@ -26,9 +24,9 @@ public function __construct($status)
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return Application|Factory|View
|
||||
* @return View
|
||||
*/
|
||||
public function render()
|
||||
public function render(): View
|
||||
{
|
||||
return view('components.host-status', ['status' => $this->status]);
|
||||
}
|
||||
|
@ -3,8 +3,6 @@
|
||||
namespace App\View\Components;
|
||||
|
||||
use App\Models\Module;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
@ -27,9 +25,9 @@ public function __construct(Module $module)
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return Application|Factory|View
|
||||
* @return View
|
||||
*/
|
||||
public function render()
|
||||
public function render(): View
|
||||
{
|
||||
$years = $this->module->calculate();
|
||||
return view('components.module-earning', compact('years'));
|
||||
|
@ -3,8 +3,6 @@
|
||||
namespace App\View\Components;
|
||||
|
||||
use App\Models\Module;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
@ -23,9 +21,9 @@ public function __construct()
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return Application|Factory|View
|
||||
* @return View
|
||||
*/
|
||||
public function render()
|
||||
public function render(): View
|
||||
{
|
||||
$modules = Module::all();
|
||||
return view('components.module-script', compact('modules'));
|
||||
|
@ -2,21 +2,19 @@
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class Payment extends Component
|
||||
{
|
||||
public $payment = null;
|
||||
public string $payment = '';
|
||||
|
||||
/**
|
||||
* Create a new component instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($payment)
|
||||
public function __construct(string $payment)
|
||||
{
|
||||
//
|
||||
$this->payment = $payment;
|
||||
@ -25,9 +23,9 @@ public function __construct($payment)
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return Application|Factory|View
|
||||
* @return View
|
||||
*/
|
||||
public function render()
|
||||
public function render(): View
|
||||
{
|
||||
|
||||
$this->payment = match ($this->payment) {
|
||||
|
Loading…
Reference in New Issue
Block a user