使用 Pint 格式化代码

This commit is contained in:
iVampireSP.com 2023-01-31 00:14:07 +08:00
parent 1081455c23
commit 835b4fc7ab
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
174 changed files with 636 additions and 785 deletions

View File

@ -29,7 +29,6 @@ class All extends Command
*/
public function handle(): int
{
$admins = Admin::all();
$this->table(['ID', '邮箱'], $admins->map(function ($admin) {

View File

@ -29,11 +29,9 @@ class Create extends Command
*/
public function handle(): int
{
// 邮箱
$email = $this->ask('请输入邮箱');
// 密码
$password = $this->secret('请输入密码');
// 确认密码
@ -42,17 +40,18 @@ public function handle(): int
// 验证密码
if ($password !== $password_confirmation) {
$this->error('两次输入的密码不一致。');
return CommandAlias::FAILURE;
}
// 创建管理员
$admin = (new Admin)->create([
'email' => $email,
'password' => bcrypt($password)
'password' => bcrypt($password),
]);
// 输出信息
$this->info('管理员创建成功ID为' . $admin->id);
$this->info('管理员创建成功ID为'.$admin->id);
return CommandAlias::SUCCESS;
}

View File

@ -37,6 +37,7 @@ public function handle(): int
// 输出信息
$this->info('管理员删除成功。');
return CommandAlias::SUCCESS;
}
}

View File

@ -29,7 +29,6 @@ class Reset extends Command
*/
public function handle(): int
{
// 获取管理员ID
$id = $this->ask('请输入管理员ID');
@ -39,6 +38,7 @@ public function handle(): int
// 验证管理员
if (is_null($admin)) {
$this->error('管理员不存在。');
return CommandAlias::FAILURE;
}

View File

@ -46,7 +46,7 @@ public function handle(): int
$user = (new User)->find($user_id);
$this->info('封禁: ' . $user->name);
$this->info('封禁: '.$user->name);
$this->confirm('确定要继续吗?如果继续,将会暂停所有的主机,并且吊销所有 Token。');

View File

@ -39,12 +39,11 @@ public function __construct()
public function handle(): int
{
$this->warn('开始计算集成模块收益。');
$this->warn('当前时间: ' . now());
$this->warn('当前时间: '.now());
(new Module)->chunk(100, function ($modules) {
foreach ($modules as $module) {
$this->warn('模块: ' . $module->name);
$this->warn('模块: '.$module->name);
$years = $module->calculate();
foreach ($years as $year => $months) {
@ -64,7 +63,7 @@ public function handle(): int
});
$this->warn('计算模块收益完成。');
$this->warn('完成时间: ' . now());
$this->warn('完成时间: '.now());
return 1;
}

View File

@ -40,11 +40,11 @@ private function format(string $event, array $message = [])
{
$status = $this->switch($event, $message['data']);
if (!$status) {
if (! $status) {
return;
}
$message = "[{$message['node']['type']}] {$message['node']['id']}:$event: " . $status;
$message = "[{$message['node']['type']}] {$message['node']['id']}:$event: ".$status;
$this->info($message);
}

View File

@ -32,12 +32,13 @@ public function handle(): int
// 检测 service 参数
$service = $this->argument('service');
if (!in_array($service, ['web', 'all'])) {
if (! in_array($service, ['web', 'all'])) {
$this->error('service 参数错误,只能是 web 或 all。');
return CommandAlias::FAILURE;
}
ClusterSupport::publish('cluster.restart.' . $service);
ClusterSupport::publish('cluster.restart.'.$service);
$this->info('已经向集群广播重启命令,等待集群响应。');

View File

@ -37,33 +37,32 @@ public function handle(): int
$node_type = config('settings.node.type');
if ($node_type === 'master') {
// if force is true, delete the old file
if ($this->option('force') === 'true') {
$confirm = 'yes';
} else {
$confirm = $this->ask('主节点同步将会恢复上一次数据,确定吗?', true);
}
if (!$confirm) {
if (! $confirm) {
$this->warn('已取消。');
return CommandAlias::SUCCESS;
}
}
$cache_key = "master_config_zip";
$cache_key = 'master_config_zip';
$config = ClusterSupport::get($cache_key);
if ($config) {
$this->info('检查下载目录的 MD5 值。');
$config_md5_key = "master_config_zip_md5";
$config_md5_key = 'master_config_zip_md5';
$config_md5 = ClusterSupport::get($config_md5_key, '');
$md5 = md5($config);
if ($md5 !== $config_md5) {
$this->error('下载目录 MD5 值被篡改。请尝试从其他节点重新同步。');
return CommandAlias::FAILURE;
}
@ -84,7 +83,6 @@ public function handle(): int
$cmd = "rm -rf $cache_path";
exec($cmd);
$this->info('正在解压缩。');
$zip = new ZipArchive();
$zip->open($path);
@ -103,6 +101,7 @@ public function handle(): int
$this->info('检查 .env 文件的 MD5 值。');
if (md5($env) !== $env_md5) {
$this->error('.env 文件 MD5 值被篡改。请尝试从其他节点重新同步。');
return CommandAlias::FAILURE;
} else {
$this->info('正在写入 .env 文件。');
@ -121,9 +120,7 @@ public function handle(): int
$env = preg_replace('/^NODE_IP=.*$/m', "NODE_IP=$node_ip", $env);
file_put_contents(base_path('.env'), $env);
}
}
$this->info('正在清理。');
@ -139,10 +136,10 @@ public function handle(): int
ClusterSupport::publish('synced');
} else {
$this->error('没有找到缓存。请尝试从其他节点重新同步。');
return CommandAlias::FAILURE;
}
return CommandAlias::SUCCESS;
}
}

View File

@ -91,7 +91,7 @@ public function upload($node_type)
// 相对路径
$cache = 'config';
$cacheZip = $cache . '.zip';
$cacheZip = $cache.'.zip';
$zip = new ZipArchive();
$zip->open($cacheZip, ZipArchive::CREATE);
$this->addFileToZip($cache, $zip);
@ -110,30 +110,27 @@ public function upload($node_type)
unlink($cacheZip);
// 上传 config/secrets/ssl_fullchain.pem 和 config/secrets/ssl_privkey.pem
$ssl_fullchain_key = "config/secrets/ssl_fullchain.pem";
$ssl_privkey_key = "config/secrets/ssl_privkey.pem";
$ssl_fullchain_key = 'config/secrets/ssl_fullchain.pem';
$ssl_privkey_key = 'config/secrets/ssl_privkey.pem';
if (file_exists(base_path($ssl_fullchain_key)) && file_exists(base_path($ssl_privkey_key))) {
$this->info('正在上传 SSL 证书。');
ClusterSupport::forever("ssl_fullchain", file_get_contents(base_path($ssl_fullchain_key)));
ClusterSupport::forever("ssl_privkey", file_get_contents(base_path($ssl_privkey_key)));
ClusterSupport::forever('ssl_fullchain', file_get_contents(base_path($ssl_fullchain_key)));
ClusterSupport::forever('ssl_privkey', file_get_contents(base_path($ssl_privkey_key)));
// 计算 md5
$ssl_fullchain_md5 = md5_file(base_path($ssl_fullchain_key));
$ssl_privkey_md5 = md5_file(base_path($ssl_privkey_key));
$this->info('正在报告 SSL 证书的 MD5 值。');
ClusterSupport::forever("ssl_fullchain_md5", $ssl_fullchain_md5);
ClusterSupport::forever("ssl_privkey_md5", $ssl_privkey_md5);
ClusterSupport::forever('ssl_fullchain_md5', $ssl_fullchain_md5);
ClusterSupport::forever('ssl_privkey_md5', $ssl_privkey_md5);
ClusterSupport::publish('config.ssl.updated');
} else {
$this->warn('SSL 证书不存在,跳过。');
}
}
// 上传 .env 文件
@ -154,10 +151,10 @@ public function addFileToZip(string $path, ZipArchive $zip): void
$handler = opendir($path);
while (($filename = readdir($handler)) !== false) {
if ($filename != '.' && $filename != '..') {
if (is_dir($path . '/' . $filename)) {
$this->addFileToZip($path . '/' . $filename, $zip);
if (is_dir($path.'/'.$filename)) {
$this->addFileToZip($path.'/'.$filename, $zip);
} else {
$zip->addFile($path . '/' . $filename);
$zip->addFile($path.'/'.$filename);
}
}
}

View File

@ -31,9 +31,8 @@ class Work extends Command
*/
public function handle(): int
{
// 检测目录下是否有 rr
if (!file_exists(base_path('rr'))) {
if (! file_exists(base_path('rr'))) {
$this->warn('未找到 rr 文件,将自动下载。');
// 获取操作系统是 darwin 还是 linux
@ -65,14 +64,15 @@ public function handle(): int
exec("rm -rf roadrunner-$version-$os-$arch");
// 设置 rr 可执行权限
exec("chmod +x rr");
exec('chmod +x rr');
}
// 关闭 Octane
Artisan::call('octane:stop');
if (!config('settings.node.ip')) {
if (! config('settings.node.ip')) {
$this->error('请先配置节点 IP。');
return CommandAlias::FAILURE;
}
@ -92,30 +92,29 @@ public function handle(): int
$pid = pcntl_fork();
if ($pid === -1) {
$this->error('无法创建子进程。');
return CommandAlias::FAILURE;
} else if ($pid === 0) {
} elseif ($pid === 0) {
// 再打开一个,负责 octane
$pid = pcntl_fork();
if ($pid === -1) {
$this->error('无法创建子进程。');
return CommandAlias::FAILURE;
} else if ($pid === 0) {
} elseif ($pid === 0) {
// 子进程
$this->info('正在启动 Web。');
$command = 'php artisan octane:start --host=0.0.0.0 --rpc-port=6001 --port=8000';
$this->pipeCommand($command);
} else {
$this->report();
}
} else {
// 父进程
$this->work();
}
return CommandAlias::SUCCESS;
}
@ -146,7 +145,6 @@ private function pipeCommand($command): void
// 关闭进程
proc_close($process);
}
private function report(): void
@ -170,6 +168,7 @@ private function getCpuUsage(): float
{
// 获取 CPU 使用率
$cpu = sys_getloadavg();
return $cpu[0];
}
@ -194,14 +193,12 @@ private function dispatchEvent($event, $message = []): void
]);
$this->info('配置文件更新完成。');
},
'cluster.restart.web' => function () {
$this->info('正在重启 Web。');
exec('php artisan octane:reload');
ClusterSupport::publish('cluster.restarted.web');
$this->info('Web 重启完成。');

View File

@ -86,18 +86,17 @@ public function handle(): int
$this->info('完成。');
$this->warn('用户数量: ' . $users);
$this->warn('主机数量: ' . $hosts);
$this->warn('正在部署的主机数量: ' . $pending_hosts);
$this->warn('已停止的主机数量: ' . $stopped_hosts);
$this->warn('部署失败的主机数量: ' . $error_hosts);
$this->warn('正常的主机数量: ' . $active_hosts);
$this->warn('暂停的主机数量: ' . $suspended_hosts);
$this->warn('服务器数量: ' . $servers);
$this->warn('工单数量: ' . $workOrders);
$this->warn('工单回复数量: ' . $replies);
$this->warn('今年的交易记录: ' . $transactions . ' 条');
$this->warn('用户数量: '.$users);
$this->warn('主机数量: '.$hosts);
$this->warn('正在部署的主机数量: '.$pending_hosts);
$this->warn('已停止的主机数量: '.$stopped_hosts);
$this->warn('部署失败的主机数量: '.$error_hosts);
$this->warn('正常的主机数量: '.$active_hosts);
$this->warn('暂停的主机数量: '.$suspended_hosts);
$this->warn('服务器数量: '.$servers);
$this->warn('工单数量: '.$workOrders);
$this->warn('工单回复数量: '.$replies);
$this->warn('今年的交易记录: '.$transactions.' 条');
return 0;
}

View File

@ -45,15 +45,14 @@ public function handle(): int
$user = (new User)->where('email', $email_or_id)->orWhere('id', $email_or_id)->orWhere('name', $email_or_id)->first();
// $transaction = new Transaction();
$this->warn('用户基本信息');
$this->info('用户 ID: ' . $user->id);
$this->info('名称: ' . $user->name);
$this->info('邮箱: ' . $user->email);
$this->info('余额:' . $user->balance . ' 元');
$this->info('用户 ID: '.$user->id);
$this->info('名称: '.$user->name);
$this->info('邮箱: '.$user->email);
$this->info('余额:'.$user->balance.' 元');
$this->warn('前 10 条充值记录');
@ -61,7 +60,7 @@ public function handle(): int
// 倒序输出
foreach (array_reverse($balances->toArray()) as $balance) {
$this->info('[' . $balance['paid_at'] . '] 支付方式: ' . $balance['payment'] . ' 金额:' . $balance['amount'] . ' 元');
$this->info('['.$balance['paid_at'].'] 支付方式: '.$balance['payment'].' 金额:'.$balance['amount'].' 元');
}
$this->warn('前 10 个主机');
@ -70,7 +69,7 @@ public function handle(): int
// 倒序
foreach (array_reverse($hosts->toArray()) as $host) {
$this->info('[' . $host['module']['name'] . '](' . $host['price'] . ' 元) ' . $host['name']);
$this->info('['.$host['module']['name'].']('.$host['price'].' 元) '.$host['name']);
}
return 0;

View File

@ -35,7 +35,7 @@ public function handle(): int
if ($this->confirm('如果不指定主机名,将会扣除所有主机的费用,是否继续?', true)) {
(new Host)->chunk(100, function ($hosts) {
foreach ($hosts as $host) {
$this->info('正在扣除主机 ' . $host->name . ' 的费用: ' . $host->getPrice() . ' 元');
$this->info('正在扣除主机 '.$host->name.' 的费用: '.$host->getPrice().' 元');
$host->cost();
}
});
@ -43,13 +43,11 @@ public function handle(): int
} else {
$host_model = (new Host)->where('id', $host)->firstOrFail();
if ($this->confirm('是否扣除主机 ' . $host_model->name . ' 的费用?', true)) {
if ($this->confirm('是否扣除主机 '.$host_model->name.' 的费用?', true)) {
$host_model->cost();
}
}
return CommandAlias::SUCCESS;
}
}

View File

@ -45,14 +45,13 @@ public function handle(): void
$amount = $this->argument('amount');
$user = (new User)->find($user_id);
$this->warn('扣除金额: ' . $amount . ' 元');
$this->warn('扣除金额: '.$amount.' 元');
$this->warn('用户当前余额:' . $user->balance . ' 元');
$this->warn('用户当前余额:'.$user->balance.' 元');
$this->warn('剩余余额:' . $user->balance - $amount . ' 元');
$this->warn('剩余余额:'.$user->balance - $amount.' 元');
$confirm = $this->confirm('确认扣除?');

View File

@ -39,25 +39,21 @@ public function __construct()
*/
public function handle(): int
{
$this->warn('===== 运行环境 =====');
// php version
$this->info('PHP 版本: ' . PHP_VERSION);
$this->info('PHP 版本: '.PHP_VERSION);
// get mysql version
$mysql_version = DB::select('select version() as version')[0]->version;
$this->warn('MySQL 版本: ' . $mysql_version);
$this->warn('MySQL 版本: '.$mysql_version);
$redis_info = Redis::info();
// get redis version
$redis_version = $redis_info['redis_version'];
$this->warn('Redis 版本: ' . $redis_version);
$this->warn('Redis 版本: '.$redis_version);
// 是否是 Redis 集群
$redis_cluster = $redis_info['cluster_enabled'];
@ -70,49 +66,46 @@ public function handle(): int
// redis 操作系统
$redis_os = $redis_info['os'];
$this->warn('Redis 操作系统: ' . $redis_os);
$this->warn('Redis 操作系统: '.$redis_os);
// redis process id
$redis_pid = $redis_info['process_id'];
$this->warn('Redis 进程 ID: ' . $redis_pid);
$this->warn('Redis 进程 ID: '.$redis_pid);
// redis used memory
$redis_used_memory = $redis_info['used_memory_human'];
$this->info('Redis 内存: ' . $redis_used_memory);
$this->info('Redis 内存: '.$redis_used_memory);
// redis memory peak
$redis_memory_peak = $redis_info['used_memory_peak_human'];
$this->info('Redis 内存峰值: ' . $redis_memory_peak);
$this->info('Redis 内存峰值: '.$redis_memory_peak);
// redis memory lua
$redis_memory_lua = $redis_info['used_memory_lua_human'];
$this->info('Redis Lua 内存: ' . $redis_memory_lua);
$this->info('Redis Lua 内存: '.$redis_memory_lua);
// redis 连接
$redis_connected_clients = $redis_info['connected_clients'];
$this->info('Redis 连接数量: ' . $redis_connected_clients);
$this->info('Redis 连接数量: '.$redis_connected_clients);
// redis 命中率
$redis_keyspace_hits = $redis_info['keyspace_hits'];
$redis_keyspace_misses = $redis_info['keyspace_misses'];
$redis_keyspace_hit_rate = round($redis_keyspace_hits / ($redis_keyspace_hits + $redis_keyspace_misses) * 100, 2);
$this->info('Redis 命中率: ' . $redis_keyspace_hit_rate . '%');
$this->info('Redis 命中率: '.$redis_keyspace_hit_rate.'%');
// redis 总连接数
$redis_total_connections_received = $redis_info['total_connections_received'];
$this->info('Redis 总连接数: ' . $redis_total_connections_received);
$this->info('Redis 总连接数: '.$redis_total_connections_received);
// redis total commands
$redis_total_commands_processed = $redis_info['total_commands_processed'];
$this->info('Redis 总命令数: ' . $redis_total_commands_processed);
$this->info('Redis 总命令数: '.$redis_total_commands_processed);
$this->warn('===== 莱云 统计 =====');
$this->warn('要获取 莱云 统计信息,请运行 count 命令。');
return 0;
}
}

View File

@ -44,7 +44,7 @@ public function handle(): void
(new Host)->where('user_id', $user_id)->update([
'status' => 'suspended',
'suspended_at' => now()
'suspended_at' => now(),
]);
$this->info('暂停用户的所有主机成功。');

View File

@ -44,7 +44,7 @@ public function handle(): void
$user = (new User)->find($user_id);
$this->info('解除封禁: ' . $user->name);
$this->info('解除封禁: '.$user->name);
$user->banned_at = null;
$user->save();

View File

@ -44,30 +44,29 @@ public function handle(): int
$user_id = $this->argument('user_id');
$amount = $this->argument('amount');
// find user
$user = (new User)->findOrFail($user_id);
$this->info($user->name . ', 当前余额: ' . $user->balance . ' 元');
$this->info($user->name.', 当前余额: '.$user->balance.' 元');
$this->info('充值后余额: ' . ($user->balance + $amount) . ' 元');
if (!$this->confirm('确认充值 ' . $amount . ' 元?')) {
$this->info('充值后余额: '.($user->balance + $amount).' 元');
if (! $this->confirm('确认充值 '.$amount.' 元?')) {
$this->info('已取消。');
return 0;
}
$transaction = new Transaction();
$description = '控制台充值 ' . $amount . ' 元';
$description = '控制台充值 '.$amount.' 元';
$transaction->addAmount($user->id, 'console', $amount, $description, true);
$this->info('充值成功。');
$user->refresh();
$this->info($user->name . ', 当前余额: ' . $user->balance);
$this->info($user->name.', 当前余额: '.$user->balance);
return 0;
}
}

