Lae/app/Console/Commands/TestCommand.php
2023-01-01 21:01:13 +08:00

45 lines
1.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Console\Commands;
use App\Models\Balance;
use Illuminate\Console\Command;
use Symfony\Component\Console\Command\Command as CommandAlias;
class TestCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'test-command';
/**
* The console command description.
*
* @var string
*/
protected $description = '测试用的命令。';
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
// 使用 SQL 语句,统计 Balance 模型中,根据 payment 类别,计算出数据总和 group by date and payment(date 类型要求 datetime)
$balances = Balance::selectRaw('date(created_at) as date, payment, sum(amount) as total')
->groupBy('date', 'payment')
->get();
// table
$this->table(['支付方式', '数量', '日期'], $balances->toArray());
return CommandAlias::SUCCESS;
}
}