From e7fdccd402023f8b3328214532a89d1b1ec794c8 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Sat, 19 Nov 2022 21:18:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=20=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Jobs/HostCost.php | 2 +- app/Models/Host.php | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/Jobs/HostCost.php b/app/Jobs/HostCost.php index 6e740f8..d3d5522 100644 --- a/app/Jobs/HostCost.php +++ b/app/Jobs/HostCost.php @@ -35,7 +35,7 @@ public function handle() // $this->cache = new Cache(); // chunk hosts and load user - Host::active()->with('user')->chunk(1000, function ($hosts) { + Host::whereIn('status', ['running', 'stopped'])->with('user')->chunk(1000, function ($hosts) { foreach ($hosts as $host) { $host->cost(); } diff --git a/app/Models/Host.php b/app/Models/Host.php index 20cbf19..d942261 100644 --- a/app/Models/Host.php +++ b/app/Models/Host.php @@ -122,7 +122,7 @@ public function workOrders(): HasManyAlias public function scopeActive($query) { - return $query->whereIn('status', ['running', 'stopped'])->where('price', '!=', 0)->orWhereNotNull('managed_price'); + return $query->whereIn('status', ['running', 'stopped']); } public function scopeThisUser($query, $module = null) @@ -142,8 +142,6 @@ public function safeDelete(): bool public function cost($price = null, $auto = true): bool { - - Log::debug('Host::cost()'); $this->load('user'); $transaction = new Transaction(); @@ -153,10 +151,17 @@ public function cost($price = null, $auto = true): bool $real_price = $price ?? $this->price; if (!$price) { - $real_price = $this->managed_price; + + if ($this->managed_price) { + $real_price = $this->managed_price; + } } + Log::debug('Host Cost', [ + 'real_price' => $real_price, + ]); + if ($real_price == 0) { return true; }