改进 条件查询
This commit is contained in:
parent
e6ca3ccded
commit
e7fdccd402
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user