View File

@ -21,8 +21,7 @@ class Kernel extends ConsoleKernel
/**
* Define the application's command schedule.
*
* @param Schedule $schedule
*
* @param Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule): void
@ -70,7 +69,7 @@ protected function schedule(Schedule $schedule): void
*/
protected function commands(): void
{
$this->load(__DIR__ . '/Commands');
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}

View File

@ -7,7 +7,6 @@
class Servers extends Event implements ShouldBroadcast
{
public array $data;
public string $type = 'servers.updated';

View File

@ -17,13 +17,15 @@ class Users extends Event implements ShouldBroadcastNow
use SerializesModels;
public User $user;
public array|Model $data;
public null|Module $module = null;
public string $event = 'notification';
public Carbon $sent_at;
/**
* Create a new event instance.
*
@ -57,7 +59,6 @@ public function __construct(User|int $user, string $event, array|Model $data)
// }
}
// log
if (config('app.env') != 'production') {
Log::debug('Users Event', [
@ -69,14 +70,12 @@ public function __construct(User|int $user, string $event, array|Model $data)
}
}
public
function broadcastOn(): PrivateChannel
public function broadcastOn(): PrivateChannel
{
return new PrivateChannel('users.' . $this->user->id);
return new PrivateChannel('users.'.$this->user->id);
}
public
function broadcastAs(): string
public function broadcastAs(): string
{
return 'messages';
}

View File

@ -7,4 +7,4 @@
class ChargeException extends Exception
{
//
}
}

View File

@ -42,7 +42,6 @@ class Handler extends ExceptionHandler
/**
* Register the exception handling callbacks for the application.
*
*/
public function register(): void
{
@ -68,9 +67,8 @@ public function register(): void
/**
* Convert an authentication exception into an unauthenticated response.
*
* @param Request $request
* @param AuthenticationException $exception
*
* @param Request $request
* @param AuthenticationException $exception
* @return JsonResponse|RedirectResponse
*/
protected function unauthenticated($request, AuthenticationException $exception): JsonResponse|RedirectResponse

View File

@ -4,5 +4,4 @@
trait HttpEvent
{
}

View File

@ -13,9 +13,10 @@ public function await($name, Closure $callback)
if (config('app.env') == 'local') {
return $callback();
}
$lock = Cache::lock("lock_" . $name, 5);
$lock = Cache::lock('lock_'.$name, 5);
try {
$lock->block(5);
return $callback();
} finally {
optional($lock)->release();

View File

@ -26,8 +26,7 @@ public function index(): View
/**
* Store a newly created resource in storage.
*
* @param Request $request
*
* @param Request $request
* @return RedirectResponse
*/
public function store(Request $request): RedirectResponse
@ -45,7 +44,7 @@ public function store(Request $request): RedirectResponse
'password' => bcrypt($password),
]);
return redirect()->route('admin.admins.edit', $admin)->with('success', '管理员创建成功,密码为:' . $password . '。');
return redirect()->route('admin.admins.edit', $admin)->with('success', '管理员创建成功,密码为:'.$password.'。');
}
/**
@ -61,8 +60,7 @@ public function create(): View
/**
* Show the form for editing the specified resource.
*
* @param Admin $admin
*
* @param Admin $admin
* @return View
*/
public function edit(Admin $admin): View
@ -73,15 +71,14 @@ public function edit(Admin $admin): View
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param Admin $admin
*
* @param Request $request
* @param Admin $admin
* @return RedirectResponse
*/
public function update(Request $request, Admin $admin): RedirectResponse
{
$request->validate([
'email' => 'required|email|unique:admins,email,' . $admin->id,
'email' => 'required|email|unique:admins,email,'.$admin->id,
'name' => 'required|string|max:30',
]);
@ -91,7 +88,7 @@ public function update(Request $request, Admin $admin): RedirectResponse
// 随机密码
$password = Str::random();
$msg .= ',新的密码为:' . $password;
$msg .= ',新的密码为:'.$password;
$admin->password = bcrypt($password);
}
@ -109,8 +106,7 @@ public function update(Request $request, Admin $admin): RedirectResponse
/**
* Remove the specified resource from storage.
*
* @param Admin $admin
*
* @param Admin $admin
* @return RedirectResponse
*/
public function destroy(Admin $admin): RedirectResponse

View File

@ -25,8 +25,7 @@ public function index(): View
/**
* Store a newly created resource in storage.
*
* @param Request $request
*
* @param Request $request
* @return View
*/
public function store(Request $request): View
@ -59,8 +58,7 @@ public function create(): View
/**
* Display the specified resource.
*
* @param Application $application
*
* @param Application $application
* @return RedirectResponse
*/
public function show(Application $application): RedirectResponse
@ -73,8 +71,7 @@ public function show(Application $application): RedirectResponse
/**
* Show the form for editing the specified resource.
*
* @param Application $application
*
* @param Application $application
* @return View
*/
public function edit(Application $application): View
@ -87,9 +84,8 @@ public function edit(Application $application): View
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param Application $application
*
* @param Request $request
* @param Application $application
* @return RedirectResponse
*/
public function update(Request $request, Application $application): RedirectResponse
@ -99,7 +95,7 @@ public function update(Request $request, Application $application): RedirectResp
$this->validate($request, [
'name' => 'required',
'description' => 'required',
'api_token' => 'required|unique:applications,api_token,' . $application->id,
'api_token' => 'required|unique:applications,api_token,'.$application->id,
]);
$application->update($request->all());
@ -110,8 +106,7 @@ public function update(Request $request, Application $application): RedirectResp
/**
* Remove the specified resource from storage.
*
* @param Application $application
*
* @param Application $application
* @return RedirectResponse
*/
public function destroy(Application $application): RedirectResponse

