格式化与整理代码

This commit is contained in:
iVampireSP.com 2023-02-13 03:12:26 +08:00
parent 089f97ff79
commit f974d3f0f3
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
9 changed files with 76 additions and 76 deletions

View File

@ -112,6 +112,18 @@ private function handleIncomingRequest(array $message): string
return $msg;
}
private function appendUser(array $message): string
{
$msg = '';
if ($message['user']) {
$msg .= "{$message['user']['name']}#{$message['user']['id']} ";
} else {
$msg .= 'Guest ';
}
return $msg;
}
private function handleOutgoingRequest(array $message): string
{
$msg = $this->appendUser($message);
@ -132,16 +144,4 @@ private function handleWeightUpdated(array $message): string
return $msg;
}
private function appendUser(array $message): string
{
$msg = '';
if ($message['user']) {
$msg .= "{$message['user']['name']}#{$message['user']['id']} ";
} else {
$msg .= 'Guest ';
}
return $msg;
}
}

View File

@ -7,6 +7,7 @@
use App\Support\ClusterSupport;
use Illuminate\Contracts\View\View;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
use Symfony\Component\HttpFoundation\StreamedResponse;
@ -45,7 +46,7 @@ public function update(Request $request, string $node): JsonResponse
return $this->success('Updated');
}
public function event(Request $request): \Illuminate\Http\RedirectResponse
public function event(Request $request): RedirectResponse
{
$request->validate([
'restart' => 'nullable|string|max:10|in:web,queue',

View File

@ -23,15 +23,6 @@ public function verify(Request $request): JsonResponse
: $this->failed();
}
public function process(Request $request): View
{
Log::debug('实名认证回调', $request->all());
return $this->validateOrSave($request)
? view('real_name.success')
: view('real_name.failed');
}
public function validateOrSave(Request $request): bool
{
Log::debug('实名认证回调', $request->all());
@ -64,4 +55,13 @@ public function validateOrSave(Request $request): bool
return true;
}
public function process(Request $request): View
{
Log::debug('实名认证回调', $request->all());
return $this->validateOrSave($request)
? view('real_name.success')
: view('real_name.failed');
}
}

View File

@ -37,7 +37,6 @@ public function renew(Host $host): RedirectResponse
return back()->with('success', '续费成功,新的到期时间为:'.$host->next_due_at.'。');
}
return back()->with('error', '续费失败,请检查是否有足够的余额。');
}
@ -45,7 +44,6 @@ public function renew(Host $host): RedirectResponse
* Remove the specified resource from storage.
*
* @param Host $host
*
* @return RedirectResponse
*/
public function destroy(Host $host): RedirectResponse

View File

@ -110,11 +110,6 @@ public function isStopped(): bool
return $this->status === 'stopped';
}
public function isSuspended(): bool
{
return $this->status === 'suspended';
}
public function renew(): bool
{
if (! $this->isCycle()) {
@ -240,6 +235,20 @@ public function getNewDueDate(): string
};
}
public function isSuspended(): bool
{
return $this->status === 'suspended';
}
public function run(): bool
{
$this->update([
'status' => 'running',
]);
return true;
}
public function isOverdue(): bool
{
return now()->gt($this->next_due_at);
@ -373,13 +382,4 @@ public function suspend(): bool
return true;
}
public function run(): bool
{
$this->update([
'status' => 'running',
]);
return true;
}
}

View File

@ -163,17 +163,6 @@ public function startTransfer(self $to, string $amount, string|null $description
return $this->balance;
}
public function getCostPrice(string $price): string
{
$this->load('user_group');
if (! $this->user_group) {
return $price;
}
return $this->user_group->getCostPrice($price);
}
/**
* 扣除费用
*
@ -269,6 +258,17 @@ public function charge(string|null $amount = '0', string $payment = 'console', s
return $this->balance;
}
public function getCostPrice(string $price): string
{
$this->load('user_group');
if (! $this->user_group) {
return $price;
}
return $this->user_group->getCostPrice($price);
}
/**
* 获取用户的身份证号
*

View File

@ -79,9 +79,12 @@ public static function update($node_id, $data = []): void
ClusterSupport::hset('nodes', $node_id, $node);
}
public static function removeNode($node_id): void
public static function hget($key, $hashKey, $default = []): string|array|null
{
self::hdel('nodes', $node_id);
/** @noinspection PhpUndefinedMethodInspection */
$value = Redis::hget(self::$prefix.$key, $hashKey);
return $value ?: $default;
}
public static function hset($key, $value, $data = []): void
@ -90,6 +93,11 @@ public static function hset($key, $value, $data = []): void
Redis::hset(self::$prefix.$key, $value, json_encode($data));
}
public static function removeNode($node_id): void
{
self::hdel('nodes', $node_id);
}
public static function hdel($key, $hash_key): void
{
/** @noinspection PhpUndefinedMethodInspection */
@ -133,13 +141,14 @@ public static function get($key, $default = null): string|array|null
return Redis::get(self::$prefix.$key, $default);
}
// forever
public static function forget($key): void
{
/** @noinspection PhpUndefinedMethodInspection */
Redis::forget(self::$prefix.$key);
}
// forever
public static function forever($key, $value): void
{
self::set($key, $value, -1);
@ -151,14 +160,6 @@ public static function set($key, $value, $ttl = null): void
Redis::set(self::$prefix.$key, $value, $ttl);
}
public static function hget($key, $hashKey, $default = []): string|array|null
{
/** @noinspection PhpUndefinedMethodInspection */
$value = Redis::hget(self::$prefix.$key, $hashKey);
return $value ?: $default;
}
public static function nodes($hide_ip = false, $type = 'all'): array
{
$nodes = self::hgetAll('nodes');