改进 条件查询

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

View File

@ -35,7 +35,7 @@ public function handle()
// $this->cache = new Cache(); // $this->cache = new Cache();
// chunk hosts and load user // 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) { foreach ($hosts as $host) {
$host->cost(); $host->cost();
} }

View File

@ -122,7 +122,7 @@ public function workOrders(): HasManyAlias
public function scopeActive($query) 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) public function scopeThisUser($query, $module = null)
@ -142,8 +142,6 @@ public function safeDelete(): bool
public function cost($price = null, $auto = true): bool public function cost($price = null, $auto = true): bool
{ {
Log::debug('Host::cost()');
$this->load('user'); $this->load('user');
$transaction = new Transaction(); $transaction = new Transaction();
@ -153,10 +151,17 @@ public function cost($price = null, $auto = true): bool
$real_price = $price ?? $this->price; $real_price = $price ?? $this->price;
if (!$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) { if ($real_price == 0) {
return true; return true;
} }