View File

@ -14,7 +14,7 @@ class AuthController extends Controller
*/
public function index(): View|RedirectResponse
{
if (!auth('admin')->check()) {
if (! auth('admin')->check()) {
return view('admin.login');
} else {
return redirect()->route('admin.index');
@ -22,8 +22,7 @@ public function index(): View|RedirectResponse
}
/**
* @param Request $request
*
* @param Request $request
* @return RedirectResponse
*/
public function login(Request $request): RedirectResponse
@ -41,6 +40,7 @@ public function login(Request $request): RedirectResponse
public function logout(): RedirectResponse
{
auth('admin')->logout();
return redirect()->route('admin.login');
}
}

View File

@ -51,7 +51,7 @@ public function destroy(Request $request): RedirectResponse
$module_name = explode('.', $username)[0];
$this->dispatch(new EMQXKickClientJob(null, $module_name, false));
$this->dispatch(new EMQXKickClientJob(null, $module_name . '.', true));
$this->dispatch(new EMQXKickClientJob(null, $module_name.'.', true));
}
return back()->with('success', '正在让它们下线。');

View File

@ -14,8 +14,7 @@ class HostController extends Controller
* Display a listing of the resource.
*
*
* @param Request $request
*
* @param Request $request
* @return View
*/
public function index(Request $request): View
@ -25,7 +24,7 @@ public function index(Request $request): View
// 遍历所有的搜索条件
foreach (['name', 'module_id', 'status', 'user_id', 'price', 'managed_price', 'created_at', 'updated_at'] as $field) {
if ($request->has($field)) {
$hosts = $hosts->where($field, 'like', '%' . $request->input($field) . '%');
$hosts = $hosts->where($field, 'like', '%'.$request->input($field).'%');
}
}
@ -39,8 +38,7 @@ public function index(Request $request): View
/**
* Show the form for editing the specified resource.
*
* @param Host $host
*
* @param Host $host
* @return View
*/
public function edit(Host $host): View
@ -51,9 +49,8 @@ public function edit(Host $host): View
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param Host $host
*
* @param Request $request
* @param Host $host
* @return RedirectResponse
*/
public function update(Request $request, Host $host): RedirectResponse
@ -73,8 +70,7 @@ public function update(Request $request, Host $host): RedirectResponse
/**
* Remove the specified resource from storage.
*
* @param Host $host
*
* @param Host $host
* @return RedirectResponse
*/
public function destroy(Host $host): RedirectResponse

View File

