From e94c86eb5352efdaf0e38d47fe2fbcd3393cac9f Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Sat, 19 Nov 2022 11:08:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=A6=BB=20=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Modules/ModuleController.php | 18 +-------------- app/Models/Module.php | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/app/Http/Controllers/Modules/ModuleController.php b/app/Http/Controllers/Modules/ModuleController.php index 8b5f830..39e7f04 100644 --- a/app/Http/Controllers/Modules/ModuleController.php +++ b/app/Http/Controllers/Modules/ModuleController.php @@ -15,7 +15,7 @@ public function index() { $module = auth('module')->user(); - $calc = $this->calcModule($module); + $calc = $module->calculate(); $data = [ 'module' => $module, @@ -28,22 +28,6 @@ public function index() return $this->success($data); } - public function calcModule(Module|Authenticatable $module): array - { - - $default = [ - 'balance' => 0, - 'drops' => 0, - ]; - - return [ - 'transactions' => [ - 'this_month' => Cache::get('this_month_balance_and_drops_' . $module->id, $default), - 'last_month' => Cache::get('last_month_balance_and_drops_' . $module->id, $default), - ] - ]; - } - public function call(Request $request, Module $module) { $path = request()->path(); diff --git a/app/Models/Module.php b/app/Models/Module.php index 191a7f8..d3434f7 100644 --- a/app/Models/Module.php +++ b/app/Models/Module.php @@ -5,9 +5,11 @@ use GeneaLabs\LaravelModelCaching\Traits\Cachable; use GuzzleHttp\Exception\ConnectException; use Illuminate\Foundation\Auth\User as Authenticatable; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; +use JetBrains\PhpStorm\ArrayShape; class Module extends Authenticatable { @@ -71,8 +73,7 @@ public function remoteRequest($method, $path, $requests) { $user = auth()->user(); - $http = Http::module($this->api_token, $this->url) - ->accept('application/json'); + $http = Http::module($this->api_token, $this->url); // add Headers $http->withHeaders([ @@ -167,4 +168,21 @@ public function check($module_id = null) return false; } } + + #[ArrayShape(['transactions' => "array"])] + public function calculate(): array + { + + $default = [ + 'balance' => 0, + 'drops' => 0, + ]; + + return [ + 'transactions' => [ + 'this_month' => Cache::get('this_month_balance_and_drops_' . $this->id, $default), + 'last_month' => Cache::get('last_month_balance_and_drops_' . $this->id, $default), + ] + ]; + } }