分离 模块统计

This commit is contained in:
iVampireSP.com 2022-11-19 11:08:16 +08:00
parent b2ee0f3244
commit e94c86eb53
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
2 changed files with 21 additions and 19 deletions

View File

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

View File

@ -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),
]
];
}
}