@ -16,8 +16,7 @@ class ModuleController extends Controller
/**
* Display a listing of the resource.
*
* @param Module $module
*
* @param Module $module
* @return View
*/
public function index(Module $module): View
@ -40,8 +39,7 @@ public function create(): View
/**
* Store a newly created resource in storage.
*
* @param Request $request
*
* @param Request $request
* @return RedirectResponse
*/
public function store(Request $request): RedirectResponse
@ -62,7 +60,6 @@ public function store(Request $request): RedirectResponse
$module->save();
return redirect()->route('admin.modules.edit', $module)->with('success', '模块创建成功。');
}
private function rules(): array
@ -80,8 +77,7 @@ private function rules(): array
/**
* Display the specified resource.
*
* @param Module $module
*
* @param Module $module
* @return View
*/
public function show(Module $module): View
@ -96,8 +92,7 @@ public function show(Module $module): View
/**
* Show the form for editing the specified resource.
*
* @param Module $module
*
* @param Module $module
* @return View
*/
public function edit(Module $module): View
@ -110,9 +105,8 @@ public function edit(Module $module): View
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param Module $module
*
* @param Request $request
* @param Module $module
* @return RedirectResponse
*/
public function update(Request $request, Module $module): RedirectResponse
@ -125,7 +119,7 @@ public function update(Request $request, Module $module): RedirectResponse
$module->status = $request->input('status');
$module->wecom_key = $request->input('wecom_key');
if (!$request->filled('api_token')) {
if (! $request->filled('api_token')) {
$module->api_token = Str::random(60);
} else {
$module->api_token = $request->input('api_token');
@ -143,18 +137,17 @@ public function update(Request $request, Module $module): RedirectResponse
// 充值或者扣费
if ($diff > 0) {
$description = '管理员 ' . auth('admin')->user()->name . ' 充值 ' . $diff . ' 元';
$description = '管理员 '.auth('admin')->user()->name.' 充值 '.$diff.' 元';
$module->charge($diff, 'console', $description);
} else {
$description = '管理员 ' . auth('admin')->user()->name . ' 扣除 ' . abs($diff) . ' 元';
$description = '管理员 '.auth('admin')->user()->name.' 扣除 '.abs($diff).' 元';
$module->reduce(abs($diff), $description);
}
}
}
if ($request->input('reset_api_token')) {
$text .= ', API Token 为 ' . $module->api_token . '。';
$text .= ', API Token 为 '.$module->api_token.'。';
} else {
$text .= '。';
}
@ -165,8 +158,7 @@ public function update(Request $request, Module $module): RedirectResponse
/**
* Remove the specified resource from storage.
*
* @param Module $module
*
* @param Module $module
* @return RedirectResponse
*/
public function destroy(Module $module): RedirectResponse
@ -198,7 +190,6 @@ public function allows_store(Request $request, Module $module): RedirectResponse
return back()->with('success', '已信任该模块。');
}
// fast login
public function allows_destroy(Module $module, ModuleAllow $allow): RedirectResponse
@ -214,6 +205,7 @@ public function fast_login(Module $module): View|RedirectResponse
if ($resp['success']) {
$resp = $resp['json'];
return view('admin.modules.login', compact('module', 'resp'));
} else {
return redirect()->route('admin.modules.show', $module)->with('error', '快速登录失败,可能是模块不支持。');

View File

@ -14,12 +14,10 @@
class NotificationController extends Controller
{
/**
* Show the form for creating a new resource.
*
* @param Request $request
*
* @param Request $request
* @return View
*/
public function create(Request $request): View
@ -37,26 +35,26 @@ public function query(Request|array $request): User|CachedBuilder|Builder
$request = $request->all();
}
if (!empty($request['user_id'])) {
if (! empty($request['user_id'])) {
$users = (new User)->where('id', $request['user_id']);
} else {
$users = User::query();
if (!empty($request['user'])) {
if (! empty($request['user'])) {
$user = $request['user'];
if ($user == 'active') {
// 寻找有 host 的用户
$users = $users->whereHas('hosts');
} else if ($user == 'normal') {
} elseif ($user == 'normal') {
$users = $users->whereNull('banned_at');
} else if ($user == 'banned') {
} elseif ($user == 'banned') {
$users = $users->whereNotNull('banned_at');
}
}
}
if (!empty($request['module_id'])) {
if (! empty($request['module_id'])) {
// 从 hosts 中找到 module_id然后找到拥有此 host 的用户
$users = $users->whereHas('hosts', function ($query) use ($request) {
$query->where('module_id', $request['module_id']);
@ -69,8 +67,7 @@ public function query(Request|array $request): User|CachedBuilder|Builder
/**
* Store a newly created resource in storage.
*
* @param Request $request
*
* @param Request $request
* @return RedirectResponse
*/
public function store(Request $request): RedirectResponse

View File

@ -14,9 +14,8 @@ class ReplyController extends Controller
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @param WorkOrder $work_order
*
* @param Request $request
* @param WorkOrder $work_order
* @return RedirectResponse
*/
public function store(Request $request, WorkOrder $work_order): RedirectResponse
@ -32,7 +31,7 @@ public function store(Request $request, WorkOrder $work_order): RedirectResponse
(new Reply)->create([
'content' => $request->input('content'),
'work_order_id' => $work_order->id,
'name' => auth('admin')->user()->name
'name' => auth('admin')->user()->name,
]);
return back()->with('success', '回复成功,请等待同步。');
@ -41,9 +40,8 @@ public function store(Request $request, WorkOrder $work_order): RedirectResponse
/**
* Show the form for editing the specified resource.
*
* @param WorkOrder $work_order
* @param Reply $reply
*
* @param WorkOrder $work_order
* @param Reply $reply
* @return View
*/
public function edit(WorkOrder $work_order, Reply $reply): View
@ -54,10 +52,9 @@ public function edit(WorkOrder $work_order, Reply $reply): View
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param WorkOrder $work_order
* @param Reply $reply
*
* @param Request $request
* @param WorkOrder $work_order
* @param Reply $reply
* @return RedirectResponse
*/
public function update(Request $request, WorkOrder $work_order, Reply $reply): RedirectResponse
@ -67,7 +64,7 @@ public function update(Request $request, WorkOrder $work_order, Reply $reply): R
]);
$reply->update([
'content' => $request->input('content')
'content' => $request->input('content'),
]);
return redirect()->route('admin.work-orders.show', $work_order)->with('success', '修改成功。');
@ -76,9 +73,8 @@ public function update(Request $request, WorkOrder $work_order, Reply $reply): R
/**
* Remove the specified resource from storage.
*
* @param WorkOrder $work_order
* @param Reply $reply
*
* @param WorkOrder $work_order
* @param Reply $reply
* @return RedirectResponse
*/
public function destroy(WorkOrder $work_order, Reply $reply): RedirectResponse

View File

@ -18,7 +18,6 @@ class UserController extends Controller
{
/**
* Display a listing of the resource.
*
*/
public function index(Request $request): View
{
@ -29,15 +28,15 @@ public function index(Request $request): View
}
if ($request->filled('name')) {
$users = $users->where('name', 'like', '%' . $request->input('name') . '%');
$users = $users->where('name', 'like', '%'.$request->input('name').'%');
}
if ($request->filled('email')) {
$users = $users->where('email', 'like', '%' . $request->input('email') . '%');
$users = $users->where('email', 'like', '%'.$request->input('email').'%');
}
if ($request->filled('real_name')) {
$users = $users->where('real_name', 'like', '%' . $request->input('real_name') . '%');
$users = $users->where('real_name', 'like', '%'.$request->input('real_name').'%');
}
if ($request->has('banned_at')) {
@ -58,22 +57,20 @@ public function index(Request $request): View
/**
* Display the specified resource.
*
* @param User $user
*
* @param User $user
* @return RedirectResponse
*/
public function show(User $user): RedirectResponse
{
Auth::guard('web')->login($user);
return back()->with('success', '您已切换到用户 ' . $user->name . ' 的身份。');
return back()->with('success', '您已切换到用户 '.$user->name.' 的身份。');
}
/**
* Show the form for editing the specified resource.
*
* @param User $user
*
* @param User $user
* @return View
*/
public function edit(User $user): View
@ -89,9 +86,8 @@ public function edit(User $user): View
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param User $user
*
* @param Request $request
* @param User $user
* @return RedirectResponse
*/
public function update(Request $request, User $user): RedirectResponse
@ -119,20 +115,19 @@ public function update(Request $request, User $user): RedirectResponse
if ($request->filled('one_time_action')) {
if ($one_time_action == 'clear_all_keys') {
$user->tokens()->delete();
} else if ($one_time_action == 'suspend_all_hosts') {
} elseif ($one_time_action == 'suspend_all_hosts') {
$user->hosts()->update(['status' => 'suspended', 'suspended_at' => now()]);
} else if ($one_time_action == 'stop_all_hosts') {
} elseif ($one_time_action == 'stop_all_hosts') {
$user->hosts()->update(['status' => 'stopped', 'suspended_at' => null]);
} else if ($one_time_action == 'add_balance') {
$description = '管理员 ' . $request->user('admin')->name . " 增加。";
} elseif ($one_time_action == 'add_balance') {
$description = '管理员 '.$request->user('admin')->name.' 增加。';
$user->charge($request->input('balance'), 'console', $description);
} else if ($one_time_action == 'reduce_balance') {
$description = '管理员 ' . $request->user('admin')->name . " 扣除。";
} elseif ($one_time_action == 'reduce_balance') {
$description = '管理员 '.$request->user('admin')->name.' 扣除。';
$user->reduce($request->input('balance'), $description);
}
}
if ($request->has('user_group_id')) {

View File

@ -26,8 +26,7 @@ public function index(): View
/**
* Store a newly created resource in storage.
*
* @param Request $request
*
* @param Request $request
* @return RedirectResponse
*/
public function store(Request $request): RedirectResponse
@ -64,8 +63,7 @@ public function create(): View
/**
* Display the specified resource.
*
* @param UserGroup $user_group
*
* @param UserGroup $user_group
* @return View
*/
public function show(UserGroup $user_group): View
@ -78,8 +76,7 @@ public function show(UserGroup $user_group): View
/**
* Show the form for editing the specified resource.
*
* @param UserGroup $user_group
*
* @param UserGroup $user_group
* @return View
*/
public function edit(UserGroup $user_group): View
@ -92,9 +89,8 @@ public function edit(UserGroup $user_group): View
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param UserGroup $user_group
*
* @param Request $request
* @param UserGroup $user_group
* @return RedirectResponse
*/
public function update(Request $request, UserGroup $user_group): RedirectResponse
@ -110,8 +106,7 @@ public function update(Request $request, UserGroup $user_group): RedirectRespons
/**
* Remove the specified resource from storage.
*
* @param UserGroup $user_group
*
* @param UserGroup $user_group
* @return RedirectResponse
*/
public function destroy(UserGroup $user_group): RedirectResponse

View File

@ -15,8 +15,7 @@ class WorkOrderController extends Controller
/**
* Display a listing of the resource.
*
* @param WorkOrder $workOrder
*
* @param WorkOrder $workOrder
* @return View
*/
public function index(WorkOrder $workOrder): View
@ -29,8 +28,7 @@ public function index(WorkOrder $workOrder): View
/**
* Display the specified resource.
*
* @param WorkOrder $workOrder
*
* @param WorkOrder $workOrder
* @return View
*/
public function show(WorkOrder $workOrder): View
@ -45,8 +43,7 @@ public function show(WorkOrder $workOrder): View
/**
* Show the form for editing the specified resource.
*
* @param WorkOrder $workOrder
*
* @param WorkOrder $workOrder
* @return View
*/
public function edit(WorkOrder $workOrder): View
@ -57,9 +54,8 @@ public function edit(WorkOrder $workOrder): View
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param WorkOrder $workOrder
*
* @param Request $request
* @param WorkOrder $workOrder
* @return RedirectResponse
*/
public function update(Request $request, WorkOrder $workOrder): RedirectResponse
@ -80,8 +76,7 @@ public function update(Request $request, WorkOrder $workOrder): RedirectResponse
/**
* Remove the specified resource from storage.
*
* @param WorkOrder $workOrder
*
* @param WorkOrder $workOrder
* @return RedirectResponse
*/
public function destroy(WorkOrder $workOrder): RedirectResponse

View File

@ -24,8 +24,7 @@ public function index(): JsonResponse
/**
* Store a newly created resource in storage.
*
* @param Request $request
*
* @param Request $request
* @return JsonResponse
*/
public function store(Request $request): JsonResponse
@ -50,14 +49,12 @@ public function store(Request $request): JsonResponse
/**
* Display the specified resource.
*
* @param Balance $balance
*
* @param Balance $balance
* @return JsonResponse
*/
public function show(Balance $balance): JsonResponse
{
if ($balance->canPay()) {
$url = route('balances.show', compact('balance'));
$balance->url = $url;

View File

@ -4,22 +4,22 @@
use App\Http\Controllers\Controller;
use Closure;
use function config;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use function config;
class ForumController extends Controller
{
private mixed $baseUrl;
private PendingRequest $http;
public function __construct()
{
$this->baseUrl = config('settings.forum.base_url');
$this->http = Http::baseUrl($this->baseUrl . '/api')->throw();
$this->http = Http::baseUrl($this->baseUrl.'/api')->throw();
}
public function announcements(): JsonResponse
@ -36,7 +36,7 @@ public function cache(Closure $callback)
// 获取调用方法名
$method = debug_backtrace()[1]['function'];
return Cache::remember('forum.func.' . $method, 60, function () use ($callback) {
return Cache::remember('forum.func.'.$method, 60, function () use ($callback) {
return $callback();
});
}

View File

@ -6,10 +6,10 @@
use App\Http\Requests\User\HostRequest;
use App\Jobs\Host\HostJob;
use App\Models\Host;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Cache;
use function auth;
use function dispatch;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Cache;
use function now;
class HostController extends Controller
@ -37,7 +37,7 @@ public function update(HostRequest $request, Host $host): JsonResponse
$user = $request->user();
if ($user->balance < 0.5) {
return $this->error('余额不足,无法开启计费项目。请确保您的余额至少为 0.5 元,您当前有 ' . $user->balance . ' 元。');
return $this->error('余额不足,无法开启计费项目。请确保您的余额至少为 0.5 元,您当前有 '.$user->balance.' 元。');
}
$host->update([
@ -74,11 +74,11 @@ public function usages(): JsonResponse
{
$month = now()->month;
$month_cache_key = 'user_' . auth()->id() . '_month_' . $month . '_hosts_balances';
$month_cache_key = 'user_'.auth()->id().'_month_'.$month.'_hosts_balances';
$hosts_balances = Cache::get($month_cache_key, []);
return $this->success([
'balances' => $hosts_balances
'balances' => $hosts_balances,
]);
}
}

View File

@ -20,7 +20,7 @@ public function index(): JsonResponse
public function servers(Module $module): JsonResponse
{
$servers = Cache::get('module:' . $module->id . ':servers', []);
$servers = Cache::get('module:'.$module->id.':servers', []);
return $this->success($servers);
}

View File

@ -5,17 +5,16 @@
use App\Http\Controllers\Controller;
use App\Models\WorkOrder\Reply;
use App\Models\WorkOrder\WorkOrder;
use function auth;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use function auth;
class ReplyController extends Controller
{
/**
* Display a listing of the resource.
*
* @param WorkOrder $workOrder
*
* @param WorkOrder $workOrder
* @return JsonResponse
*/
public function index(WorkOrder $workOrder): JsonResponse
@ -28,9 +27,8 @@ public function index(WorkOrder $workOrder): JsonResponse
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @param WorkOrder $workOrder
*
* @param Request $request
* @param WorkOrder $workOrder
* @return JsonResponse
*/
public function store(Request $request, WorkOrder $workOrder): JsonResponse
@ -44,7 +42,7 @@ public function store(Request $request, WorkOrder $workOrder): JsonResponse
}
// 如果工单已经关闭,那么访客不能回复
if ($workOrder->isClosed() && !auth('sanctum')->check()) {
if ($workOrder->isClosed() && ! auth('sanctum')->check()) {
return $this->error('工单已关闭,无法进行回复。');
}

View File

@ -57,7 +57,7 @@ public function update(Request $request, WorkOrder $workOrder): JsonResponse
]);
// 访客不能关闭
if ($request->input('status') === 'closed' && !auth('sanctum')->check()) {
if ($request->input('status') === 'closed' && ! auth('sanctum')->check()) {
return $this->forbidden('访客不能修改工单状态。');
}

View File

@ -15,7 +15,6 @@ public function index()
return $this->success($modules);
}
public function show(Module $module): JsonResponse
{
return $this->success($module);

View File

@ -24,7 +24,7 @@ public function authentication(Request $request): Response
$module = (new Module)->where('id', $module_id)->first();
if (!$module) {
if (! $module) {
return $this->ignore();
}
@ -33,7 +33,7 @@ public function authentication(Request $request): Response
}
// 如果没有设置 device_id那么就是模块自己的连接
if (!$device_id) {
if (! $device_id) {
// 让 api_token 可见
$module->makeVisible('api_token');
@ -62,7 +62,6 @@ public function authentication(Request $request): Response
} else {
return $this->deny();
}
}
}
@ -119,25 +118,23 @@ public function authorization(Request $request): Response
$module = (new Module)->where('id', $module_id)->first();
if (!$module) {
if (! $module) {
// 不属于我们管理,跳过。
return $this->ignore();
}
// 设备只能在自己的模块下发布消息
if ($action == 'publish') {
if ($topics[0] !== $module_id) {
// 但是,在拒绝之前,应该检查一下,是否有允许的模块
$allow = (new ModuleAllow)->where('module_id', $topics[0])->where('allowed_module_id', $module_id)->exists();
if (!$allow) {
if (! $allow) {
return $this->deny();
}
}
}
if (count($usernames) === 1) {
// 是模块自己的连接
return $this->allow();

View File

@ -6,7 +6,6 @@
use App\Models\PersonalAccessToken;
use App\Models\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Arr;
class UserController extends Controller
{
@ -22,12 +21,10 @@ public function show(User $user): JsonResponse
return $this->success($user);
}
public function auth($token): JsonResponse
{
$token = PersonalAccessToken::findToken($token);
return $token ? $this->success($token->tokenable) : $this->notFound();
}
}

View File

@ -16,7 +16,7 @@ public function broadcast_to_user(Request $request, User $user): JsonResponse
$user->notify(new WebNotification($request->all(), $request->input('event')));
return $this->created("message sent.");
return $this->created('message sent.');
}
private function rules(): array

View File

@ -18,10 +18,11 @@ public function index(Request $request): JsonResponse
try {
$clients = $emqx->pagination([
'like_username' => $request->user('module')->id . '.',
'like_username' => $request->user('module')->id.'.',
]);
} catch (EmqxSupportException $e) {
Log::error('emqx connect failed.', [$e]);
return $this->error('unable connectto emqx');
}

View File

@ -5,13 +5,13 @@
use App\Http\Controllers\Controller;
use App\Models\Host;
use App\Models\User;
use function auth;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
use function auth;
// use App\Models\User;
@ -19,8 +19,6 @@ class HostController extends Controller
{
/**
* Display a listing of the resource.
*
*
*/
public function index(Request $request): Paginator
{
@ -30,9 +28,9 @@ public function index(Request $request): Paginator
/**
* Store a newly created resource in storage.
*
* @param Request $request
*
* @param Request $request
* @return Response|JsonResponse
*
* @throws ValidationException
*/
public function store(Request $request): Response|JsonResponse
@ -61,7 +59,7 @@ public function store(Request $request): Response|JsonResponse
'price' => $request->input('price'),
'managed_price' => $request->input('managed_price'),
'user_id' => $user->id,
'module_id' => auth('module')->id()
'module_id' => auth('module')->id(),
];
$host = (new Host)->create($data);
@ -74,13 +72,11 @@ public function store(Request $request): Response|JsonResponse
/**
* Display the specified resource.
*
* @param Host $host
*
* @param Host $host
* @return JsonResponse
*/
public function show(Host $host): JsonResponse
{
return $this->success($host);
//
@ -90,10 +86,10 @@ public function show(Host $host): JsonResponse
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param Host $host
*
* @param Request $request
* @param Host $host
* @return JsonResponse
*
* @throws ValidationException
*/
public function update(Request $request, Host $host): JsonResponse
@ -124,14 +120,13 @@ public function update(Request $request, Host $host): JsonResponse
/**
* Remove the specified resource from storage.
*
* @param $host
*
* @param $host
* @return JsonResponse
*/
public function destroy($host): JsonResponse
{
// if host not instance of HostJob
if (!$host instanceof Host) {
if (! $host instanceof Host) {
$host = (new Host)->findOrFail($host);
}

View File

@ -13,8 +13,7 @@ class ReplyController extends Controller
/**
* Display a listing of the resource.
*
* @param Request $request
*
* @param Request $request
* @return JsonResponse
*/
public function index(Request $request): JsonResponse
@ -26,8 +25,6 @@ public function index(Request $request): JsonResponse
/**
* Store a newly created resource in storage.
*
*
*/
public function store(Request $request, WorkOrder $work_order): JsonResponse
{

View File

@ -10,13 +10,14 @@
class TaskController extends Controller
{
public int $user_id, $host_id;
public int $user_id;
public int $host_id;
/**
* Display a listing of the resource.
*
* @param Request $request
*
* @param Request $request
* @return JsonResponse
*/
public function index(Request $request): JsonResponse
@ -29,9 +30,9 @@ public function index(Request $request): JsonResponse
/**
* Store a newly created resource in storage.
*
* @param Request $request
*
* @param Request $request
* @return JsonResponse
*
* @throws ValidationException
*/
public function store(Request $request): JsonResponse
@ -51,10 +52,10 @@ public function store(Request $request): JsonResponse
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param Task $task
*
* @param Request $request
* @param Task $task
* @return JsonResponse
*
* @throws ValidationException
*/
public function update(Request $request, Task $task): JsonResponse
@ -65,10 +66,8 @@ public function update(Request $request, Task $task): JsonResponse
'status' => 'sometimes|in:pending,processing,need_operation,done,success,failed,error,canceled',
]);
$task->update($request->all());
return $this->updated($task);
}
}

View File

@ -24,15 +24,15 @@ public function index(Request $request): JsonResponse
// 搜索 name, email, balance
if ($request->has('name')) {
$users->where('name', 'like', '%' . $request->input('name') . '%');
$users->where('name', 'like', '%'.$request->input('name').'%');
}
if ($request->has('email')) {
$users->where('email', 'like', '%' . $request->input('email') . '%');
$users->where('email', 'like', '%'.$request->input('email').'%');
}
if ($request->has('balance')) {
$users->where('balance', 'like', '%' . $request->input('balance') . '%');
$users->where('balance', 'like', '%'.$request->input('balance').'%');
}
$users = $users->simplePaginate(100);
@ -84,7 +84,7 @@ public function update(Request $request, User $user): JsonResponse
$module->reduce($balance, $request->description, true, [
'user_id' => $user->id,
'payment' => 'module_balance'
'payment' => 'module_balance',
]);
$user->charge($balance, 'module_balance', $request->description);
@ -102,12 +102,10 @@ public function auth($token): JsonResponse
return $token ? $this->success(Arr::only(
$token->tokenable
->makeVisible('real_name')
->toArray()
,
->toArray(),
[
'id', 'name', 'email', 'real_name'
'id', 'name', 'email', 'real_name',
]
)) : $this->notFound();
}
}

View File

@ -16,8 +16,9 @@ public function verify(Request $request): JsonResponse
{
$result = (new RealNameSupport())->verify($request->all());
if (!$result) {
if (! $result) {
Log::warning('实名认证失败', $request->all());
return $this->error('实名认证失败。');
}
@ -26,7 +27,7 @@ public function verify(Request $request): JsonResponse
$user->id_card = $result['id_card'];
$user->save();
$user->reduce("0.7", '实名认证费用。');
$user->reduce('0.7', '实名认证费用。');
return $this->success('实名认证成功。');
}

View File

@ -7,6 +7,8 @@
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Notifications\User\UserNotification;
use function back;
use function config;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\GuzzleException;
@ -15,8 +17,6 @@
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use Illuminate\View\View;
use function back;
use function config;
use function redirect;
use function session;
use function view;
@ -27,26 +27,22 @@ public function index(Request $request): View|RedirectResponse
{
// if logged in
if ($request->filled('callback')) {
$callback = $request->input('callback');
session(['callback' => $callback]);
if (Auth::guard('web')->check()) {
$callbackHost = parse_url($callback, PHP_URL_HOST);
$dashboardHost = parse_url(config('settings.dashboard.base_url'), PHP_URL_HOST);
if ($callbackHost === $dashboardHost) {
if (!Auth::guard('web')->user()->isRealNamed()) {
if (! Auth::guard('web')->user()->isRealNamed()) {
return redirect()->route('real_name.create')->with('status', '重定向已被打断,需要先实人认证。');
}
$token = $request->user()->createToken('Dashboard')->plainTextToken;
return redirect($callback . '?token=' . $token);
return redirect($callback.'?token='.$token);
}
return redirect()->route('confirm_redirect');
@ -78,14 +74,14 @@ public function redirect(Request $request): RedirectResponse
'meta' => 'test_meta',
]);
return redirect()->to(config('oauth.oauth_auth_url') . '?' . $query);
return redirect()->to(config('oauth.oauth_auth_url').'?'.$query);
}
public function callback(Request $request): RedirectResponse
{
$state = $request->session()->pull('state');
if (!strlen($state) > 0 && $state === $request->input('state')) {
if (! strlen($state) > 0 && $state === $request->input('state')) {
return redirect(route('login'));
}
@ -111,7 +107,7 @@ public function callback(Request $request): RedirectResponse
$oauth_user = $http->get(config('oauth.oauth_user_url'), [
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer ' . $authorize->access_token,
'Authorization' => 'Bearer '.$authorize->access_token,
],
])->getBody();
} catch (GuzzleException) {
@ -119,7 +115,6 @@ public function callback(Request $request): RedirectResponse
}
$oauth_user = json_decode($oauth_user);
$user_sql = (new User)->where('email', $oauth_user->email);
$user = $user_sql->first();
@ -139,7 +134,7 @@ public function callback(Request $request): RedirectResponse
} else {
if ($user->name != $oauth_user->name) {
(new User)->where('email', $oauth_user->email)->update([
'name' => $oauth_user->name
'name' => $oauth_user->name,
]);
}
}

View File

@ -72,7 +72,7 @@ public function show(Request $request, Balance $balance): RedirectResponse|JsonR
$balance->load('user');
$subject = config('app.display_name') . ' 充值';
$subject = config('app.display_name').' 充值';
$order = [
'out_trade_no' => $balance->order_id,
@ -90,18 +90,17 @@ public function show(Request $request, Balance $balance): RedirectResponse|JsonR
$pay = Pay::alipay()->web($order);
return view('balances.alipay', ['html' => (string)$pay->getBody()]);
return view('balances.alipay', ['html' => (string) $pay->getBody()]);
}
if (!isset($qr_code)) {
if (! isset($qr_code)) {
return redirect()->route('index')->with('error', '支付方式错误。');
}
return view('balances.pay', compact('balance', 'qr_code'));
}
private
function xunhu_wechat(
private function xunhu_wechat(
Balance $balance, $subject = '支付'
) {
$data = [
@ -128,7 +127,7 @@ function xunhu_wechat(
$response = Http::post(config('pay.xunhu.gateway'), $data);
if (!$response->successful()) {
if (! $response->successful()) {
return redirect()->route('index')->with('error', '支付网关错误。');
}
@ -136,15 +135,14 @@ function xunhu_wechat(
$hash = $this->xunhu_hash($response);
if (!isset($response['hash']) || $response['hash'] !== $hash) {
if (! isset($response['hash']) || $response['hash'] !== $hash) {
return redirect()->route('index')->with('error', '无法校验支付网关返回数据。');
}
return $response;
}
private
function xunhu_hash(
private function xunhu_hash(
array $arr
): string {
ksort($arr);
@ -167,25 +165,24 @@ function xunhu_hash(
foreach ($pre as $key => $val) {
$arg .= "$key=$val";
if ($index++ < ($qty - 1)) {
$arg .= "&";
$arg .= '&';
}
}
return md5($arg . config('pay.xunhu.app_secret'));
return md5($arg.config('pay.xunhu.app_secret'));
}
/**
* @throws ValidationException
*/
public
function notify(
public function notify(
Request $request, $payment
): View|JsonResponse {
$is_paid = false;
if ($payment === 'alipay') {
$out_trade_no = $request->input('out_trade_no');
} else if ($payment === 'wechat') {
} elseif ($payment === 'wechat') {
$out_trade_no = $request->input('trade_order_id');
} else {
abort(400, '支付方式错误');
@ -193,7 +190,7 @@ function notify(
// 检测订单是否存在
$balance = (new Balance)->where('order_id', $out_trade_no)->with('user')->first();
if (!$balance) {
if (! $balance) {
abort(404, '找不到订单。');
}
@ -208,7 +205,7 @@ function notify(
// 处理验证
if ($payment === 'wechat') {
if (!($request->filled('hash') || $request->filled('trade_order_id'))) {
if (! ($request->filled('hash') || $request->filled('trade_order_id'))) {
return $this->error('参数错误。');
}
@ -229,31 +226,26 @@ function notify(
if ($is_paid) {
// $balance->user->charge($balance->amount, $balance->payment, $balance->order_id);
$balance->update([
'paid_at' => now()
'paid_at' => now(),
]);
}
if ($request->ajax()) {
return $this->success($balance);
}
return view('balances.process', compact('balance'));
}
/**
* 获取交易记录
*
* @param mixed $request
*
* @param mixed $request
* @return View
*/
public
function transactions(
public function transactions(
Request $request
): View {
$modules = Module::all();
$transactions = (new Transaction)->where('user_id', auth('web')->id())->where('payment', '!=', 'module_balance');

View File

@ -21,16 +21,14 @@ public function store(Request $request): RedirectResponse
$realNameSupport = new RealNameSupport();
$birthday = $realNameSupport->getBirthday($request->input('id_card'));
// 检查年龄是否在区间内 settings.supports.real_name.min_age ~ settings.supports.real_name.max_age
if (Carbon::now()->diffInYears($birthday) < config('settings.supports.real_name.min_age') || Carbon::now()->diffInYears($birthday) > config('settings.supports.real_name.max_age')) {
$message = '至少需要 ' . config('settings.supports.real_name.min_age') . ' 岁,最大 ' . config('settings.supports.real_name.max_age') . ' 岁。';
$message = '至少需要 '.config('settings.supports.real_name.min_age').' 岁,最大 '.config('settings.supports.real_name.max_age').' 岁。';
return back()->with('error', $message);
}
$user = $request->user();
if ($user->real_name_verified_at !== null) {
@ -44,14 +42,14 @@ public function store(Request $request): RedirectResponse
$output = $realNameSupport->create($user->id, $request->input('real_name'), $request->input('id_card'));
// 标记用户正在实名,缓存 600s
if (Cache::has('real_name:user:' . $user->id)) {
if (Cache::has('real_name:user:'.$user->id)) {
// 获取缓存
$output = Cache::get('real_name:user:' . $user->id);
$output = Cache::get('real_name:user:'.$user->id);
return back()->with('error', '因为您有一个正在进行的实名认证,请等待 10 分钟后重试。')->with('output', $output);
}
Cache::set('real_name:user:' . $user->id, $output, 600);
Cache::set('real_name:user:'.$user->id, $output, 600);
return redirect($output);
}

View File

@ -26,7 +26,7 @@ public function transfer(Request $request): RedirectResponse
]);
$to = (new User)->where('email', $request->input('to'))->first();
if (!$to) {
if (! $to) {
return back()->withErrors(['to' => '找不到用户。']);
}

View File

@ -13,15 +13,14 @@ class ValidateReferer
/**
* Handle an incoming request.
*
* @param Request $request
* @param Request $request
* @param Closure(Request): (Response|RedirectResponse) $next
*
* @return Response|RedirectResponse
*/
public function handle(Request $request, Closure $next): Response|RedirectResponse
{
// 如果 referer 不为空,且不是来自本站的请求,则返回 403
if ($request->headers->get('referer') && !Str::contains($request->headers->get('referer'), config('app.url'))) {
if ($request->headers->get('referer') && ! Str::contains($request->headers->get('referer'), config('app.url'))) {
abort(403, '来源不属于后台。');
} else {
return $next($request);

View File

@ -10,13 +10,12 @@ class Authenticate extends Middleware
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param Request $request
*
* @param Request $request
* @return string|null
*/
protected function redirectTo($request): ?string
{
if (!$request->expectsJson()) {
if (! $request->expectsJson()) {
return route('index');
}

View File

@ -12,9 +12,8 @@ class JsonResponse
/**
* Handle an incoming request.
*
* @param Request $request
* @param Request $request
* @param Closure(Request): (Response|RedirectResponse) $next
*
* @return Response|RedirectResponse|\Illuminate\Http\JsonResponse
*/
public function handle(Request $request, Closure $next): Response|\Illuminate\Http\JsonResponse|RedirectResponse

View File

@ -14,6 +14,6 @@ class PreventRequestsDuringMaintenance extends Middleware
protected $except = [
// except modules
'admin/*',
'remote/*'
'remote/*',
];
}

View File

@ -16,10 +16,9 @@ class RealNamed
/**
* Handle an incoming request.
*
* @param Request $request
* @param Closure $next
* @param string $guard
*
* @param Request $request
* @param Closure $next
* @param string $guard
* @return Response|RedirectResponse|JsonResponse
*/
public function handle(Request $request, Closure $next, string $guard = 'web'): Response|RedirectResponse|JsonResponse

View File

@ -14,10 +14,9 @@ class RedirectIfAuthenticated
/**
* Handle an incoming request.
*
* @param Request $request
* @param Request $request
* @param Closure(Request): (Response|RedirectResponse) $next
* @param string|null ...$guards
*
* @param string|null ...$guards
* @return Response|RedirectResponse
*/
public function handle(Request $request, Closure $next, ...$guards): Response|RedirectResponse

View File

@ -13,16 +13,17 @@ class ValidateUserIfBanned
/**
* Handle an incoming request.
*
* @param Request $request
* @param Closure $next
*
* @param Request $request
* @param Closure $next
* @return Response|RedirectResponse|JsonResponse
*/
public function handle(Request $request, Closure $next): Response|RedirectResponse|JsonResponse
{
$user = $request->user();
if ($user) if ($user->banned_at !== null) {
return redirect()->route('banned');
if ($user) {
if ($user->banned_at !== null) {
return redirect()->route('banned');
}
}
return $next($request);

View File

@ -1,6 +1,7 @@
<?php
namespace App\Http\Requests;
use Illuminate\Http\Request as HttpRequest;
use Illuminate\Support\Str;
use Symfony\Component\HttpFoundation\ParameterBag;

View File

@ -16,7 +16,7 @@ public function authorize(): bool
{
$host = $this->route('host');
if (!($host instanceof Host)) {
if (! ($host instanceof Host)) {
$host = (new Host)->where('id', $host)->first();
}
@ -25,7 +25,6 @@ public function authorize(): bool
} else {
return false;
}
}
/**

View File

@ -13,7 +13,6 @@ class WorkOrderRequest extends FormRequest
*/
public function authorize(): bool
{
$work_order = $this->route('workOrder');
return $work_order->user_id == auth()->id();

View File

@ -15,6 +15,7 @@ class HostJob implements ShouldQueue
use InteractsWithQueue, Queueable, SerializesModels;
public HostModel $host;
public string $type;
/**
@ -33,6 +34,7 @@ public function __construct(HostModel $host, $type = 'post')
* Execute the job.
*
* @return void
*
* @noinspection PhpUndefinedVariableInspection
*/
public function handle(): void
@ -44,12 +46,11 @@ public function handle(): void
return;
}
$host->load(['module']);
switch ($this->type) {
case 'patch':
$response = $host->module->http()->patch('hosts/' . $host->id, $host->toArray());
$response = $host->module->http()->patch('hosts/'.$host->id, $host->toArray());
break;
case 'post':
@ -57,7 +58,7 @@ public function handle(): void
break;
case 'delete':
$response = $host->module->baseRequest('delete', 'hosts/' . $host->id);
$response = $host->module->baseRequest('delete', 'hosts/'.$host->id);
// if successful
if ($response['status'] === 404) {
@ -68,7 +69,7 @@ public function handle(): void
}
if ($this->type !== 'delete') {
if (!$response->successful()) {
if (! $response->successful()) {
$host->status = 'error';
}

View File

@ -38,7 +38,7 @@ public function handle(): void
$response = $host->module->http()->post('hosts', $host->toArray());
if (!$response->successful()) {
if (! $response->successful()) {
$host->status = 'error';
}
@ -53,7 +53,6 @@ public function handle(): void
}
$host->save();
}
});
}

View File

@ -14,13 +14,14 @@ class RealHostCostJob implements ShouldQueue
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public Host $host;
public string $price;
/**
* Create a new job instance.
*
* @param Host $host
* @param string $price
* @param Host $host
* @param string $price
*/
public function __construct(Host $host, string $price)
{

View File

@ -36,19 +36,18 @@ public function handle(): void
{
$host = $this->host;
$response = $host->module->baseRequest('get', 'hosts/' . $host->id);
$response = $host->module->baseRequest('get', 'hosts/'.$host->id);
if ($response['status'] === 200) {
Log::debug($host->module->name . ' ' . $host->name . ' ' . $host->id . ' 更新成功。', $response['json']);
Log::debug($host->module->name.' '.$host->name.' '.$host->id.' 更新成功。', $response['json']);
$host->update(Arr::except($response['json'], ['id', 'user_id', 'module_id', 'created_at', 'updated_at']));
} else if ($response['status'] === 404) {
} elseif ($response['status'] === 404) {
if ($host->status !== 'unavailable') {
Log::warning($host->module->name . ' ' . $host->name . ' ' . $host->id . ' 不存在,标记为不可用。');
Log::warning($host->module->name.' '.$host->name.' '.$host->id.' 不存在,标记为不可用。');
$host->status = 'unavailable';
$host->save();
}
// dispatch(new HostJob($host, 'delete'));
}
}
}

View File

@ -3,13 +3,10 @@
namespace App\Jobs\Module;
use App\Models\Module;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
class DispatchFetchModuleJob implements ShouldQueue
{

View File

@ -2,7 +2,6 @@
namespace App\Jobs\Module;
use App\Jobs\Host\UpdateOrDeleteHostJob;
use App\Models\Module;
use Exception;
use Illuminate\Bus\Queueable;
@ -17,7 +16,6 @@ class FetchModuleJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected Module $module;
/**
@ -45,6 +43,7 @@ public function handle(): void
$response = $module->http()->get('remote');
} catch (Exception $e) {
Log::error($e->getMessage());
return;
}
@ -68,13 +67,12 @@ public function handle(): void
'module' => [
'id' => $module->id,
'name' => $module->name,
]
],
];
}, $json['servers']));
// broadcast(new Servers($servers));
}
} else {
// if module return maintenance, then set module status to maintenance
$status = $response->status();
@ -89,10 +87,9 @@ public function handle(): void
// if local
if (config('app.env') === 'local') {
Cache::forever('module:' . $module->id . ':servers', $servers);
Cache::forever('module:'.$module->id.':servers', $servers);
} else {
Cache::put('module:' . $module->id . ':servers', $servers, now()->addMinutes(10));
Cache::put('module:'.$module->id.':servers', $servers, now()->addMinutes(10));
}
}
}

View File

@ -31,21 +31,19 @@ public function handle(): void
$this->send($module);
}
});
}
private function send(Module $module): void
{
$data = $module->calculate();
if (!$data) {
if (! $data) {
return;
}
// make wecom_key visible
$wecom_key = $module->wecom_key ?? config('settings.wecom.robot_hook.billing');
$text = "# $module->name 收益";
foreach ($data as $year => $months) {
// 排序 months 从小到大
@ -68,15 +66,13 @@ private function send(Module $module): void
}
}
$resp = Http::post('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=' . $wecom_key, [
$resp = Http::post('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key='.$wecom_key, [
'msgtype' => 'markdown',
'markdown' => [
'content' => $text,
],
]);
if ($resp->failed()) {
Log::error('发送模块盈利到企业微信时失败', [
'module' => $module->id,

View File

@ -15,7 +15,10 @@ class EMQXKickClientJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected string|null $client_id, $username;
protected string|null $client_id;
protected string|null $username;
protected bool $like_username;
/**
@ -40,7 +43,7 @@ public function handle(): void
$emqx = new EmqxSupport();
if ($this->client_id) {
$emqx->api()->delete('/clients/' . $this->client_id);
$emqx->api()->delete('/clients/'.$this->client_id);
}
if ($this->username) {
@ -53,10 +56,10 @@ public function handle(): void
$clients = $emqx->clients([$query => $this->username]);
} catch (EmqxSupportException $e) {
Log::error('emqx connect failed.', [$e]);
return;
}
if ($clients) {
if (count($clients['data']) > 0) {
foreach ($clients['data'] as $client) {
@ -65,7 +68,6 @@ public function handle(): void
dispatch(new self(null, $this->username, $this->like_username));
}
}
}
}

View File

@ -31,7 +31,7 @@ public function handle(): void
{
(new Balance)->where('paid_at', null)->chunk(100, function ($balances) {
foreach ($balances as $balance) {
if (!$this->checkAndCharge($balance, true)) {
if (! $this->checkAndCharge($balance, true)) {
if (now()->diffInDays($balance->created_at) > 1) {
$balance->delete();
}
@ -44,7 +44,6 @@ public function handle(): void
public function checkAndCharge(Balance $balance, $check = false): bool
{
if ($check) {
try {
$alipay = Pay::alipay()->find(['out_trade_no' => $balance->order_id]);
@ -62,7 +61,7 @@ public function checkAndCharge(Balance $balance, $check = false): bool
}
$balance->update([
'paid_at' => now()
'paid_at' => now(),
]);
return true;

View File

@ -17,8 +17,13 @@ class SendUserNotificationsJob implements ShouldQueue
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected array $requests;
protected User|CachedBuilder $users;
protected string $title, $content;
protected string $title;
protected string $content;
protected bool $send_mail;
/**

View File

@ -34,7 +34,7 @@ public function handle(): void
{
$birthday_group = (new UserGroup)->find(config('settings.user_groups.birthday_group_id'));
if (!$birthday_group) {
if (! $birthday_group) {
return;
}

View File

@ -57,7 +57,7 @@ public function handle(): void
try {
$response = $workOrder->module->http()->retry(3, 100)->post('work-orders', $workOrder->toArray());
if (!$response->successful()) {
if (! $response->successful()) {
Log::warning('推送工单失败', [
'work_order_id' => $workOrder->id,
'response' => $response->body(),
@ -69,13 +69,11 @@ public function handle(): void
Log::warning($e->getMessage());
}
if (!$success) {
if (! $success) {
$workOrder->status = 'error';
}
$workOrder->save();
}
});
@ -84,6 +82,5 @@ public function handle(): void
dispatch(new Reply($reply));
}
});
}
}

View File

@ -13,6 +13,7 @@ class Reply implements ShouldQueue
use InteractsWithQueue, Queueable, SerializesModels;
protected WorkOrderReply $reply;
protected string $type;
/**
@ -46,32 +47,30 @@ public function handle(): void
$reply = $this->reply->toArray();
if ($this->type == 'post') {
$response = $this->reply->workOrder->module->http()->post('work-orders/' . $this->reply->workOrder->id . '/replies', $reply);
$response = $this->reply->workOrder->module->http()->post('work-orders/'.$this->reply->workOrder->id.'/replies', $reply);
if ($response->successful()) {
$this->reply->update([
'is_pending' => false
'is_pending' => false,
]);
} else {
$this->reply->update([
'is_pending' => true
'is_pending' => true,
]);
}
} else if ($this->type == 'patch') {
} elseif ($this->type == 'patch') {
// 不更新 is_pending
if ($this->reply->workOrder->isPlatform()) {
$this->reply->update([
'is_pending' => false
'is_pending' => false,
]);
return;
}
$this->reply->workOrder->module->http()->patch('work-orders/' . $this->reply->workOrder->id . '/replies/' . $this->reply->id, $reply);
} else if ($this->type == 'delete') {
$response = $this->reply->workOrder->module->http()->delete('work-orders/' . $this->reply->workOrder->id . '/replies/' . $this->reply->id);
$this->reply->workOrder->module->http()->patch('work-orders/'.$this->reply->workOrder->id.'/replies/'.$this->reply->id, $reply);
} elseif ($this->type == 'delete') {
$response = $this->reply->workOrder->module->http()->delete('work-orders/'.$this->reply->workOrder->id.'/replies/'.$this->reply->id);
if ($response->successful()) {
$this->reply->delete();
@ -79,4 +78,3 @@ public function handle(): void
}
}
}

View File

@ -16,6 +16,7 @@ class WorkOrder implements ShouldQueue
use InteractsWithQueue, Queueable, SerializesModels;
protected WorkOrderModel $workOrder;
protected string $type;
/**
@ -44,20 +45,19 @@ public function handle(): void
$this->type = 'post';
}
if ($this->type == 'post') {
$response = $this->workOrder->module->http()->post('work-orders', $this->workOrder->toArray());
} else if ($this->type == 'put') {
$response = $this->workOrder->module->http()->put('work-orders/' . $this->workOrder->id, $this->workOrder->toArray());
} elseif ($this->type == 'put') {
$response = $this->workOrder->module->http()->put('work-orders/'.$this->workOrder->id, $this->workOrder->toArray());
} else {
$response = $this->workOrder->module->http()->delete('work-orders/' . $this->workOrder->id);
$response = $this->workOrder->module->http()->delete('work-orders/'.$this->workOrder->id);
if ($response->successful()) {
$this->workOrder->delete();
}
}
if (!$response->successful()) {
if (! $response->successful()) {
Log::debug('WorkOrder push failed', [
'type' => $this->type,
'response' => $response->json(),
@ -65,7 +65,7 @@ public function handle(): void
]);
$this->workOrder->update([
'status' => 'error'
'status' => 'error',
]);
}
}

View File

@ -4,11 +4,11 @@
use App\Events\Users;
use App\Notifications\User\UserCharged;
use function auth;
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo as BelongsToAlias;
use Illuminate\Notifications\Notifiable;
use function auth;
class Balance extends Model
{
@ -20,7 +20,7 @@ class Balance extends Model
'amount',
'user_id',
'paid_at',
'trade_id'
'trade_id',
];
protected $casts = [
@ -36,7 +36,7 @@ protected static function boot()
// $balance->remaining_amount = $balance->amount;
$balance->remaining_amount = 0;
$balance->order_id = date('YmdHis') . $balance->id . rand(1000, 9999);
$balance->order_id = date('YmdHis').$balance->id.rand(1000, 9999);
});
static::created(function (self $balance) {
@ -67,7 +67,7 @@ public function scopeThisUser($query)
public function canPay(): bool
{
return !$this->isPaid() && !$this->isOverdue();
return ! $this->isPaid() && ! $this->isOverdue();
}
public function isPaid(): bool
@ -77,6 +77,6 @@ public function isPaid(): bool
public function isOverdue(): bool
{
return $this->created_at->diffInDays(now()) > 1 && !$this->isPaid();
return $this->created_at->diffInDays(now()) > 1 && ! $this->isPaid();
}
}

View File

@ -57,7 +57,6 @@ protected static function boot()
$model->user->notify(new WebNotification($model, 'hosts.created'));
});
static::updating(function (self $model) {
if ($model->isDirty('status')) {
if ($model->status == 'suspended') {
@ -98,13 +97,13 @@ protected static function boot()
// });
static::deleting(function ($model) {
Cache::forget('user_tasks_' . $model->user_id);
Cache::forget('user_tasks_'.$model->user_id);
});
static::deleted(function ($model) {
broadcast(new Users($model->user_id, 'hosts.deleted', $model));
Cache::forget('user_tasks_' . $model->user_id);
Cache::forget('user_hosts_' . $model->user_id);
Cache::forget('user_tasks_'.$model->user_id);
Cache::forget('user_hosts_'.$model->user_id);
});
}
@ -131,7 +130,6 @@ public function module(): BelongsToAlias
// return $this->hasMany(WorkOrder::class);
// }
public function getPrice(): float
{
return $this->managed_price ?? $this->price;
@ -162,6 +160,7 @@ public function safeDelete(): bool
}
dispatch(new HostJob($this, 'delete'));
return true;
}
@ -180,7 +179,7 @@ public function cost(string $amount = null, $auto = true): bool
$real_price = $amount ?? $this->price;
if (!$amount) {
if (! $amount) {
if ($this->managed_price) {
$real_price = $this->managed_price;
}
@ -189,9 +188,9 @@ public function cost(string $amount = null, $auto = true): bool
$append_description = '';
if ($user_group) {
if ($user_group->discount !== 100 && $user_group->discount !== null) {
$real_price = bcmul($real_price, bcdiv($user_group->discount, "100", 4), 4);
$real_price = bcmul($real_price, bcdiv($user_group->discount, '100', 4), 4);
$append_description = ' (折扣 ' . $user_group->discount . '%)';
$append_description = ' (折扣 '.$user_group->discount.'%)';
}
}
@ -206,6 +205,7 @@ public function cost(string $amount = null, $auto = true): bool
if ($real_price == 0) {
echo '价格为 0不扣费';
return true;
}
@ -218,7 +218,7 @@ public function cost(string $amount = null, $auto = true): bool
$month = now()->month;
$month_cache_key = 'user_' . $this->user_id . '_month_' . $month . '_hosts_balances';
$month_cache_key = 'user_'.$this->user_id.'_month_'.$month.'_hosts_balances';
$hosts_balances = Cache::get($month_cache_key, []);
// 统计 Host 消耗的 Balance
@ -262,9 +262,9 @@ public function cost(string $amount = null, $auto = true): bool
return true;
}
public function addLog(string $amount = "0"): bool
public function addLog(string $amount = '0'): bool
{
if ($amount === "0") {
if ($amount === '0') {
return false;
}
@ -272,7 +272,7 @@ public function addLog(string $amount = "0"): bool
$current_month = now()->month;
$current_year = now()->year;
$cache_key = 'module_earning_' . $this->module_id;
$cache_key = 'module_earning_'.$this->module_id;
// 应支付的提成
$commission = config('billing.commission');
@ -287,7 +287,7 @@ public function addLog(string $amount = "0"): bool
$earnings = Cache::get($cache_key, []);
if (!isset($earnings[$current_year])) {
if (! isset($earnings[$current_year])) {
$earnings[$current_year] = [];
}

View File

@ -21,19 +21,20 @@ class Module extends Authenticatable
public $incrementing = false;
protected $table = 'modules';
protected $keyType = 'string';
protected $fillable = [
'id',
'name',
'api_token'
'api_token',
];
protected $hidden = [
'api_token',
'wecom_key',
'balance',
'url'
'url',
];
protected $casts = [
@ -45,7 +46,7 @@ protected static function boot()
{
parent::boot();
static::creating(function (self $model) {
if (!app()->environment('local')) {
if (! app()->environment('local')) {
$model->api_token = Str::random(60);
}
@ -66,18 +67,17 @@ protected static function boot()
// return $this->getResponse($response);
// }
// post, get, patch, delete 等请求
public function remote($func, $requests): array
{
$response = $this->http()->post('functions/' . $func, $requests);
$response = $this->http()->post('functions/'.$func, $requests);
return $this->getResponse($response);
}
public function http(): PendingRequest
{
return Http::module($this->api_token, $this->url . '/remote')->acceptJson()->timeout(5);
return Http::module($this->api_token, $this->url.'/remote')->acceptJson()->timeout(5);
}
private function getResponse(Response $response): array
@ -141,7 +141,7 @@ public function moduleRequest($method, $path, $requests): array
$module_id = auth('module')->id();
$http = $this->http()->withHeaders([
'X-Module' => $module_id
'X-Module' => $module_id,
]);
$requests['module_id'] = $module_id;
@ -175,31 +175,30 @@ public function check(): bool
return $success;
}
#[ArrayShape(['transactions' => "array"])]
#[ArrayShape(['transactions' => 'array'])]
public function calculate(): array
{
$cache_key = 'module_earning_' . $this->id;
$cache_key = 'module_earning_'.$this->id;
return Cache::get($cache_key, []);
}
/**
* 扣除费用
*
* @param string|null $amount
* @param string|null $description
* @param bool $fail
* @param array $options
*
* @param string|null $amount
* @param string|null $description
* @param bool $fail
* @param array $options
* @return string
*/
public function reduce(string|null $amount = "0", string|null $description = "消费", bool $fail = false, array $options = []): string
public function reduce(string|null $amount = '0', string|null $description = '消费', bool $fail = false, array $options = []): string
{
if ($amount === null || $amount === '') {
return $this->balance;
}
Cache::lock('module_balance_' . $this->id, 10)->block(10, function () use ($amount, $fail, $description, $options) {
Cache::lock('module_balance_'.$this->id, 10)->block(10, function () use ($amount, $fail, $description, $options) {
$this->refresh();
if ($this->balance < $amount) {
@ -225,9 +224,7 @@ public function reduce(string|null $amount = "0", string|null $description = "
}
(new Transaction)->create($data);
}
});
return $this->balance;
@ -236,20 +233,19 @@ public function reduce(string|null $amount = "0", string|null $description = "
/**
* 增加余额
*
* @param string|null $amount
* @param string $payment
* @param string|null $description
* @param array $options
*
* @param string|null $amount
* @param string $payment
* @param string|null $description
* @param array $options
* @return string
*/
public function charge(string|null $amount = "0", string $payment = 'console', string|null $description = '充值', array $options = []): string
public function charge(string|null $amount = '0', string $payment = 'console', string|null $description = '充值', array $options = []): string
{
if ($amount === null || $amount === '') {
return $this->balance;
}
Cache::lock('module_balance_' . $this->id, 10)->block(10, function () use ($amount, $description, $payment, $options) {
Cache::lock('module_balance_'.$this->id, 10)->block(10, function () use ($amount, $description, $payment, $options) {
$this->refresh();
$this->balance = bcadd($this->balance, $amount, 4);
@ -271,8 +267,6 @@ public function charge(string|null $amount = "0", string $payment = 'console', s
(new Transaction)->create($data);
}
});
return $this->balance;

View File

@ -16,17 +16,17 @@ class PersonalAccessToken extends SanctumPersonalAccessToken
* the last_used_at column that has changed. It prevents extra DB writes
* since we aren't going to use that column for anything.
*
* @param array $options
*
* @param array $options
* @return bool
*/
public function save(array $options = []): bool
{
$changes = $this->getDirty();
// Check for 2 changed values because one is always the updated_at column
if (!array_key_exists('last_used_at', $changes) || count($changes) > 2) {
if (! array_key_exists('last_used_at', $changes) || count($changes) > 2) {
parent::save();
}
return false;
}
}

View File

@ -4,21 +4,23 @@
use App\Events\Users;
use App\Exceptions\CommonException;
use function auth;
use function broadcast;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Ramsey\Uuid\Uuid;
use function auth;
use function broadcast;
class Task extends Model
{
public $incrementing = false;
protected $fillable = [
'host_id',
'title',
'progress',
'status',
];
protected $casts = [
'id' => 'string',
'progress' => 'integer',
@ -40,7 +42,7 @@ protected static function boot()
}
// host_id 和 user_id 至少存在一个
if (!$model->host_id && !$model->user_id) {
if (! $model->host_id && ! $model->user_id) {
throw new CommonException('host_id 和 user_id 至少存在一个');
}
@ -75,7 +77,6 @@ protected static function boot()
broadcast(new Users($model->user_id, 'tasks.updated', $model));
});
static::deleted(function (self $model) {
broadcast(new Users($model->user_id, 'tasks.deleted', $model));
});

View File

@ -8,10 +8,12 @@
class Transaction extends Model
{
const UPDATED_AT = null;
protected $connection = 'mongodb';
// 停用 updated_at
protected $collection = 'transactions';
protected $dates = [
'created_at',
'updated_at',

View File

@ -23,6 +23,14 @@ class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable, Cachable;
public array $publics = [
'id',
'name',
'email',
'real_name',
'balance',
];
/**
* The attributes that are mass assignable.
*
@ -52,7 +60,7 @@ class User extends Authenticatable
'real_name_verified_at' => 'datetime',
'balance' => 'decimal:4',
'banned_at' => 'datetime',
'birthday_at' => 'date:Y-m-d'
'birthday_at' => 'date:Y-m-d',
];
protected $dates = [
@ -62,14 +70,6 @@ class User extends Authenticatable
'birthday_at',
];
public array $publics = [
'id',
'name',
'email',
'real_name',
'balance',
];
protected static function boot()
{
parent::boot();
@ -96,19 +96,20 @@ protected static function boot()
$user->id_card = Crypt::encryptString($user->id_card);
}
if ($user->isDirty('id_card') || $user->isDirty('real_name')) if (empty($user->id_card) || empty($user->real_name)) {
$user->real_name_verified_at = null;
} else {
$user->real_name_verified_at = now();
if ($user->isDirty('id_card') || $user->isDirty('real_name')) {
if (empty($user->id_card) || empty($user->real_name)) {
$user->real_name_verified_at = null;
} else {
$user->real_name_verified_at = now();
// 更新生日
try {
$user->birthday_at = $user->getBirthdayFromIdCard();
} catch (InvalidFormatException) {
$user->birthday_at = null;
// 更新生日
try {
$user->birthday_at = $user->getBirthdayFromIdCard();
} catch (InvalidFormatException) {
$user->birthday_at = null;
}
}
}
});
}
@ -122,14 +123,14 @@ private function getBirthdayFromIdCard(): string
$idCard = $this->id_card;
$bir = substr($idCard, 6, 8);
$year = (int)substr($bir, 0, 4);
$month = (int)substr($bir, 4, 2);
$day = (int)substr($bir, 6, 2);
$year = (int) substr($bir, 0, 4);
$month = (int) substr($bir, 4, 2);
$day = (int) substr($bir, 6, 2);
return $year . '-' . $month . '-' . $day;
return $year.'-'.$month.'-'.$day;
}
public function hasBalance(string $amount = "0.01"): bool
public function hasBalance(string $amount = '0.01'): bool
{
return bccomp($this->balance, $amount, 4) >= 0;
}
@ -183,20 +184,19 @@ public function startTransfer(self $to, string $amount, string|null $description
/**
* 扣除费用
*
* @param string|null $amount
* @param string $description
* @param bool $fail
* @param array $options
*
* @param string|null $amount
* @param string $description
* @param bool $fail
* @param array $options
* @return string
*/
public function reduce(string|null $amount = "0", string $description = "消费", bool $fail = false, array $options = []): string
public function reduce(string|null $amount = '0', string $description = '消费', bool $fail = false, array $options = []): string
{
if ($amount === null || $amount === '') {
return $this->balance;
}
Cache::lock('user_balance_' . $this->id, 10)->block(10, function () use ($amount, $fail, $description, $options) {
Cache::lock('user_balance_'.$this->id, 10)->block(10, function () use ($amount, $fail, $description, $options) {
$this->refresh();
if ($this->balance < $amount) {
@ -229,20 +229,19 @@ public function reduce(string|null $amount = "0", string $description = "消费"
/**
* 增加余额
*
* @param string|null $amount
* @param string $payment
* @param string $description
* @param array $options
*
* @param string|null $amount
* @param string $payment
* @param string $description
* @param array $options
* @return string
*/
public function charge(string|null $amount = "0", string $payment = 'console', string $description = '充值', array $options = []): string
public function charge(string|null $amount = '0', string $payment = 'console', string $description = '充值', array $options = []): string
{
if ($amount === null || $amount === '') {
return $this->balance;
}
Cache::lock('user_balance_' . $this->id, 10)->block(10, function () use ($amount, $description, $payment, $options) {
Cache::lock('user_balance_'.$this->id, 10)->block(10, function () use ($amount, $description, $payment, $options) {
$this->refresh();
$this->balance = bcadd($this->balance, $amount, 4);
$this->save();

View File

@ -29,14 +29,12 @@ public function users(): HasMany
return $this->hasMany(User::class);
}
/**
* 设置临时用户组
*
* @param User $user
* @param UserGroup $group
* @param Carbon $expired_at
*
* @param User $user
* @param UserGroup $group
* @param Carbon $expired_at
* @return User
*/
public function setTempGroup(User $user, self $group, Carbon $expired_at): User
@ -62,5 +60,4 @@ public function setTempGroup(User $user, self $group, Carbon $expired_at): User
return $user;
}
}

View File

@ -23,7 +23,7 @@ class Reply extends Model
'name',
'module_id',
'is_pending',
'role'
'role',
];
protected $hidden = [
@ -46,24 +46,20 @@ protected static function boot()
throw_if($model->workOrder->isFailure(), CommonException::class, '工单还没有就绪。');
// change work order status
if (auth('admin')->check()) {
$model->role = 'admin';
$model->workOrder->status = 'replied';
} else if (auth('sanctum')->check()) {
} elseif (auth('sanctum')->check()) {
$model->user_id = auth('sanctum')->id();
$model->role = 'user';
$model->workOrder->status = 'user_replied';
} else if (auth('module')->check()) {
} elseif (auth('module')->check()) {
$model->user_id = null;
$model->role = 'module';
$model->workOrder->status = 'replied';
broadcast(new Users($model->user, 'work-order.replied', $model->workOrder));
} else {
$model->role = 'guest';
}

View File

@ -28,7 +28,7 @@ class WorkOrder extends Model
'user_id',
'module_id',
'status',
'notify'
'notify',
];
protected $hidden = [
@ -36,7 +36,7 @@ class WorkOrder extends Model
];
protected $casts = [
'notify' => 'boolean'
'notify' => 'boolean',
];
protected static function boot()
@ -55,12 +55,12 @@ protected static function boot()
$model->user_id = auth()->id();
if ($model->host_id) {
if (!$model->user_id == $model->host->user_id) {
if (! $model->user_id == $model->host->user_id) {
throw new CommonException('user_id not match host user_id');
}
}
} else {
if (!$model->user_id) {
if (! $model->user_id) {
throw new CommonException('user_id is required');
}
}

View File

@ -14,27 +14,26 @@ class WeComChannel extends Notification
/**
* Send the given notification.
*
* @param mixed $notifiable
* @param Notification $notification
*
* @param mixed $notifiable
* @param Notification $notification
* @return void
*/
public function send(mixed $notifiable, Notification $notification): void
{
$data = $notification->toWeCom($notifiable);
if (!$data) {
if (! $data) {
return;
}
$view = $data['view'];
$key = $data['wecom_key'] ?? null;
if (!$key) {
if (! $key) {
$key = config('settings.wecom.robot_hook.default');
}
$resp = Http::post('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=' . $key, [
$resp = Http::post('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key='.$key, [
'msgtype' => 'markdown',
'markdown' => [
'content' => view($view, [
@ -43,7 +42,7 @@ public function send(mixed $notifiable, Notification $notification): void
],
]);
if (!$resp->successful()) {
if (! $resp->successful()) {
Log::error('企业微信机器人发送失败', $data['data']);
}
}

View File

@ -14,16 +14,15 @@ class WebChannel extends Notification
/**
* Send the given notification.
*
* @param mixed $notifiable
* @param Notification $notification
*
* @param mixed $notifiable
* @param Notification $notification
* @return void
*/
public function send(mixed $notifiable, Notification $notification): void
{
$data = $notification->toArray($notifiable);
if (!$data) {
if (! $data) {
return;
}

View File

@ -43,24 +43,23 @@ public function toMail(): MailMessage
{
$url = URL::format(config('settings.dashboard.base_url'), config('settings.dashboard.birthday_path'));
$lyrics = [
[
"Happy Birthday",
"好想把我的心意传达给你。"
'Happy Birthday',
'好想把我的心意传达给你。',
],
[
'今天祝你生日快乐!',
'这是第几次呢 假装忘记了(实际上)。',
'心里很清楚 只是在装傻。'
'心里很清楚 只是在装傻。',
],
[
'今天祝你生日快乐!',
'蛋糕上的蜡烛要立几根好呢。连备用的都一起买好了!'
'蛋糕上的蜡烛要立几根好呢。连备用的都一起买好了!',
],
[
'Happy Birthday!',
'人与人的相遇真是不可思议。'
'人与人的相遇真是不可思议。',
],
[
'你知道吗?',
@ -68,7 +67,7 @@ public function toMail(): MailMessage
'会不会太迟了呢?我喜欢你,还会更喜欢你。',
],
[
'即使以心传心但也一定有着极限的。所以要好好地说出来。'
'即使以心传心但也一定有着极限的。所以要好好地说出来。',
],
];
@ -85,7 +84,7 @@ public function toMail(): MailMessage
$email->line('生日快乐🎂')
->line('在生日当天,我们还为您提供了专属用户组,您可以前往仪表盘查看。')
->action('前往仪表盘', $url)
->line('感谢您继续使用 ' . config('app.display_name') . '。');
->line('感谢您继续使用 '.config('app.display_name').'。');
return $email;
}

View File

@ -47,8 +47,7 @@ public function toWeCom(Balance $notifiable): array
'data' => [
'user' => $user,
'balance' => $notifiable,
]
],
];
}
}

View File

@ -13,7 +13,9 @@ class UserNotification extends Notification implements ShouldQueue
use Queueable;
public string $title;
public string $content;
public bool $send_mail;
/**

View File

@ -30,8 +30,7 @@ public function __construct(WorkOrderModel $work_order)
* Get the notification's delivery channels.
*
*
* @param WorkOrderModel $workOrder
*
* @param WorkOrderModel $workOrder
* @return array
*/
public function via(WorkOrderModel $workOrder): array
@ -49,14 +48,13 @@ public function via(WorkOrderModel $workOrder): array
* Get the mail representation of the notification.
*
*
* @param WorkOrderModel $workOrder
*
* @param WorkOrderModel $workOrder
* @return MailMessage
*/
public function toMail(WorkOrderModel $workOrder): MailMessage
{
return (new MailMessage)
->subject('工单: ' . $workOrder->title . ' 状态更新。')
->subject('工单: '.$workOrder->title.' 状态更新。')
->line('我们查阅了您的工单并做出了相应处理。')
->line('请前往我们的仪表盘继续跟进问题。');
}
@ -65,15 +63,14 @@ public function toMail(WorkOrderModel $workOrder): MailMessage
* Get the array representation of the notification.
*
*
* @param WorkOrderModel $workOrder
*
* @param WorkOrderModel $workOrder
* @return array
*/
public function toArray(WorkOrderModel $workOrder): array
{
$array = $workOrder->toArray();
$array['event'] = 'work-order.' . $workOrder->status;
$array['event'] = 'work-order.'.$workOrder->status;
return $array;
}
@ -88,7 +85,6 @@ public function toWeCom(WorkOrderModel $workOrder): false|array
// 取消隐藏字段
$module->makeVisible(['wecom_key']);
}
if ($module?->wecom_key == null) {
@ -100,7 +96,7 @@ public function toWeCom(WorkOrderModel $workOrder): false|array
return [
'key' => $wecom_key,
'view' => 'notifications.work_order',
'data' => $workOrder
'data' => $workOrder,
];
}
@ -108,5 +104,4 @@ public function toWeCom(WorkOrderModel $workOrder): false|array
// {
// return new BroadcastMessage($workOrder->toArray());
// }
}

View File

@ -15,9 +15,8 @@ class WorkOrderPolicy
/**
* Determine whether the user can view the model.
*
* @param User|Module $user
* @param WorkOrder $workOrder
*
* @param User|Module $user
* @param WorkOrder $workOrder
* @return Response|bool
*/
public function view(User|Module $user, WorkOrder $workOrder): Response|bool
@ -32,9 +31,8 @@ public function view(User|Module $user, WorkOrder $workOrder): Response|bool
/**
* Determine whether the user can update the model.
*
* @param User|Module $user
* @param WorkOrder $workOrder
*
* @param User|Module $user
* @param WorkOrder $workOrder
* @return Response|bool
*/
public function update(User|Module $user, WorkOrder $workOrder): Response|bool
@ -49,9 +47,8 @@ public function update(User|Module $user, WorkOrder $workOrder): Response|bool
/**
* Determine whether the user can delete the model.
*
* @param User|Module $user
* @param WorkOrder $workOrder
*
* @param User|Module $user
* @param WorkOrder $workOrder
* @return Response|bool
*/
public function delete(User|Module $user, WorkOrder $workOrder): Response|bool

View File

@ -18,7 +18,6 @@ class AppServiceProvider extends ServiceProvider
public function register(): void
{
//
}
/**
@ -45,9 +44,7 @@ public function boot(): void
]);
});
// Carbon setTestNow
// Carbon::setTestNow(now()->addDays(1));
}
}

View File

@ -6,7 +6,6 @@
class ClusterSupport
{
public static string $prefix = 'cluster:';
public static function isCluster(): bool
@ -61,14 +60,13 @@ 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));
Redis::hset(self::$prefix.$key, $value, json_encode($data));
}
/**
* @param string|array $events 事件名称
* @param $callback callable 回调函数,接收一个参数,为事件数据。
* @param $ignore_self bool 是否忽略此节点的消息。
*
* @param string|array $events 事件名称
* @param $callback callable 回调函数,接收一个参数,为事件数据。
* @param $ignore_self bool 是否忽略此节点的消息。
* @return void
*/
public static function listen(string|array $events, callable $callback, bool $ignore_self = true): void
@ -98,13 +96,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);
return Redis::get(self::$prefix.$key, $default);
}
public static function forget($key): void
{
/** @noinspection PhpUndefinedMethodInspection */
Redis::forget(self::$prefix . $key);
Redis::forget(self::$prefix.$key);
}
// forever
@ -116,13 +114,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);
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);
$value = Redis::hget(self::$prefix.$key, $hashKey);
return $value ?: $default;
}
@ -145,7 +143,7 @@ public static function nodes($hide_ip = false): array
public static function hgetAll($hashKey, $default = []): array
{
/** @noinspection PhpUndefinedMethodInspection */
$value = Redis::hgetall(self::$prefix . $hashKey);
$value = Redis::hgetall(self::$prefix.$hashKey);
return $value ?: $default;
}

Some files were not shown because too many files have changed in this diff Show More