增加 手动扣费 和 获取价格方法
This commit is contained in:
parent
882d447754
commit
38240aeceb
54
app/Console/Commands/HostCost.php
Normal file
54
app/Console/Commands/HostCost.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Models\Host;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class HostCost extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'host:cost {--host-id=}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = '手动扣费';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$host = $this->option('host-id');
|
||||||
|
|
||||||
|
if (empty($host)) {
|
||||||
|
if ($this->confirm('如果不指定主机名,将会扣除所有主机的费用,是否继续?', true)) {
|
||||||
|
Host::chunk(100, function ($hosts) {
|
||||||
|
foreach ($hosts as $host) {
|
||||||
|
$this->info('正在扣除主机 ' . $host->name . ' 的费用: ' . $host->getPrice() . ' 元');
|
||||||
|
$host->cost();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$host_model = Host::where('id', $host)->firstOrFail();
|
||||||
|
|
||||||
|
|
||||||
|
if ($this->confirm('是否扣除主机 ' . $host_model->name . ' 的费用?', true)) {
|
||||||
|
$host_model->cost();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
@ -182,7 +182,9 @@ public function module(): BelongsToAlias
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
// cost
|
public function getPrice() {
|
||||||
|
return $this->managed_price ?? $this->price;
|
||||||
|
}
|
||||||
|
|
||||||
public function scopeActive($query)
|
public function scopeActive($query)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user