整理函数 & 格式化代码

This commit is contained in:
iVampireSP.com 2023-02-13 15:33:37 +08:00
parent 10a7df704c
commit 85c4f22ed4
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
5 changed files with 34 additions and 45 deletions

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
@ -55,8 +54,7 @@ public function create(): View
/**
* Display the specified resource.
*
* @param Application $application
*
* @param Application $application
* @return RedirectResponse
*/
public function show(Application $application): RedirectResponse
@ -67,8 +65,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
@ -79,9 +76,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
@ -89,7 +85,7 @@ public function update(Request $request, Application $application): RedirectResp
$request->validate([
'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());
@ -100,8 +96,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

@ -17,8 +17,7 @@ class TaskController extends Controller
/**
* Display a listing of the resource.
*
* @param Request $request
*
* @param Request $request
* @return JsonResponse
*/
public function index(Request $request): JsonResponse
@ -31,8 +30,7 @@ public function index(Request $request): JsonResponse
/**
* Store a newly created resource in storage.
*
* @param Request $request
*
* @param Request $request
* @return JsonResponse
*
* @throws ValidationException
@ -53,9 +51,8 @@ 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

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);

View File

@ -55,7 +55,7 @@ public function handle(): void
$host->load(['module']);
if (!$host->module->isUp()) {
if (! $host->module->isUp()) {
Log::warning('模块不可用,跳过主机更新。', [
'host' => $host->name,
'module' => $host->module->name,

View File

@ -48,14 +48,14 @@ class Module extends Authenticatable
// 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($files = []): PendingRequest
{
$http = Http::module($this->api_token, $this->url . '/remote');
$http = Http::module($this->api_token, $this->url.'/remote');
if ($files) {
$http->asMultipart();
@ -68,7 +68,7 @@ public function http($files = []): PendingRequest
if ($this->ip_port) {
// 如果设置了 ip_port 则使用 ip_port
$http->baseUrl($this->ip_port . '/remote');
$http->baseUrl($this->ip_port.'/remote');
// 添加 Host 头
$http->withHeaders([
@ -107,11 +107,10 @@ private function getResponse(Response $response): array
}
/**
* @param $method
* @param $path
* @param $requests
* @param array $files
*
* @param $method
* @param $path
* @param $requests
* @param array $files
* @return array
*/
public function request($method, $path, $requests, array $files = []): array
@ -119,7 +118,7 @@ public function request($method, $path, $requests, array $files = []): array
try {
return $this->baseRequest($method, "functions/$path", $requests, $files);
} /** @noinspection PhpRedundantCatchClauseInspection */ catch (ConnectException|ConnectionException $e) {
Log::error('在执行 call ' . $method . ' ' . $path . ' 时发生错误: ' . $e->getMessage());
Log::error('在执行 call '.$method.' '.$path.' 时发生错误: '.$e->getMessage());
return [
'body' => null,
@ -195,7 +194,7 @@ public function check(): bool
#[ArrayShape(['transactions' => 'array'])]
public function calculate(): array
{
$cache_key = 'module_earning_' . $this->id;
$cache_key = 'module_earning_'.$this->id;
return Cache::get($cache_key, []);
}
@ -203,11 +202,10 @@ public function calculate(): array
/**
* 扣除费用
*
* @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
@ -216,7 +214,7 @@ public function reduce(string|null $amount = '0', string|null $description = '
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) {
@ -251,11 +249,10 @@ 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
@ -264,7 +261,7 @@ public function charge(string|null $amount = '0', string $payment = 'console', s
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);